3 * Copyright 2018 gRPC authors.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #ifndef GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_GLOBAL_SUBCHANNEL_POOL_H
20 #define GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_GLOBAL_SUBCHANNEL_POOL_H
22 #include <grpc/support/port_platform.h>
24 #include "src/core/ext/filters/client_channel/subchannel_pool_interface.h"
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.
33 class GlobalSubchannelPool final : public SubchannelPoolInterface {
35 // The ctor and dtor are not intended to use directly.
36 GlobalSubchannelPool();
37 ~GlobalSubchannelPool() override;
39 // Should be called exactly once at filter initialization time.
41 // Should be called exactly once at filter shutdown time.
42 static void Shutdown();
44 // Gets the singleton instance.
45 static RefCountedPtr<GlobalSubchannelPool> instance();
47 // Implements interface methods.
48 Subchannel* RegisterSubchannel(SubchannelKey* key,
49 Subchannel* constructed) override;
50 void UnregisterSubchannel(SubchannelKey* key) override;
51 Subchannel* FindSubchannel(SubchannelKey* key) override;
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_;
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_.
66 } // namespace grpc_core
68 #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_GLOBAL_SUBCHANNEL_POOL_H */