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