3#include "cluster/ClioNode.hpp"
4#include "cluster/impl/RepeatedTask.hpp"
5#include "data/BackendInterface.hpp"
6#include "data/LedgerCacheLoadingState.hpp"
7#include "etl/WriterState.hpp"
8#include "util/log/Logger.hpp"
10#include <boost/asio/any_io_executor.hpp>
11#include <boost/asio/cancellation_signal.hpp>
12#include <boost/asio/execution_context.hpp>
13#include <boost/asio/executor.hpp>
14#include <boost/asio/spawn.hpp>
15#include <boost/asio/strand.hpp>
16#include <boost/asio/thread_pool.hpp>
17#include <boost/signals2/connection.hpp>
18#include <boost/signals2/signal.hpp>
19#include <boost/signals2/variadic_signal.hpp>
20#include <boost/uuid/uuid.hpp>
41 using ClusterData = std::expected<std::vector<ClioNode>, std::string>;
46 std::shared_ptr<data::BackendInterface> backend_;
47 std::unique_ptr<etl::WriterStateInterface const> writerState_;
48 std::unique_ptr<data::LedgerCacheLoadingStateInterface const> cacheLoadingState_;
53 ClioNode::Uuid selfUuid_;
55 boost::signals2::signal<void(ClioNode::CUuid, std::shared_ptr<ClusterData const>)> onNewState_;
69 boost::asio::thread_pool& ctx,
70 std::shared_ptr<data::BackendInterface> backend,
71 std::unique_ptr<etl::WriterStateInterface const> writerState,
72 std::unique_ptr<data::LedgerCacheLoadingStateInterface const> cacheLoadingState,
73 std::chrono::steady_clock::duration readInterval,
74 std::chrono::steady_clock::duration writeInterval
84 operator=(
Backend const&) =
delete;
109 template <
typename S>
110 requires std::invocable<S, ClioNode::CUuid, std::shared_ptr<ClusterData const>>
111 boost::signals2::connection
114 return onNewState_.connect(s);
127 doRead(boost::asio::yield_context yield);
Backend communication handler for cluster state synchronization.
Definition Backend.hpp:37
Backend(boost::asio::thread_pool &ctx, std::shared_ptr< data::BackendInterface > backend, std::unique_ptr< etl::WriterStateInterface const > writerState, std::unique_ptr< data::LedgerCacheLoadingStateInterface const > cacheLoadingState, std::chrono::steady_clock::duration readInterval, std::chrono::steady_clock::duration writeInterval)
Construct a Backend communication handler.
Definition Backend.cpp:26
void run()
Start the backend read and write tasks.
Definition Backend.cpp:44
void stop()
Stop the backend read and write tasks.
Definition Backend.cpp:60
ClioNode::CUuid selfId() const
Get the UUID of this node in the cluster.
Definition Backend.cpp:67
std::expected< std::vector< ClioNode >, std::string > ClusterData
Type representing cluster data result - either a vector of nodes or an error message.
Definition Backend.hpp:41
boost::signals2::connection subscribeToNewState(S &&s)
Subscribe to new cluster state notifications.
Definition Backend.hpp:112
Definition RepeatedTask.hpp:24
A simple thread-safe logger for the channel specified in the constructor.
Definition Logger.hpp:77