rippled
Loading...
Searching...
No Matches
TimeoutCounter.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012, 2013 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or 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#ifndef RIPPLE_APP_LEDGER_TIMEOUTCOUNTER_H_INCLUDED
21#define RIPPLE_APP_LEDGER_TIMEOUTCOUNTER_H_INCLUDED
22
23#include <xrpld/app/main/Application.h>
24#include <xrpld/core/Job.h>
25#include <xrpl/beast/utility/Journal.h>
26
27#include <boost/asio/basic_waitable_timer.hpp>
28
29#include <mutex>
30
31namespace ripple {
32
68{
69public:
78 virtual void
79 cancel();
80
81protected:
83
85 {
89 };
90
92 Application& app,
93 uint256 const& targetHash,
94 std::chrono::milliseconds timeoutInterval,
95 QueueJobParameter&& jobParameter,
96 beast::Journal journal);
97
98 virtual ~TimeoutCounter() = default;
99
101 void
103
105 void
107
109 virtual void
110 onTimer(bool progress, ScopedLockType&) = 0;
111
115
116 bool
117 isDone() const
118 {
119 return complete_ || failed_;
120 }
121
122 // Used in this class for access to boost::asio::io_service and
123 // ripple::Overlay. Used in subtypes for the kitchen sink.
127
138
140
141private:
145 void
147
148 boost::asio::basic_waitable_timer<std::chrono::steady_clock> timer_;
149};
150
151} // namespace ripple
152
153#endif
A generic endpoint for log messages.
Definition: Journal.h:60
This class is an "active" object.
void queueJob(ScopedLockType &)
Queue a job to call invokeOnTimer().
virtual void onTimer(bool progress, ScopedLockType &)=0
Hook called from invokeOnTimer().
bool progress_
Whether forward progress has been made.
void setTimer(ScopedLockType &)
Schedule a call to queueJob() after mTimerInterval.
void invokeOnTimer()
Calls onTimer() if in the right state.
std::chrono::milliseconds timerInterval_
The minimum time to wait between calls to execute().
virtual ~TimeoutCounter()=default
QueueJobParameter queueJobParameter_
beast::Journal journal_
uint256 const hash_
The hash of the object (in practice, always a ledger) we are trying to fetch.
boost::asio::basic_waitable_timer< std::chrono::steady_clock > timer_
virtual std::weak_ptr< TimeoutCounter > pmDowncast()=0
Return a weak pointer to this.
virtual void cancel()
Cancel the task by marking it as failed if the task is not done.
std::recursive_mutex mtx_
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
JobType
Definition: Job.h:34
std::optional< std::uint32_t > jobLimit