GRPC C++  1.39.1
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 
24 #include <map>
25 
28 
29 namespace grpc_core {
30 
31 // The global subchannel pool. It shares subchannels among channels. There
32 // should be only one instance of this class. Init() should be called once at
33 // the filter initialization time; Shutdown() should be called once at the
34 // filter shutdown time.
35 // TODO(juanlishen): Enable subchannel retention.
37  public:
38  // The ctor and dtor are not intended to use directly.
40  ~GlobalSubchannelPool() override {}
41 
42  // Should be called exactly once at filter initialization time.
43  static void Init();
44  // Should be called exactly once at filter shutdown time.
45  static void Shutdown();
46 
47  // Gets the singleton instance.
49 
50  // Implements interface methods.
52  const SubchannelKey& key, RefCountedPtr<Subchannel> constructed) override
53  ABSL_LOCKS_EXCLUDED(mu_);
54  void UnregisterSubchannel(const SubchannelKey& key,
55  Subchannel* subchannel) override
56  ABSL_LOCKS_EXCLUDED(mu_);
58  ABSL_LOCKS_EXCLUDED(mu_);
59 
60  private:
61  // The singleton instance. (It's a pointer to RefCountedPtr so that this
62  // non-local static object can be trivially destructible.)
63  static RefCountedPtr<GlobalSubchannelPool>* instance_;
64 
65  // A map from subchannel key to subchannel.
66  std::map<SubchannelKey, Subchannel*> subchannel_map_ ABSL_GUARDED_BY(mu_);
67  // To protect subchannel_map_.
68  Mutex mu_;
69 };
70 
71 } // namespace grpc_core
72 
73 #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_GLOBAL_SUBCHANNEL_POOL_H */
Definition: global_subchannel_pool.h:36
static void Init()
Definition: global_subchannel_pool.cc:30
RefCountedPtr< Subchannel > FindSubchannel(const SubchannelKey &key) override ABSL_LOCKS_EXCLUDED(mu_)
Definition: global_subchannel_pool.cc:75
~GlobalSubchannelPool() override
Definition: global_subchannel_pool.h:40
GlobalSubchannelPool()
Definition: global_subchannel_pool.h:39
static void Shutdown()
Definition: global_subchannel_pool.cc:35
RefCountedPtr< Subchannel > RegisterSubchannel(const SubchannelKey &key, RefCountedPtr< Subchannel > constructed) override ABSL_LOCKS_EXCLUDED(mu_)
Definition: global_subchannel_pool.cc:50
static RefCountedPtr< GlobalSubchannelPool > instance()
Definition: global_subchannel_pool.cc:44
void UnregisterSubchannel(const SubchannelKey &key, Subchannel *subchannel) override ABSL_LOCKS_EXCLUDED(mu_)
Definition: global_subchannel_pool.cc:64
Definition: sync.h:59
Definition: ref_counted_ptr.h:35
Definition: subchannel.h:148
Definition: subchannel_pool_interface.h:36
Definition: subchannel_pool_interface.h:64
Round Robin Policy.
Definition: backend_metric.cc:26
RefCountedPtr< SubchannelInterface > subchannel
Definition: ring_hash.cc:213