xrpld
Loading...
Searching...
No Matches
TimeoutCounter.h
1#pragma once
2
3#include <xrpld/app/main/Application.h>
4
5#include <xrpl/basics/base_uint.h>
6#include <xrpl/beast/utility/Journal.h>
7#include <xrpl/core/Job.h>
8
9#include <boost/asio/basic_waitable_timer.hpp>
10
11#include <chrono>
12#include <cstdint>
13#include <memory>
14#include <mutex>
15#include <optional>
16#include <string>
17
18namespace xrpl {
19
55{
56public:
65 virtual void
66 cancel();
67
68 virtual ~TimeoutCounter() = default;
69
70protected:
72
79
81 Application& app,
82 uint256 const& targetHash,
83 std::chrono::milliseconds timeoutInterval,
84 QueueJobParameter&& jobParameter,
85 beast::Journal journal);
86
90 void
92
96 void
98
102 virtual void
103 onTimer(bool progress, ScopedLockType&) = 0;
104
110
111 bool
112 isDone() const
113 {
114 return complete_ || failed_;
115 }
116
117 // Used in this class for access to boost::asio::io_context and
118 // xrpl::Overlay. Used in subtypes for the kitchen sink.
122
128 int timeouts_{0};
129 bool complete_{false};
130 bool failed_{false};
134 bool progress_{false};
139
141
142private:
147 void
149
150 boost::asio::basic_waitable_timer<std::chrono::steady_clock> timer_;
151};
152
153} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:44
TimeoutCounter(Application &app, uint256 const &targetHash, std::chrono::milliseconds timeoutInterval, QueueJobParameter &&jobParameter, beast::Journal journal)
boost::asio::basic_waitable_timer< std::chrono::steady_clock > timer_
std::recursive_mutex mtx_
virtual std::weak_ptr< TimeoutCounter > pmDowncast()=0
Return a weak pointer to this.
virtual void onTimer(bool progress, ScopedLockType &)=0
Hook called from invokeOnTimer().
std::unique_lock< std::recursive_mutex > ScopedLockType
uint256 const hash_
The hash of the object (in practice, always a ledger) we are trying to fetch.
void queueJob(ScopedLockType &)
Queue a job to call invokeOnTimer().
bool progress_
Whether forward progress has been made.
beast::Journal journal_
virtual ~TimeoutCounter()=default
QueueJobParameter queueJobParameter_
void invokeOnTimer()
Calls onTimer() if in the right state.
void setTimer(ScopedLockType &)
Schedule a call to queueJob() after timerInterval_.
std::chrono::milliseconds timerInterval_
The minimum time to wait between calls to execute().
virtual void cancel()
Cancel the task by marking it as failed if the task is not done.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
JobType
Definition Job.h:21
BaseUInt< 256 > uint256
Definition base_uint.h:580
std::optional< std::uint32_t > jobLimit