Clio  develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
Monitor.hpp
1#pragma once
2
3#include "data/BackendInterface.hpp"
4#include "etl/MonitorInterface.hpp"
6#include "util/Mutex.hpp"
7#include "util/async/AnyExecutionContext.hpp"
8#include "util/async/AnyOperation.hpp"
9#include "util/async/AnyStrand.hpp"
10#include "util/log/Logger.hpp"
11
12#include <boost/signals2/connection.hpp>
13#include <xrpl/protocol/TxFormats.h>
14
15#include <atomic>
16#include <chrono>
17#include <cstddef>
18#include <cstdint>
19#include <memory>
20#include <optional>
21
22namespace etl::impl {
23
24class Monitor : public MonitorInterface {
26 std::shared_ptr<BackendInterface> backend_;
27 std::shared_ptr<NetworkValidatedLedgersInterface> validatedLedgers_;
28
29 std::atomic_uint32_t nextSequence_;
30 std::optional<util::async::AnyOperation<void>> repeatedTask_;
31 std::optional<boost::signals2::scoped_connection>
32 subscription_; // network validated ledgers subscription
33
34 NewSequenceSignalType notificationChannel_;
35 DbStalledSignalType dbStalledChannel_;
36
37 struct UpdateData {
38 std::chrono::steady_clock::duration dbStalledReportDelay;
39 std::chrono::steady_clock::time_point lastDbCheckTime;
40 uint32_t lastSeenMaxSeqInDb = 0u;
41 };
42
43 util::Mutex<UpdateData> updateData_;
44
45 util::Logger log_{"ETL"};
46
47public:
48 Monitor(
50 std::shared_ptr<BackendInterface> backend,
51 std::shared_ptr<NetworkValidatedLedgersInterface> validatedLedgers,
52 uint32_t startSequence,
53 std::chrono::steady_clock::duration dbStalledReportDelay
54 );
55 ~Monitor() override;
56
57 void
58 notifySequenceLoaded(uint32_t seq) override;
59
60 void
61 notifyWriteConflict(uint32_t seq) 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 subscribeToNewSequence(NewSequenceSignalType::slot_type const& subscriber) override;
71
72 boost::signals2::scoped_connection
73 subscribeToDbStalled(DbStalledSignalType::slot_type const& subscriber) override;
74
75private:
76 void
77 onNextSequence(uint32_t seq);
78
79 void
80 doWork();
81};
82
83} // namespace etl::impl
An interface for the monitor service An implementation of this service is responsible for periodicall...
Definition MonitorInterface.hpp:17
void run(std::chrono::steady_clock::duration repeatInterval) override
Run the monitor service.
Definition Monitor.cpp:67
boost::signals2::scoped_connection subscribeToDbStalled(DbStalledSignalType::slot_type const &subscriber) override
Allows clients to get notified when no database update is detected for a configured period.
Definition Monitor.cpp:103
void stop() override
Stops the monitor service.
Definition Monitor.cpp:87
void notifyWriteConflict(uint32_t seq) override
Notifies the monitor of a write conflict.
Definition Monitor.cpp:58
boost::signals2::scoped_connection subscribeToNewSequence(NewSequenceSignalType::slot_type const &subscriber) override
Allows clients to get notified when a new ledger becomes available in Clio's database.
Definition Monitor.cpp:97
void notifySequenceLoaded(uint32_t seq) override
Allows the loading process to notify of a freshly committed ledger.
Definition Monitor.cpp:46
A simple thread-safe logger for the channel specified in the constructor.
Definition Logger.hpp:77
A container for data that is protected by a mutex. Inspired by Mutex in Rust.
Definition Mutex.hpp:82
A type-erased execution context.
Definition AnyExecutionContext.hpp:22
A type-erased execution context.
Definition AnyStrand.hpp:21