rippled
|
This class is an "active" object. More...
Classes | |
struct | QueueJobParameter |
Public Member Functions | |
virtual void | cancel () |
Cancel the task by marking it as failed if the task is not done. More... | |
Protected Types | |
using | ScopedLockType = std::unique_lock< std::recursive_mutex > |
Protected Member Functions | |
TimeoutCounter (Application &app, uint256 const &targetHash, std::chrono::milliseconds timeoutInterval, QueueJobParameter &&jobParameter, beast::Journal journal) | |
virtual | ~TimeoutCounter ()=default |
void | setTimer (ScopedLockType &) |
Schedule a call to queueJob() after mTimerInterval. More... | |
void | queueJob (ScopedLockType &) |
Queue a job to call invokeOnTimer(). More... | |
virtual void | onTimer (bool progress, ScopedLockType &)=0 |
Hook called from invokeOnTimer(). More... | |
virtual std::weak_ptr< TimeoutCounter > | pmDowncast ()=0 |
Return a weak pointer to this. More... | |
bool | isDone () const |
Protected Attributes | |
Application & | app_ |
beast::Journal | journal_ |
std::recursive_mutex | mtx_ |
const uint256 | hash_ |
The hash of the object (in practice, always a ledger) we are trying to fetch. More... | |
int | timeouts_ |
bool | complete_ |
bool | failed_ |
bool | progress_ |
Whether forward progress has been made. More... | |
std::chrono::milliseconds | timerInterval_ |
The minimum time to wait between calls to execute(). More... | |
QueueJobParameter | queueJobParameter_ |
Private Member Functions | |
void | invokeOnTimer () |
Calls onTimer() if in the right state. More... | |
Private Attributes | |
boost::asio::basic_waitable_timer< std::chrono::steady_clock > | timer_ |
This class is an "active" object.
It maintains its own timer and dispatches work to a job queue. Implementations derive from this class and override the abstract hook functions in the base.
This class implements an asynchronous loop:
setTimer
.mTimerInterval
, queueJob
is called, which schedules a job to call invokeOnTimer
(or loops back to setTimer if there are too many concurrent jobs).invokeOnTimer
which either breaks the loop if isDone
or calls onTimer
.onTimer
is the only "real" virtual method in this class. It is the callback for when the timeout expires. Generally, its only responsibility is to set mFailed = true
. However, if it wants to implement a policy of retries, then it has a chance to just increment a count of expired timeouts.onTimer
returns, if the object is still not isDone
, then invokeOnTimer
sets another timeout by looping back to setTimer.This loop executes concurrently with another asynchronous sequence, implemented by the subtype, that is trying to make progress and eventually set mComplete = true
. While it is making progress but not complete, it should set mProgress = true
, which is passed to onTimer so it can decide whether to postpone failure and reset the timeout. However, if it can complete all its work in one synchronous step (while it holds the lock), then it can ignore mProgress
.
Definition at line 66 of file TimeoutCounter.h.
|
protected |
Definition at line 81 of file TimeoutCounter.h.
|
protected |
Definition at line 29 of file TimeoutCounter.cpp.
|
protectedvirtualdefault |
|
virtual |
Cancel the task by marking it as failed if the task is not done.
Definition at line 118 of file TimeoutCounter.cpp.
|
protected |
Schedule a call to queueJob() after mTimerInterval.
Definition at line 50 of file TimeoutCounter.cpp.
|
protected |
Queue a job to call invokeOnTimer().
Definition at line 69 of file TimeoutCounter.cpp.
|
protectedpure virtual |
Hook called from invokeOnTimer().
Implemented in ripple::LedgerReplayTask, ripple::InboundLedger, ripple::LedgerDeltaAcquire, ripple::SkipListAcquire, and ripple::TransactionAcquire.
|
protectedpure virtual |
Return a weak pointer to this.
Implemented in ripple::InboundLedger, ripple::LedgerReplayTask, ripple::LedgerDeltaAcquire, ripple::SkipListAcquire, and ripple::TransactionAcquire.
|
protected |
Definition at line 116 of file TimeoutCounter.h.
|
private |
Calls onTimer() if in the right state.
Only called by queueJob().
Definition at line 93 of file TimeoutCounter.cpp.
|
protected |
Definition at line 123 of file TimeoutCounter.h.
|
protected |
Definition at line 124 of file TimeoutCounter.h.
|
mutableprotected |
Definition at line 125 of file TimeoutCounter.h.
|
protected |
The hash of the object (in practice, always a ledger) we are trying to fetch.
Definition at line 129 of file TimeoutCounter.h.
|
protected |
Definition at line 130 of file TimeoutCounter.h.
|
protected |
Definition at line 131 of file TimeoutCounter.h.
|
protected |
Definition at line 132 of file TimeoutCounter.h.
|
protected |
Whether forward progress has been made.
Definition at line 134 of file TimeoutCounter.h.
|
protected |
The minimum time to wait between calls to execute().
Definition at line 136 of file TimeoutCounter.h.
|
protected |
Definition at line 138 of file TimeoutCounter.h.
|
private |
Definition at line 147 of file TimeoutCounter.h.