Line data Source code
1 : #pragma once 2 : 3 : #include <memory> 4 : 5 : #include "envoy/config/eds_resources_cache.h" 6 : #include "envoy/event/dispatcher.h" 7 : #include "envoy/event/timer.h" 8 : 9 : #include "absl/container/flat_hash_map.h" 10 : 11 : namespace Envoy { 12 : namespace Config { 13 : 14 : class EdsResourcesCacheImpl : public EdsResourcesCache { 15 : public: 16 : EdsResourcesCacheImpl(Event::Dispatcher& main_thread_dispatcher) 17 0 : : dispatcher_(main_thread_dispatcher) {} 18 : 19 : // EdsResourcesCache 20 : void setResource(absl::string_view resource_name, 21 : const envoy::config::endpoint::v3::ClusterLoadAssignment& resource) override; 22 : void removeResource(absl::string_view resource_name) override; 23 : OptRef<const envoy::config::endpoint::v3::ClusterLoadAssignment> 24 : getResource(absl::string_view resource_name, EdsResourceRemovalCallback* removal_cb) override; 25 : void removeCallback(absl::string_view resource_name, 26 : EdsResourceRemovalCallback* removal_cb) override; 27 : uint32_t cacheSizeForTest() const override; 28 : void setExpiryTimer(absl::string_view resource_name, std::chrono::milliseconds ms) override; 29 : void disableExpiryTimer(absl::string_view resource_name) override; 30 : 31 : private: 32 : // The value of the map, holds the resource and the removal callbacks. 33 : struct ResourceData { 34 : envoy::config::endpoint::v3::ClusterLoadAssignment resource_; 35 : std::vector<EdsResourceRemovalCallback*> removal_cbs_; 36 : 37 : ResourceData(const envoy::config::endpoint::v3::ClusterLoadAssignment& resource) 38 0 : : resource_(resource) {} 39 : }; 40 : // A map between a resource name and its ResourceData. 41 : absl::flat_hash_map<std::string, ResourceData> resources_map_; 42 : // The per-resource timeout timer to track when the resource should be removed. 43 : absl::flat_hash_map<std::string, Event::TimerPtr> expiry_timers_; 44 : Event::Dispatcher& dispatcher_; 45 : }; 46 : 47 : } // namespace Config 48 : } // namespace Envoy