1
#pragma once
2

            
3
#include "envoy/upstream/cluster_manager.h"
4

            
5
namespace Envoy {
6
namespace Upstream {
7

            
8
/**
9
 * Keeps track of cluster updates in order to spot addition and removal.
10
 *
11
 * Use this class as a performance optimization to avoid going through ClusterManager::get()
12
 * on the hot path.
13
 */
14
class ClusterUpdateTracker : public ClusterUpdateCallbacks {
15
public:
16
  ClusterUpdateTracker(ClusterManager& cm, const std::string& cluster_name);
17
75
  ThreadLocalClusterOptRef threadLocalCluster() { return thread_local_cluster_; };
18

            
19
  // ClusterUpdateCallbacks
20
  void onClusterAddOrUpdate(absl::string_view cluster_name,
21
                            ThreadLocalClusterCommand& get_cluster) override;
22
  void onClusterRemoval(const std::string& cluster) override;
23

            
24
private:
25
  const std::string cluster_name_;
26
  const ClusterUpdateCallbacksHandlePtr cluster_update_callbacks_handle_;
27

            
28
  ThreadLocalClusterOptRef thread_local_cluster_;
29
};
30

            
31
} // namespace Upstream
32
} // namespace Envoy