rippled
ripple
core
Job.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_CORE_JOB_H_INCLUDED
21
#define RIPPLE_CORE_JOB_H_INCLUDED
22
23
#include <ripple/basics/CountedObject.h>
24
#include <ripple/core/ClosureCounter.h>
25
#include <ripple/core/LoadMonitor.h>
26
#include <
functional
>
27
28
#include <
functional
>
29
30
namespace
ripple
{
31
32
// Note that this queue should only be used for CPU-bound jobs
33
// It is primarily intended for signature checking
34
35
enum
JobType
{
36
// Special type indicating an invalid job - will go away soon.
37
jtINVALID
= -1,
38
39
// Job types - the position in this enum indicates the job priority with
40
// earlier jobs having lower priority than later jobs. If you wish to
41
// insert a job at a specific priority, simply add it at the right location.
42
43
jtPACK
,
// Make a fetch pack for a peer
44
jtPUBOLDLEDGER
,
// An old ledger has been accepted
45
jtCLIENT
,
// A placeholder for the priority of all jtCLIENT jobs
46
jtCLIENT_SUBSCRIBE
,
// A websocket subscription by a client
47
jtCLIENT_FEE_CHANGE
,
// Subscription for fee change by a client
48
jtCLIENT_CONSENSUS
,
// Subscription for consensus state change by a client
49
jtCLIENT_ACCT_HIST
,
// Subscription for account history by a client
50
jtCLIENT_SHARD
,
// Client request for shard archiving
51
jtCLIENT_RPC
,
// Client RPC request
52
jtCLIENT_WEBSOCKET
,
// Client websocket request
53
jtRPC
,
// A websocket command from the client
54
jtSWEEP
,
// Sweep for stale structures
55
jtVALIDATION_ut
,
// A validation from an untrusted source
56
jtMANIFEST
,
// A validator's manifest
57
jtUPDATE_PF
,
// Update pathfinding requests
58
jtTRANSACTION_l
,
// A local transaction
59
jtREPLAY_REQ
,
// Peer request a ledger delta or a skip list
60
jtLEDGER_REQ
,
// Peer request ledger/txnset data
61
jtPROPOSAL_ut
,
// A proposal from an untrusted source
62
jtREPLAY_TASK
,
// A Ledger replay task/subtask
63
jtTRANSACTION
,
// A transaction received from the network
64
jtMISSING_TXN
,
// Request missing transactions
65
jtREQUESTED_TXN
,
// Reply with requested transactions
66
jtBATCH
,
// Apply batched transactions
67
jtLEDGER_DATA
,
// Received data for a ledger we're acquiring
68
jtADVANCE
,
// Advance validated/acquired ledgers
69
jtPUBLEDGER
,
// Publish a fully-accepted ledger
70
jtTXN_DATA
,
// Fetch a proposed set
71
jtWAL
,
// Write-ahead logging
72
jtVALIDATION_t
,
// A validation from a trusted source
73
jtWRITE
,
// Write out hashed objects
74
jtACCEPT
,
// Accept a consensus ledger
75
jtPROPOSAL_t
,
// A proposal from a trusted source
76
jtNETOP_CLUSTER
,
// NetworkOPs cluster peer report
77
jtNETOP_TIMER
,
// NetworkOPs net timer processing
78
jtADMIN
,
// An administrative operation
79
80
// Special job types which are not dispatched by the job pool
81
jtPEER
,
82
jtDISK
,
83
jtTXN_PROC
,
84
jtOB_SETUP
,
85
jtPATH_FIND
,
86
jtHO_READ
,
87
jtHO_WRITE
,
88
jtGENERIC
,
// Used just to measure time
89
90
// Node store monitoring
91
jtNS_SYNC_READ
,
92
jtNS_ASYNC_READ
,
93
jtNS_WRITE
,
94
};
95
96
class
Job
:
public
CountedObject
<Job>
97
{
98
public
:
99
using
clock_type
=
std::chrono::steady_clock
;
100
107
// VFALCO NOTE I'd prefer not to have a default constructed object.
108
// What is the semantic meaning of a Job with no associated
109
// function? Having the invariant "all Job objects refer to
110
// a job" would reduce the number of states.
111
//
112
Job
();
113
114
Job
(
JobType
type,
std::uint64_t
index);
115
116
// VFALCO TODO try to remove the dependency on LoadMonitor.
117
Job
(
JobType
type,
118
std::string
const
& name,
119
std::uint64_t
index,
120
LoadMonitor
& lm,
121
std::function
<
void
()>
const
& job);
122
123
JobType
124
getType
()
const
;
125
127
clock_type::time_point
const
&
128
queue_time
()
const
;
129
130
void
131
doJob
();
132
133
// These comparison operators make the jobs sort in priority order
134
// in the job set
135
bool
136
operator<
(
const
Job
& j)
const
;
137
bool
138
operator>
(
const
Job
& j)
const
;
139
bool
140
operator<=
(
const
Job
& j)
const
;
141
bool
142
operator>=
(
const
Job
& j)
const
;
143
144
private
:
145
JobType
mType
;
146
std::uint64_t
mJobIndex
;
147
std::function
<void()>
mJob
;
148
std::shared_ptr<LoadEvent>
m_loadEvent
;
149
std::string
mName
;
150
clock_type::time_point
m_queue_time
;
151
};
152
153
using
JobCounter
=
ClosureCounter<void>
;
154
155
}
// namespace ripple
156
157
#endif
ripple::jtCLIENT_SUBSCRIBE
@ jtCLIENT_SUBSCRIBE
Definition:
Job.h:46
ripple::jtTRANSACTION
@ jtTRANSACTION
Definition:
Job.h:63
std::chrono::steady_clock
ripple::Job::mName
std::string mName
Definition:
Job.h:149
ripple::jtHO_WRITE
@ jtHO_WRITE
Definition:
Job.h:87
ripple::CountedObject
Tracks the number of instances of an object.
Definition:
CountedObject.h:124
std::string
STL class.
std::shared_ptr
STL class.
ripple::jtCLIENT
@ jtCLIENT
Definition:
Job.h:45
ripple::jtMANIFEST
@ jtMANIFEST
Definition:
Job.h:56
ripple::Job::mJob
std::function< void()> mJob
Definition:
Job.h:147
ripple::Job::operator>=
bool operator>=(const Job &j) const
Definition:
Job.cpp:88
ripple::jtPATH_FIND
@ jtPATH_FIND
Definition:
Job.h:85
ripple::jtACCEPT
@ jtACCEPT
Definition:
Job.h:74
functional
ripple::jtHO_READ
@ jtHO_READ
Definition:
Job.h:86
ripple::jtMISSING_TXN
@ jtMISSING_TXN
Definition:
Job.h:64
ripple::jtREPLAY_TASK
@ jtREPLAY_TASK
Definition:
Job.h:62
ripple::Job::mJobIndex
std::uint64_t mJobIndex
Definition:
Job.h:146
ripple::jtNETOP_CLUSTER
@ jtNETOP_CLUSTER
Definition:
Job.h:76
ripple::Job::queue_time
clock_type::time_point const & queue_time() const
Returns the time when the job was queued.
Definition:
Job.cpp:56
ripple::jtNS_SYNC_READ
@ jtNS_SYNC_READ
Definition:
Job.h:91
ripple::jtCLIENT_CONSENSUS
@ jtCLIENT_CONSENSUS
Definition:
Job.h:48
std::function
ripple::jtUPDATE_PF
@ jtUPDATE_PF
Definition:
Job.h:57
ripple::jtADMIN
@ jtADMIN
Definition:
Job.h:78
ripple::jtNS_WRITE
@ jtNS_WRITE
Definition:
Job.h:93
ripple::Job::operator<=
bool operator<=(const Job &j) const
Definition:
Job.cpp:112
ripple::jtSWEEP
@ jtSWEEP
Definition:
Job.h:54
ripple::jtWRITE
@ jtWRITE
Definition:
Job.h:73
ripple::jtCLIENT_RPC
@ jtCLIENT_RPC
Definition:
Job.h:51
ripple::Job::operator<
bool operator<(const Job &j) const
Definition:
Job.cpp:100
ripple::jtLEDGER_DATA
@ jtLEDGER_DATA
Definition:
Job.h:67
ripple::jtBATCH
@ jtBATCH
Definition:
Job.h:66
ripple::jtTXN_DATA
@ jtTXN_DATA
Definition:
Job.h:70
ripple::jtCLIENT_WEBSOCKET
@ jtCLIENT_WEBSOCKET
Definition:
Job.h:52
ripple::jtTRANSACTION_l
@ jtTRANSACTION_l
Definition:
Job.h:58
ripple::jtPUBOLDLEDGER
@ jtPUBOLDLEDGER
Definition:
Job.h:44
ripple::jtDISK
@ jtDISK
Definition:
Job.h:82
ripple::jtTXN_PROC
@ jtTXN_PROC
Definition:
Job.h:83
ripple::Job::Job
Job()
Default constructor.
Definition:
Job.cpp:26
ripple::jtPROPOSAL_t
@ jtPROPOSAL_t
Definition:
Job.h:75
ripple::jtNETOP_TIMER
@ jtNETOP_TIMER
Definition:
Job.h:77
ripple::jtGENERIC
@ jtGENERIC
Definition:
Job.h:88
ripple::jtVALIDATION_t
@ jtVALIDATION_t
Definition:
Job.h:72
ripple::jtINVALID
@ jtINVALID
Definition:
Job.h:37
ripple::jtOB_SETUP
@ jtOB_SETUP
Definition:
Job.h:84
ripple::jtRPC
@ jtRPC
Definition:
Job.h:53
ripple::Job
Definition:
Job.h:96
ripple::ClosureCounter< void >
std::uint64_t
ripple::LoadMonitor
Definition:
LoadMonitor.h:36
ripple::jtPUBLEDGER
@ jtPUBLEDGER
Definition:
Job.h:69
ripple::jtPEER
@ jtPEER
Definition:
Job.h:81
ripple::jtCLIENT_ACCT_HIST
@ jtCLIENT_ACCT_HIST
Definition:
Job.h:49
ripple::jtCLIENT_FEE_CHANGE
@ jtCLIENT_FEE_CHANGE
Definition:
Job.h:47
ripple::Job::mType
JobType mType
Definition:
Job.h:145
ripple::jtREQUESTED_TXN
@ jtREQUESTED_TXN
Definition:
Job.h:65
ripple::jtPACK
@ jtPACK
Definition:
Job.h:43
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition:
RCLCensorshipDetector.h:29
ripple::jtVALIDATION_ut
@ jtVALIDATION_ut
Definition:
Job.h:55
ripple::jtWAL
@ jtWAL
Definition:
Job.h:71
ripple::jtREPLAY_REQ
@ jtREPLAY_REQ
Definition:
Job.h:59
ripple::jtPROPOSAL_ut
@ jtPROPOSAL_ut
Definition:
Job.h:61
ripple::JobType
JobType
Definition:
Job.h:35
ripple::Job::getType
JobType getType() const
Definition:
Job.cpp:50
ripple::Job::operator>
bool operator>(const Job &j) const
Definition:
Job.cpp:76
ripple::jtADVANCE
@ jtADVANCE
Definition:
Job.h:68
ripple::Job::doJob
void doJob()
Definition:
Job.cpp:62
ripple::Job::m_queue_time
clock_type::time_point m_queue_time
Definition:
Job.h:150
ripple::jtCLIENT_SHARD
@ jtCLIENT_SHARD
Definition:
Job.h:50
ripple::Job::m_loadEvent
std::shared_ptr< LoadEvent > m_loadEvent
Definition:
Job.h:148
ripple::jtNS_ASYNC_READ
@ jtNS_ASYNC_READ
Definition:
Job.h:92
ripple::jtLEDGER_REQ
@ jtLEDGER_REQ
Definition:
Job.h:60
Generated by
1.8.17