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/clock/abstract_clock.h>
26#include <xrpl/beast/utility/Journal.h>
27#include <boost/asio/basic_waitable_timer.hpp>
28#include <mutex>
29
30namespace ripple {
31
67{
68public:
77 virtual void
78 cancel();
79
80protected:
82
84 {
88 };
89
91 Application& app,
92 uint256 const& targetHash,
93 std::chrono::milliseconds timeoutInterval,
94 QueueJobParameter&& jobParameter,
95 beast::Journal journal);
96
97 virtual ~TimeoutCounter() = default;
98
100 void
102
104 void
106
108 virtual void
109 onTimer(bool progress, ScopedLockType&) = 0;
110
114
115 bool
116 isDone() const
117 {
118 return complete_ || failed_;
119 }
120
121 // Used in this class for access to boost::asio::io_service and
122 // ripple::Overlay. Used in subtypes for the kitchen sink.
126
137
139
140private:
144 void
146
147 boost::asio::basic_waitable_timer<std::chrono::steady_clock> timer_;
148};
149
150} // namespace ripple
151
152#endif
A generic endpoint for log messages.
Definition: Journal.h:59
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:35
std::optional< std::uint32_t > jobLimit