GRPC Core  9.0.0
global_subchannel_pool.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_GLOBAL_SUBCHANNEL_POOL_H
20 #define GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_GLOBAL_SUBCHANNEL_POOL_H
21 
23 
25 
26 namespace grpc_core {
27 
28 // The global subchannel pool. It shares subchannels among channels. There
29 // should be only one instance of this class. Init() should be called once at
30 // the filter initialization time; Shutdown() should be called once at the
31 // filter shutdown time.
32 // TODO(juanlishen): Enable subchannel retention.
34  public:
35  // The ctor and dtor are not intended to use directly.
37  ~GlobalSubchannelPool() override;
38 
39  // Should be called exactly once at filter initialization time.
40  static void Init();
41  // Should be called exactly once at filter shutdown time.
42  static void Shutdown();
43 
44  // Gets the singleton instance.
46 
47  // Implements interface methods.
49  Subchannel* constructed) override;
50  void UnregisterSubchannel(SubchannelKey* key) override;
51  Subchannel* FindSubchannel(SubchannelKey* key) override;
52 
53  private:
54  // The singleton instance. (It's a pointer to RefCountedPtr so that this
55  // non-local static object can be trivially destructible.)
56  static RefCountedPtr<GlobalSubchannelPool>* instance_;
57 
58  // The vtable for subchannel operations in an AVL tree.
59  static const grpc_avl_vtable subchannel_avl_vtable_;
60  // A map from subchannel key to subchannel.
61  grpc_avl subchannel_map_;
62  // To protect subchannel_map_.
63  gpr_mu mu_;
64 };
65 
66 } // namespace grpc_core
67 
68 #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_GLOBAL_SUBCHANNEL_POOL_H */
Definition: global_subchannel_pool.h:33
static void Init()
Definition: global_subchannel_pool.cc:37
Subchannel * RegisterSubchannel(SubchannelKey *key, Subchannel *constructed) override
Definition: global_subchannel_pool.cc:57
Subchannel * FindSubchannel(SubchannelKey *key) override
Definition: global_subchannel_pool.cc:127
~GlobalSubchannelPool() override
Definition: global_subchannel_pool.cc:32
GlobalSubchannelPool()
Definition: global_subchannel_pool.cc:27
static void Shutdown()
Definition: global_subchannel_pool.cc:42
void UnregisterSubchannel(SubchannelKey *key) override
Definition: global_subchannel_pool.cc:100
static RefCountedPtr< GlobalSubchannelPool > instance()
Definition: global_subchannel_pool.cc:51
Definition: ref_counted_ptr.h:35
Definition: subchannel.h:176
Definition: subchannel_pool_interface.h:35
Definition: subchannel_pool_interface.h:63
Round Robin Policy.
Definition: backend_metric.cc:24
Definition: sync_windows.h:26
vtable for the AVL tree The optional user_data is propagated from the top level grpc_avl_XXX API.
Definition: avl.h:41
"pointer" to an AVL tree - this is a reference counted object - use grpc_avl_ref to add a reference,...
Definition: avl.h:58