1
#include "source/extensions/common/dynamic_forward_proxy/cluster_store.h"
2

            
3
namespace Envoy {
4
namespace Extensions {
5
namespace Common {
6
namespace DynamicForwardProxy {
7

            
8
SINGLETON_MANAGER_REGISTRATION(dynamic_forward_proxy_cluster_store);
9

            
10
58
DfpClusterSharedPtr DFPClusterStore::load(const std::string cluster_name) {
11
58
  ClusterStoreType& clusterStore = getClusterStore();
12
58
  absl::ReaderMutexLock lock(clusterStore.mutex_);
13
58
  auto it = clusterStore.map_.find(cluster_name);
14
58
  if (it != clusterStore.map_.end()) {
15
57
    return it->second.lock();
16
57
  }
17
1
  return nullptr;
18
58
}
19

            
20
144
void DFPClusterStore::save(const std::string cluster_name, DfpClusterSharedPtr cluster) {
21
144
  ClusterStoreType& clusterStore = getClusterStore();
22
144
  absl::WriterMutexLock lock(clusterStore.mutex_);
23
144
  clusterStore.map_[cluster_name] = std::move(cluster);
24
144
}
25

            
26
1
void DFPClusterStore::remove(const std::string cluster_name) {
27
1
  ClusterStoreType& clusterStore = getClusterStore();
28
1
  absl::WriterMutexLock lock(clusterStore.mutex_);
29
1
  clusterStore.map_.erase(cluster_name);
30
1
}
31

            
32
199
DFPClusterStoreSharedPtr DFPClusterStoreFactory::get() {
33
199
  return singleton_manager_.getTyped<DFPClusterStore>(
34
199
      SINGLETON_MANAGER_REGISTERED_NAME(dynamic_forward_proxy_cluster_store),
35
199
      []() { return std::make_shared<DFPClusterStore>(); });
36
199
}
37

            
38
} // namespace DynamicForwardProxy
39
} // namespace Common
40
} // namespace Extensions
41
} // namespace Envoy