subchannel_pool_interface.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2018 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 #ifndef GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_SUBCHANNEL_POOL_INTERFACE_H
20 #define GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_SUBCHANNEL_POOL_INTERFACE_H
21 
23 
24 #include <string>
25 
27 
32 
33 namespace grpc_core {
34 
35 class Subchannel;
36 
38 
39 // A key that can uniquely identify a subchannel.
41  public:
43  const grpc_channel_args* args);
45 
46  // Copyable.
47  SubchannelKey(const SubchannelKey& other);
48  SubchannelKey& operator=(const SubchannelKey& other);
49  // Movable
50  SubchannelKey(SubchannelKey&&) noexcept;
52 
53  bool operator<(const SubchannelKey& other) const;
54 
55  const grpc_resolved_address& address() const { return address_; }
56  const grpc_channel_args* args() const { return args_; }
57 
58  // Human-readable string suitable for logging.
59  std::string ToString() const;
60 
61  private:
62  // Initializes the subchannel key with the given \a args and the function to
63  // copy channel args.
64  void Init(
66  grpc_channel_args* (*copy_channel_args)(const grpc_channel_args* args));
67 
70 };
71 
72 // Interface for subchannel pool.
73 // TODO(juanlishen): This refcounting mechanism may lead to memory leak.
74 // To solve that, we should force polling to flush any pending callbacks, then
75 // shut down safely. See https://github.com/grpc/grpc/issues/12560.
76 class SubchannelPoolInterface : public RefCounted<SubchannelPoolInterface> {
77  public:
80  ? "SubchannelPoolInterface"
81  : nullptr) {}
83 
84  // Registers a subchannel against a key. Returns the subchannel registered
85  // with \a key, which may be different from \a constructed because we reuse
86  // (instead of update) any existing subchannel already registered with \a key.
88  const SubchannelKey& key, RefCountedPtr<Subchannel> constructed) = 0;
89 
90  // Removes the registered subchannel found by \a key.
91  virtual void UnregisterSubchannel(const SubchannelKey& key,
92  Subchannel* subchannel) = 0;
93 
94  // Finds the subchannel registered for the given subchannel key. Returns NULL
95  // if no such channel exists. Thread-safe.
97  const SubchannelKey& key) = 0;
98 
99  // Creates a channel arg from \a subchannel pool.
100  static grpc_arg CreateChannelArg(SubchannelPoolInterface* subchannel_pool);
101 
102  // Gets the subchannel pool from the channel args.
104  const grpc_channel_args* args);
105 };
106 
107 } // namespace grpc_core
108 
109 #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_SUBCHANNEL_POOL_INTERFACE_H */
grpc_arg
Definition: grpc_types.h:103
trace.h
grpc_core::SubchannelKey::~SubchannelKey
~SubchannelKey()
Definition: subchannel_pool_interface.cc:47
grpc_core::SubchannelPoolInterface::CreateChannelArg
static grpc_arg CreateChannelArg(SubchannelPoolInterface *subchannel_pool)
Definition: subchannel_pool_interface.cc:121
grpc_core
Definition: call_metric_recorder.h:31
subchannel
RingHashSubchannelData * subchannel
Definition: ring_hash.cc:285
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
grpc_resolved_address
Definition: resolved_address.h:34
grpc_core::SubchannelPoolInterface::SubchannelPoolInterface
SubchannelPoolInterface()
Definition: subchannel_pool_interface.h:78
grpc_core::SubchannelPoolInterface::FindSubchannel
virtual RefCountedPtr< Subchannel > FindSubchannel(const SubchannelKey &key)=0
resolved_address.h
grpc_channel_args
Definition: grpc_types.h:132
GRPC_TRACE_FLAG_ENABLED
#define GRPC_TRACE_FLAG_ENABLED(f)
Definition: debug/trace.h:114
grpc_types.h
grpc_core::SubchannelPoolInterface::~SubchannelPoolInterface
~SubchannelPoolInterface() override
Definition: subchannel_pool_interface.h:82
grpc_core::grpc_subchannel_pool_trace
TraceFlag grpc_subchannel_pool_trace(false, "subchannel_pool")
Definition: subchannel_pool_interface.h:35
asyncio_get_stats.args
args
Definition: asyncio_get_stats.py:40
grpc_core::SubchannelKey::operator=
SubchannelKey & operator=(const SubchannelKey &other)
Definition: subchannel_pool_interface.cc:55
grpc_core::RefCountedPtr
Definition: ref_counted_ptr.h:35
grpc_core::SubchannelKey::Init
void Init(const grpc_resolved_address &address, const grpc_channel_args *args, grpc_channel_args *(*copy_channel_args)(const grpc_channel_args *args))
Definition: subchannel_pool_interface.cc:86
grpc_core::SubchannelKey::args_
const grpc_channel_args * args_
Definition: subchannel_pool_interface.h:69
grpc_core::SubchannelKey::SubchannelKey
SubchannelKey(const grpc_resolved_address &address, const grpc_channel_args *args)
Definition: subchannel_pool_interface.cc:42
grpc_core::SubchannelKey::ToString
std::string ToString() const
Definition: subchannel_pool_interface.cc:93
grpc_core::RefCounted
Definition: ref_counted.h:280
grpc_core::SubchannelPoolInterface::GetSubchannelPoolFromChannelArgs
static SubchannelPoolInterface * GetSubchannelPoolFromChannelArgs(const grpc_channel_args *args)
Definition: subchannel_pool_interface.cc:129
grpc_core::TraceFlag
Definition: debug/trace.h:63
grpc_core::SubchannelKey
Definition: subchannel_pool_interface.h:40
grpc_core::Subchannel
Definition: subchannel.h:166
key
const char * key
Definition: hpack_parser_table.cc:164
grpc_core::SubchannelPoolInterface
Definition: subchannel_pool_interface.h:76
grpc_core::SubchannelKey::address
const grpc_resolved_address & address() const
Definition: subchannel_pool_interface.h:55
grpc_core::SubchannelPoolInterface::RegisterSubchannel
virtual RefCountedPtr< Subchannel > RegisterSubchannel(const SubchannelKey &key, RefCountedPtr< Subchannel > constructed)=0
ref_counted.h
grpc_core::SubchannelKey::operator<
bool operator<(const SubchannelKey &other) const
Definition: subchannel_pool_interface.cc:77
grpc_core::SubchannelPoolInterface::UnregisterSubchannel
virtual void UnregisterSubchannel(const SubchannelKey &key, Subchannel *subchannel)=0
ref_counted_ptr.h
grpc_core::SubchannelKey::args
const grpc_channel_args * args() const
Definition: subchannel_pool_interface.h:56
grpc_core::SubchannelKey::address_
grpc_resolved_address address_
Definition: subchannel_pool_interface.h:68
port_platform.h


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:01:27