hce-node application  1.4.3
HCE Hierarchical Cluster Engine node application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ClientWorkerItem.cpp
Go to the documentation of this file.
1 #include <utility>
2 
3 #include "zhelpers.hpp"
4 #include "ClientWorkerItem.hpp"
5 
6 namespace HCE
7 {
8 namespace handlers
9 {
10 //-----------------------------------------------------------------------------
12 : rcounter(0), rdiff(0), shift(0)
13 {
14 }
15 //-----------------------------------------------------------------------------
17 {
18  if (this!=&rhs)
19  {
20  rcounter = rhs.getRcounter();
21  rdiff = rhs.getRdiff();
22  shift = rhs.getShift();
23  }
24  return *this;
25 }
26 //-----------------------------------------------------------------------------
28 {
29  if (this!=&rhs)
30  {
31  rcounter = std::move(rhs.getRcounter());
32  rdiff = std::move(rhs.getRdiff());
33  shift = std::move(rhs.getShift());
34  }
35  return *this;
36 
37 }
38 //-----------------------------------------------------------------------------
40 {
41  rcounter = 0;
42  rdiff = 0;
43  shift = 0;
44 }
45 //-----------------------------------------------------------------------------
47 {
48  size_t delta = abs(s_clock() - rtimestamp);
49  if (delta)
50  {
51  rdiff += delta;
52  ++rcounter;
53  }
54 // std::stringstream outMsg;
55 // outMsg << "TimeoutShiftCounter::recountDiff rtimestamp= " << rtimestamp
56 // << " (s_clock() - rtimestamp)= " << delta << " rdiff= " << rdiff << " rcounter= " << rcounter;
57 // Poco::Logger::root().information(outMsg.str());
58 }
59 //-----------------------------------------------------------------------------
61 {
62  double avgdiff = 0.0;
63  if (rcounter)
64  avgdiff = static_cast<double>(rdiff) / rcounter;
65 
66 // std::stringstream outMsg;
67 // outMsg << "TimeoutShiftCounter::recountShift rdiff= " << rdiff << " rcounter= " << rcounter << " avgdiff= " << avgdiff << " timeout= " << timeout << " shift= " << shift;
68 // Poco::Logger::root().information(outMsg.str());
69 
70  if (avgdiff > timeout)
71  {
72  shift = abs(avgdiff-timeout);
73  if (shift>timeout)
74  shift = timeout;
75  }
76  else
77  {
78  shift = avgdiff;
79  }
80 }
81 //-----------------------------------------------------------------------------
82 //-----------------------------------------------------------------------------
84 : identity(""), expiry(0), frequency(0), count(0), route(), resources(), rtimestamp(s_clock()),
85  shiftCounter(), property(""), cpu(0.0), iowait(0.0)
86 {
87 }
88 //-----------------------------------------------------------------------------
89 ClientWorkerItem::ClientWorkerItem(const std::string& identity_, int64_t expiry_, unsigned long long frequency_, unsigned long long count_)
90 : identity(identity_), expiry(expiry_), frequency(frequency_), count(count_), route(), resources(), rtimestamp(s_clock()),
91  shiftCounter(), property(""), cpu(0.0), iowait(0.0)
92 {
93 }
94 //-----------------------------------------------------------------------------
96 : identity(""), expiry(0), frequency(0), count(0), route(), resources(), rtimestamp(s_clock()),
97  shiftCounter(), property(""), cpu(0.0), iowait(0.0)
98 {
99  (*this) = rhs;
100 }
101 //-----------------------------------------------------------------------------
103 : identity(""), expiry(0), frequency(0), count(0), route(), resources(), rtimestamp(s_clock()),
104  shiftCounter(), property(""), cpu(0.0), iowait(0.0)
105 {
106  (*this) = std::forward<ClientWorkerItem>(rhs);
107 }
108 //-----------------------------------------------------------------------------
110 {
111  if (this!=&rhs)
112  {
113  identity = rhs.identity;
114  expiry = rhs.expiry;
115  frequency = rhs.frequency;
116  count = rhs.count;
117  route = rhs.route;
118  resources = rhs.resources;
119  rtimestamp = rhs.rtimestamp;
121  property = rhs.property;
122  cpu = rhs.cpu;
123  iowait = rhs.iowait;
124  }
125  return *this;
126 }
127 //-----------------------------------------------------------------------------
129 {
130  if (this!=&rhs)
131  {
132  identity = std::move(rhs.identity);
133  expiry = std::move(rhs.expiry);
134  frequency = std::move(rhs.frequency);
135  count = std::move(rhs.count);
136  route = std::move(rhs.route);
137  resources = std::move(rhs.resources);
138  rtimestamp = std::move(rhs.rtimestamp);
139  shiftCounter = std::move(rhs.shiftCounter);
140  property = std::move(rhs.property);
141  cpu = std::move(rhs.cpu);
142  iowait = std::move(rhs.iowait);
143  }
144  return *this;
145 }
146 //-----------------------------------------------------------------------------
148 {
149  identity.clear();
150  expiry = 0;
151  frequency = 0;
152  count = 0;
153  route.clear();
154  resources.clear();
155  rtimestamp = s_clock();
157  property.clear();
158  cpu = 0.0;
159  iowait = 0.0;
160 }
161 //-----------------------------------------------------------------------------
163 {
164  return d1.frequency < d2.frequency;
165 }
166 //-----------------------------------------------------------------------------
167 //-----------------------------------------------------------------------------
168 } // end namespace handlers
169 } // end namespace HCE