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