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