GRPC Core  9.0.0
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 "src/core/lib/avl/avl.h"
27 
28 namespace grpc_core {
29 
30 class Subchannel;
31 
33 
34 // A key that can uniquely identify a subchannel.
36  public:
37  explicit SubchannelKey(const grpc_channel_args* args);
39 
40  // Copyable.
41  SubchannelKey(const SubchannelKey& other);
42  SubchannelKey& operator=(const SubchannelKey& other);
43  // Not movable.
44  SubchannelKey(SubchannelKey&&) = delete;
46 
47  int Cmp(const SubchannelKey& other) const;
48 
49  private:
50  // Initializes the subchannel key with the given \a args and the function to
51  // copy channel args.
52  void Init(
53  const grpc_channel_args* args,
54  grpc_channel_args* (*copy_channel_args)(const grpc_channel_args* args));
55 
56  const grpc_channel_args* args_;
57 };
58 
59 // Interface for subchannel pool.
60 // TODO(juanlishen): This refcounting mechanism may lead to memory leak.
61 // To solve that, we should force polling to flush any pending callbacks, then
62 // shut down safely. See https://github.com/grpc/grpc/issues/12560.
63 class SubchannelPoolInterface : public RefCounted<SubchannelPoolInterface> {
64  public:
67 
68  // Registers a subchannel against a key. Returns the subchannel registered
69  // with \a key, which may be different from \a constructed because we reuse
70  // (instead of update) any existing subchannel already registered with \a key.
72  Subchannel* constructed) = 0;
73 
74  // Removes the registered subchannel found by \a key.
75  virtual void UnregisterSubchannel(SubchannelKey* key) = 0;
76 
77  // Finds the subchannel registered for the given subchannel key. Returns NULL
78  // if no such channel exists. Thread-safe.
79  virtual Subchannel* FindSubchannel(SubchannelKey* key) = 0;
80 
81  // Creates a channel arg from \a subchannel pool.
82  static grpc_arg CreateChannelArg(SubchannelPoolInterface* subchannel_pool);
83 
84  // Gets the subchannel pool from the channel args.
86  const grpc_channel_args* args);
87 };
88 
89 } // namespace grpc_core
90 
91 #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_SUBCHANNEL_POOL_INTERFACE_H */
virtual ~SubchannelPoolInterface()
Definition: subchannel_pool_interface.h:66
SubchannelPoolInterface()
Definition: subchannel_pool_interface.h:65
An array of arguments that can be passed around.
Definition: grpc_types.h:132
virtual void UnregisterSubchannel(SubchannelKey *key)=0
int Cmp(const SubchannelKey &other) const
Definition: subchannel_pool_interface.cc:52
SubchannelKey(const grpc_channel_args *args)
Definition: subchannel_pool_interface.cc:34
A single argument...
Definition: grpc_types.h:103
virtual Subchannel * FindSubchannel(SubchannelKey *key)=0
Definition: subchannel_pool_interface.h:35
Round Robin Policy.
Definition: backend_metric.cc:24
Definition: trace.h:61
SubchannelKey & operator=(const SubchannelKey &other)
Definition: subchannel_pool_interface.cc:46
static grpc_arg CreateChannelArg(SubchannelPoolInterface *subchannel_pool)
Definition: subchannel_pool_interface.cc:82
Definition: subchannel_pool_interface.h:63
TraceFlag grpc_subchannel_pool_trace(false, "subchannel_pool")
Definition: subchannel_pool_interface.h:30
~SubchannelKey()
Definition: subchannel_pool_interface.cc:38
Definition: ref_counted.h:248
static SubchannelPoolInterface * GetSubchannelPoolFromChannelArgs(const grpc_channel_args *args)
Definition: subchannel_pool_interface.cc:90
Definition: subchannel.h:176
virtual Subchannel * RegisterSubchannel(SubchannelKey *key, Subchannel *constructed)=0