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
107 virtual void
108 onTimer(bool progress, ScopedLockType& sl) = 0;
109
115
116 bool
117 isDone() const
118 {
119 return complete_ || failed_;
120 }
121
122 // Used in this class for access to boost::asio::io_context and
123 // xrpl::Overlay. Used in subtypes for the kitchen sink.
127
133 int timeouts_{0};
134 bool complete_{false};
135 bool failed_{false};
139 bool progress_{false};
144
146
147private:
152 void
154
155 boost::asio::basic_waitable_timer<std::chrono::steady_clock> timer_;
156};
157
158} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:44
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.
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().
TimeoutCounter(Application &app, UInt256 const &targetHash, std::chrono::milliseconds timeoutInterval, QueueJobParameter &&jobParameter, beast::Journal journal)
bool progress_
Whether forward progress has been made.
virtual void onTimer(bool progress, ScopedLockType &sl)=0
Hook called from invokeOnTimer().
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
BaseUInt< 256 > UInt256
Definition base_uint.h:581
JobType
Definition Job.h:21
std::optional< std::uint32_t > jobLimit