#include "cluster/ClusterCommunicationService.hpp" #include "data/BackendInterface.hpp" #include "data/LedgerCacheLoadingState.hpp" #include "etl/SystemState.hpp" #include "etl/WriterState.hpp" #include "util/config/ConfigDefinition.hpp" #include #include #include namespace cluster { ClusterCommunicationService::ClusterCommunicationService( std::shared_ptr backend, std::unique_ptr writerState, std::unique_ptr cacheLoadingState, std::chrono::steady_clock::duration readInterval, std::chrono::steady_clock::duration writeInterval ) : backend_( ctx_, std::move(backend), writerState->clone(), cacheLoadingState->clone(), readInterval, writeInterval ) , writerDecider_(ctx_, std::move(writerState)) , cacheLoaderDecider_(ctx_, std::move(cacheLoadingState)) { } void ClusterCommunicationService::run() { backend_.subscribeToNewState([this](auto&&... args) { metrics_.onNewState(std::forward(args)...); }); backend_.subscribeToNewState([this](auto&&... args) { writerDecider_.onNewState(std::forward(args)...); }); backend_.subscribeToNewState([this](auto&&... args) { cacheLoaderDecider_.onNewState(std::forward(args)...); }); backend_.run(); } ClusterCommunicationService::~ClusterCommunicationService() { stop(); } void ClusterCommunicationService::stop() { backend_.stop(); } ClusterCommunicationService::MakeResult ClusterCommunicationService::make( util::config::ClioConfigDefinition const& config, std::shared_ptr backend, std::shared_ptr state ) { auto const& cache = backend->cache(); auto cacheLoadingState = std::make_unique(cache); if (not config.get("cache.limit_load_in_cluster")) { cacheLoadingState->allowLoading(); } auto cacheLoadingStateClone = cacheLoadingState->clone(); return MakeResult{ .service = std::make_unique( std::move(backend), std::make_unique(std::move(state), cache), std::move(cacheLoadingState) ), .cacheLoadingState = std::move(cacheLoadingStateClone) }; } } // namespace cluster