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