Clio develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
Monitor.hpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of clio: https://github.com/XRPLF/clio
4 Copyright (c) 2025, the clio developers.
5
6 Permission to use, copy, modify, and distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#pragma once
21
22#include "data/BackendInterface.hpp"
24#include "etlng/MonitorInterface.hpp"
25#include "util/async/AnyExecutionContext.hpp"
26#include "util/async/AnyOperation.hpp"
27#include "util/async/AnyStrand.hpp"
28#include "util/log/Logger.hpp"
29
30#include <boost/signals2/connection.hpp>
31#include <xrpl/protocol/TxFormats.h>
32
33#include <chrono>
34#include <cstddef>
35#include <cstdint>
36#include <memory>
37#include <optional>
38
39namespace etlng::impl {
40
41class Monitor : public MonitorInterface {
43 std::shared_ptr<BackendInterface> backend_;
44 std::shared_ptr<etl::NetworkValidatedLedgersInterface> validatedLedgers_;
45
46 uint32_t nextSequence_;
47 std::optional<util::async::AnyOperation<void>> repeatedTask_;
48 std::optional<boost::signals2::scoped_connection> subscription_; // network validated ledgers subscription
49
50 SignalType notificationChannel_;
51
52 util::Logger log_{"ETL"};
53
54public:
55 Monitor(
57 std::shared_ptr<BackendInterface> backend,
58 std::shared_ptr<etl::NetworkValidatedLedgersInterface> validatedLedgers,
59 uint32_t startSequence
60 );
61 ~Monitor() override;
62
63 void
64 run(std::chrono::steady_clock::duration repeatInterval) override;
65
66 void
67 stop() override;
68
69 boost::signals2::scoped_connection
70 subscribe(SignalType::slot_type const& subscriber) override;
71
72private:
73 void
74 onNextSequence(uint32_t seq);
75
76 void
77 doWork();
78};
79
80} // namespace etlng::impl
An interface for the monitor service An implementation of this service is responsible for periodicall...
Definition MonitorInterface.hpp:36
Definition Monitor.hpp:41
void run(std::chrono::steady_clock::duration repeatInterval) override
Run the monitor service.
Definition Monitor.cpp:59
void stop() override
Stops the monitor service.
Definition Monitor.cpp:69
boost::signals2::scoped_connection subscribe(SignalType::slot_type const &subscriber) override
Allows clients to get notified when a new ledger becomes available in Clio's database.
Definition Monitor.cpp:78
A simple thread-safe logger for the channel specified in the constructor.
Definition Logger.hpp:111
A type-erased execution context.
Definition AnyExecutionContext.hpp:41
A type-erased execution context.
Definition AnyStrand.hpp:40