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
11743
                                                              const HostConstSharedPtr& host) {
12
35229
  for (size_t pool_map_index = 0; pool_map_index < NumResourcePriorities; ++pool_map_index) {
13
23486
    auto priority = static_cast<ResourcePriority>(pool_map_index);
14
23486
    conn_pool_maps_[pool_map_index].reset(new ConnPoolMapType(dispatcher, host, priority));
15
23486
  }
16
11743
}
17

            
18
template <typename KEY_TYPE, typename POOL_TYPE>
19
11743
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
47311
                                                  const PoolFactory& factory) {
25
47311
  return conn_pool_maps_[getPriorityIndex(priority)]->getPool(key, factory);
26
47311
}
27

            
28
template <typename KEY_TYPE, typename POOL_TYPE>
29
bool PriorityConnPoolMap<KEY_TYPE, POOL_TYPE>::erasePool(ResourcePriority priority,
30
11486
                                                         const KEY_TYPE& key) {
31
11486
  return conn_pool_maps_[getPriorityIndex(priority)]->erasePool(key);
32
11486
}
33

            
34
template <typename KEY_TYPE, typename POOL_TYPE>
35
4
size_t PriorityConnPoolMap<KEY_TYPE, POOL_TYPE>::size() const {
36
4
  size_t size = 0;
37
8
  for (const auto& pool_map : conn_pool_maps_) {
38
8
    size += pool_map->size();
39
8
  }
40
4
  return size;
41
4
}
42

            
43
template <typename KEY_TYPE, typename POOL_TYPE>
44
11512
bool PriorityConnPoolMap<KEY_TYPE, POOL_TYPE>::empty() const {
45
22990
  for (const auto& pool_map : conn_pool_maps_) {
46
22990
    if (!pool_map->empty()) {
47
38
      return false;
48
38
    }
49
22990
  }
50
11474
  return true;
51
11512
}
52

            
53
template <typename KEY_TYPE, typename POOL_TYPE>
54
1
void PriorityConnPoolMap<KEY_TYPE, POOL_TYPE>::clear() {
55
2
  for (auto& pool_map : conn_pool_maps_) {
56
2
    pool_map->clear();
57
2
  }
58
1
}
59

            
60
template <typename KEY_TYPE, typename POOL_TYPE>
61
1
void PriorityConnPoolMap<KEY_TYPE, POOL_TYPE>::addIdleCallback(const IdleCb& cb) {
62
2
  for (auto& pool_map : conn_pool_maps_) {
63
2
    pool_map->addIdleCallback(cb);
64
2
  }
65
1
}
66

            
67
template <typename KEY_TYPE, typename POOL_TYPE>
68
void PriorityConnPoolMap<KEY_TYPE, POOL_TYPE>::drainConnections(
69
188
    ConnectionPool::DrainBehavior drain_behavior) {
70
376
  for (auto& pool_map : conn_pool_maps_) {
71
376
    pool_map->drainConnections(drain_behavior);
72
376
  }
73
188
}
74

            
75
template <typename KEY_TYPE, typename POOL_TYPE>
76
58797
size_t PriorityConnPoolMap<KEY_TYPE, POOL_TYPE>::getPriorityIndex(ResourcePriority priority) const {
77
58797
  size_t index = static_cast<size_t>(priority);
78
58797
  ASSERT(index < conn_pool_maps_.size());
79
58797
  return index;
80
58797
}
81

            
82
} // namespace Upstream
83
} // namespace Envoy