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
26#include <xrpl/beast/utility/Journal.h>
27
28#include <boost/asio/basic_waitable_timer.hpp>
29
30#include <mutex>
31
32namespace ripple {
33
69{
70public:
79 virtual void
80 cancel();
81
82protected:
84
91
93 Application& app,
94 uint256 const& targetHash,
95 std::chrono::milliseconds timeoutInterval,
96 QueueJobParameter&& jobParameter,
97 beast::Journal journal);
98
99 virtual ~TimeoutCounter() = default;
100
102 void
104
106 void
108
110 virtual void
111 onTimer(bool progress, ScopedLockType&) = 0;
112
116
117 bool
118 isDone() const
119 {
120 return complete_ || failed_;
121 }
122
123 // Used in this class for access to boost::asio::io_context and
124 // ripple::Overlay. Used in subtypes for the kitchen sink.
128
139
141
142private:
146 void
148
149 boost::asio::basic_waitable_timer<std::chrono::steady_clock> timer_;
150};
151
152} // namespace ripple
153
154#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_
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:25
JobType
Definition Job.h:35
std::optional< std::uint32_t > jobLimit