rippled
JobTypes.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_JOBTYPES_H_INCLUDED
21 #define RIPPLE_CORE_JOBTYPES_H_INCLUDED
22 
23 #include <ripple/core/Job.h>
24 #include <ripple/core/JobTypeInfo.h>
25 #include <map>
26 #include <string>
27 #include <type_traits>
28 #include <unordered_map>
29 
30 namespace ripple
31 {
32 
33 class JobTypes
34 {
35 public:
37  using const_iterator = Map::const_iterator;
38 
39 private:
41  : m_unknown (jtINVALID, "invalid", 0, true, std::chrono::milliseconds{0},
43  {
44  using namespace std::chrono_literals;
45  int maxLimit = std::numeric_limits <int>::max ();
46 
47 add( jtPACK, "makeFetchPack", 1, false, 0ms, 0ms);
48 add( jtPUBOLDLEDGER, "publishAcqLedger", 2, false, 10000ms, 15000ms);
49 add( jtVALIDATION_ut, "untrustedValidation", maxLimit, false, 2000ms, 5000ms);
50 add( jtTRANSACTION_l, "localTransaction", maxLimit, false, 100ms, 500ms);
51 add( jtLEDGER_REQ, "ledgerRequest", 2, false, 0ms, 0ms);
52 add( jtPROPOSAL_ut, "untrustedProposal", maxLimit, false, 500ms, 1250ms);
53 add( jtLEDGER_DATA, "ledgerData", 2, false, 0ms, 0ms);
54 add( jtCLIENT, "clientCommand", maxLimit, false, 2000ms, 5000ms);
55 add( jtRPC, "RPC", maxLimit, false, 0ms, 0ms);
56 add( jtUPDATE_PF, "updatePaths", maxLimit, false, 0ms, 0ms);
57 add( jtTRANSACTION, "transaction", maxLimit, false, 250ms, 1000ms);
58 add( jtBATCH, "batch", maxLimit, false, 250ms, 1000ms);
59 add( jtADVANCE, "advanceLedger", maxLimit, false, 0ms, 0ms);
60 add( jtPUBLEDGER, "publishNewLedger", maxLimit, false, 3000ms, 4500ms);
61 add( jtTXN_DATA, "fetchTxnData", 1, false, 0ms, 0ms);
62 add( jtWAL, "writeAhead", maxLimit, false, 1000ms, 2500ms);
63 add( jtVALIDATION_t, "trustedValidation", maxLimit, false, 500ms, 1500ms);
64 add( jtWRITE, "writeObjects", maxLimit, false, 1750ms, 2500ms);
65 add( jtACCEPT, "acceptLedger", maxLimit, false, 0ms, 0ms);
66 add( jtPROPOSAL_t, "trustedProposal", maxLimit, false, 100ms, 500ms);
67 add( jtSWEEP, "sweep", maxLimit, false, 0ms, 0ms);
68 add( jtNETOP_CLUSTER, "clusterReport", 1, false, 9999ms, 9999ms);
69 add( jtNETOP_TIMER, "heartbeat", 1, false, 999ms, 999ms);
70 add( jtADMIN, "administration", maxLimit, false, 0ms, 0ms);
71 
72 add( jtPEER, "peerCommand", 0, true, 200ms, 2500ms);
73 add( jtDISK, "diskAccess", 0, true, 500ms, 1000ms);
74 add( jtTXN_PROC, "processTransaction", 0, true, 0ms, 0ms);
75 add( jtOB_SETUP, "orderBookSetup", 0, true, 0ms, 0ms);
76 add( jtPATH_FIND, "pathFind", 0, true, 0ms, 0ms);
77 add( jtHO_READ, "nodeRead", 0, true, 0ms, 0ms);
78 add( jtHO_WRITE, "nodeWrite", 0, true, 0ms, 0ms);
79 add( jtGENERIC, "generic", 0, true, 0ms, 0ms);
80 add( jtNS_SYNC_READ, "SyncReadNode", 0, true, 0ms, 0ms);
81 add( jtNS_ASYNC_READ, "AsyncReadNode", 0, true, 0ms, 0ms);
82 add( jtNS_WRITE, "WriteNode", 0, true, 0ms, 0ms);
83 
84  }
85 
86 public:
87  static JobTypes const& instance()
88  {
89  static JobTypes const types;
90  return types;
91  }
92 
93  JobTypeInfo const& get (JobType jt) const
94  {
95  Map::const_iterator const iter (m_map.find (jt));
96  assert (iter != m_map.end ());
97 
98  if (iter != m_map.end())
99  return iter->second;
100 
101  return m_unknown;
102  }
103 
104  JobTypeInfo const& getInvalid () const
105  {
106  return m_unknown;
107  }
108 
109  Map::size_type size () const
110  {
111  return m_map.size();
112  }
113 
115  {
116  return m_map.cbegin ();
117  }
118 
120  {
121  return m_map.cbegin ();
122  }
123 
125  {
126  return m_map.cend ();
127  }
128 
130  {
131  return m_map.cend ();
132  }
133 
134 private:
135  void add(JobType jt, std::string name, int limit,
136  bool special, std::chrono::milliseconds avgLatency,
137  std::chrono::milliseconds peakLatency)
138  {
139  assert (m_map.find (jt) == m_map.end ());
140 
141  auto const [_, inserted] = m_map.emplace (
142  std::piecewise_construct,
144  std::forward_as_tuple (jt, name, limit, special,
145  avgLatency, peakLatency));
146 
147  assert (inserted == true);
148  (void)_;
149  (void)inserted;
150  }
151 
154 };
155 
156 }
157 
158 #endif
ripple::jtTRANSACTION
@ jtTRANSACTION
Definition: Job.h:52
ripple::jtHO_WRITE
@ jtHO_WRITE
Definition: Job.h:74
ripple::JobTypes::add
void add(JobType jt, std::string name, int limit, bool special, std::chrono::milliseconds avgLatency, std::chrono::milliseconds peakLatency)
Definition: JobTypes.h:135
std::string
STL class.
ripple::jtCLIENT
@ jtCLIENT
Definition: Job.h:49
ripple::JobTypes
Definition: JobTypes.h:33
ripple::jtPATH_FIND
@ jtPATH_FIND
Definition: Job.h:72
ripple::jtACCEPT
@ jtACCEPT
Definition: Job.h:60
ripple::jtHO_READ
@ jtHO_READ
Definition: Job.h:73
ripple::JobTypes::m_map
Map m_map
Definition: JobTypes.h:153
std::map::find
T find(T... args)
std::map::size
T size(T... args)
ripple::jtNETOP_CLUSTER
@ jtNETOP_CLUSTER
Definition: Job.h:63
std::chrono::milliseconds
ripple::JobTypes::const_iterator
Map::const_iterator const_iterator
Definition: JobTypes.h:37
std::map::emplace
T emplace(T... args)
ripple::jtNS_SYNC_READ
@ jtNS_SYNC_READ
Definition: Job.h:78
ripple::jtUPDATE_PF
@ jtUPDATE_PF
Definition: Job.h:51
ripple::jtADMIN
@ jtADMIN
Definition: Job.h:65
ripple::jtNS_WRITE
@ jtNS_WRITE
Definition: Job.h:80
ripple::jtSWEEP
@ jtSWEEP
Definition: Job.h:62
ripple::jtWRITE
@ jtWRITE
Definition: Job.h:59
ripple::jtLEDGER_DATA
@ jtLEDGER_DATA
Definition: Job.h:48
ripple::JobTypes::cbegin
const_iterator cbegin() const
Definition: JobTypes.h:119
ripple::jtBATCH
@ jtBATCH
Definition: Job.h:53
ripple::jtTXN_DATA
@ jtTXN_DATA
Definition: Job.h:56
ripple::jtTRANSACTION_l
@ jtTRANSACTION_l
Definition: Job.h:45
ripple::jtPUBOLDLEDGER
@ jtPUBOLDLEDGER
Definition: Job.h:43
ripple::jtDISK
@ jtDISK
Definition: Job.h:69
ripple::jtTXN_PROC
@ jtTXN_PROC
Definition: Job.h:70
ripple::jtPROPOSAL_t
@ jtPROPOSAL_t
Definition: Job.h:61
ripple::jtNETOP_TIMER
@ jtNETOP_TIMER
Definition: Job.h:64
ripple::JobTypes::m_unknown
JobTypeInfo m_unknown
Definition: JobTypes.h:152
ripple::JobTypeInfo
Holds all the 'static' information about a job, which does not change.
Definition: JobTypeInfo.h:27
ripple::jtGENERIC
@ jtGENERIC
Definition: Job.h:75
ripple::jtVALIDATION_t
@ jtVALIDATION_t
Definition: Job.h:58
ripple::JobTypes::get
JobTypeInfo const & get(JobType jt) const
Definition: JobTypes.h:93
ripple::JobTypes::instance
static JobTypes const & instance()
Definition: JobTypes.h:87
ripple::jtINVALID
@ jtINVALID
Definition: Job.h:36
ripple::jtOB_SETUP
@ jtOB_SETUP
Definition: Job.h:71
ripple::JobTypes::begin
const_iterator begin() const
Definition: JobTypes.h:114
ripple::jtRPC
@ jtRPC
Definition: Job.h:50
std::forward_as_tuple
T forward_as_tuple(T... args)
map
ripple::jtPUBLEDGER
@ jtPUBLEDGER
Definition: Job.h:55
ripple::jtPEER
@ jtPEER
Definition: Job.h:68
ripple::jtPACK
@ jtPACK
Definition: Job.h:42
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::JobTypes::getInvalid
JobTypeInfo const & getInvalid() const
Definition: JobTypes.h:104
ripple::jtVALIDATION_ut
@ jtVALIDATION_ut
Definition: Job.h:44
ripple::JobTypes::cend
const_iterator cend() const
Definition: JobTypes.h:129
std::map::cbegin
T cbegin(T... args)
std
STL namespace.
ripple::jtWAL
@ jtWAL
Definition: Job.h:57
ripple::JobTypes::end
const_iterator end() const
Definition: JobTypes.h:124
ripple::jtPROPOSAL_ut
@ jtPROPOSAL_ut
Definition: Job.h:47
ripple::JobType
JobType
Definition: Job.h:33
std::map::end
T end(T... args)
ripple::jtADVANCE
@ jtADVANCE
Definition: Job.h:54
ripple::JobTypes::JobTypes
JobTypes()
Definition: JobTypes.h:40
unordered_map
std::numeric_limits
ripple::JobTypes::size
Map::size_type size() const
Definition: JobTypes.h:109
type_traits
ripple::jtNS_ASYNC_READ
@ jtNS_ASYNC_READ
Definition: Job.h:79
ripple::jtLEDGER_REQ
@ jtLEDGER_REQ
Definition: Job.h:46
string