Line data Source code
1 : #pragma once 2 : 3 : #include "source/common/upstream/conn_pool_map_impl.h" 4 : #include "source/common/upstream/priority_conn_pool_map.h" 5 : 6 : namespace Envoy { 7 : namespace Upstream { 8 : 9 : template <typename KEY_TYPE, typename POOL_TYPE> 10 : PriorityConnPoolMap<KEY_TYPE, POOL_TYPE>::PriorityConnPoolMap(Envoy::Event::Dispatcher& dispatcher, 11 173 : const HostConstSharedPtr& host) { 12 519 : for (size_t pool_map_index = 0; pool_map_index < NumResourcePriorities; ++pool_map_index) { 13 346 : auto priority = static_cast<ResourcePriority>(pool_map_index); 14 346 : conn_pool_maps_[pool_map_index].reset(new ConnPoolMapType(dispatcher, host, priority)); 15 346 : } 16 173 : } 17 : 18 : template <typename KEY_TYPE, typename POOL_TYPE> 19 : PriorityConnPoolMap<KEY_TYPE, POOL_TYPE>::~PriorityConnPoolMap() = default; 20 : 21 : template <typename KEY_TYPE, typename POOL_TYPE> 22 : typename PriorityConnPoolMap<KEY_TYPE, POOL_TYPE>::PoolOptRef 23 : PriorityConnPoolMap<KEY_TYPE, POOL_TYPE>::getPool(ResourcePriority priority, const KEY_TYPE& key, 24 251 : const PoolFactory& factory) { 25 251 : return conn_pool_maps_[getPriorityIndex(priority)]->getPool(key, factory); 26 251 : } 27 : 28 : template <typename KEY_TYPE, typename POOL_TYPE> 29 : bool PriorityConnPoolMap<KEY_TYPE, POOL_TYPE>::erasePool(ResourcePriority priority, 30 173 : const KEY_TYPE& key) { 31 173 : return conn_pool_maps_[getPriorityIndex(priority)]->erasePool(key); 32 173 : } 33 : 34 : template <typename KEY_TYPE, typename POOL_TYPE> 35 : size_t PriorityConnPoolMap<KEY_TYPE, POOL_TYPE>::size() const { 36 : size_t size = 0; 37 : for (const auto& pool_map : conn_pool_maps_) { 38 : size += pool_map->size(); 39 : } 40 : return size; 41 : } 42 : 43 : template <typename KEY_TYPE, typename POOL_TYPE> 44 173 : bool PriorityConnPoolMap<KEY_TYPE, POOL_TYPE>::empty() const { 45 346 : for (const auto& pool_map : conn_pool_maps_) { 46 346 : if (!pool_map->empty()) { 47 0 : return false; 48 0 : } 49 346 : } 50 173 : return true; 51 173 : } 52 : 53 : template <typename KEY_TYPE, typename POOL_TYPE> 54 : void PriorityConnPoolMap<KEY_TYPE, POOL_TYPE>::clear() { 55 : for (auto& pool_map : conn_pool_maps_) { 56 : pool_map->clear(); 57 : } 58 : } 59 : 60 : template <typename KEY_TYPE, typename POOL_TYPE> 61 : void PriorityConnPoolMap<KEY_TYPE, POOL_TYPE>::addIdleCallback(const IdleCb& cb) { 62 : for (auto& pool_map : conn_pool_maps_) { 63 : pool_map->addIdleCallback(cb); 64 : } 65 : } 66 : 67 : template <typename KEY_TYPE, typename POOL_TYPE> 68 : void PriorityConnPoolMap<KEY_TYPE, POOL_TYPE>::drainConnections( 69 0 : ConnectionPool::DrainBehavior drain_behavior) { 70 0 : for (auto& pool_map : conn_pool_maps_) { 71 0 : pool_map->drainConnections(drain_behavior); 72 0 : } 73 0 : } 74 : 75 : template <typename KEY_TYPE, typename POOL_TYPE> 76 424 : size_t PriorityConnPoolMap<KEY_TYPE, POOL_TYPE>::getPriorityIndex(ResourcePriority priority) const { 77 424 : size_t index = static_cast<size_t>(priority); 78 424 : ASSERT(index < conn_pool_maps_.size()); 79 424 : return index; 80 424 : } 81 : 82 : } // namespace Upstream 83 : } // namespace Envoy