hce-node application  1.4.3
HCE Hierarchical Cluster Engine node application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ServiceMessages.hpp
Go to the documentation of this file.
1 
15 #ifndef ROUTE_MESSAGE_HPP
16 #define ROUTE_MESSAGE_HPP
17 
18 #include <Poco/JSON/Object.h>
19 #include <Poco/JSON/Array.h>
20 
21 #include "JsonSerializable.hpp"
22 #include "HandlerTypes.hpp"
23 
24 namespace HCE
25 {
26 namespace handlers
27 {
28 //-----------------------------------------------------------------------------
30 {
31 public:
33  {
38  };
39 public:
40  RouteMessage(std::vector<ClientWorkerItem>& queue_);
41  ~RouteMessage(void) {}
42 
43  bool serialize(std::string& json);
44  bool unserialize(const std::string& json);
45 
46  std::string build(const std::string& title="");
47  void extract(const std::string& title, const std::string& msgBody);
48 
49  void clear(void);
50 
51  static std::vector<std::string> extractIdentityNames(const std::string& routeMessage);
52  static std::string buildIdentityNames(const std::vector<ClientWorkerItem>& clientQueue);
53  static std::string buildIdentityNames(const std::vector<std::string>& names);
54 
55  static std::vector<std::string> extractRouteNames(const std::vector<ClientWorkerItem>& clientQueue);
56 
57  std::vector<std::string> extractRouteNames(void);
58 
59 private:
60  void packToObject(Poco::JSON::Object& obj, const std::vector<ClientWorkerItem>& workerItem);
61  void unpackFromObject(Poco::JSON::Object& obj, std::vector<ClientWorkerItem>& workerItem);
62 
63  static void extractRouteNames(std::vector<std::string>& routeNames, const std::vector<ClientWorkerItem>& clientQueue);
64 
66  std::vector<ClientWorkerItem>& queue;
67 
68  typedef IJsonSerializable inherited;
69 };
70 //-----------------------------------------------------------------------------
71 //-----------------------------------------------------------------------------
73 {
74  // json route message names
75  const std::string MANAGER_ROLE = "role";
76  const std::string NODES_NAMES = "nodes";
77  const std::string RESOURCES_USAGE_ALGORITHM = "alg";
78  const std::string RESOURCES_USAGE_ALGORITHM_WEIGHTS = "alg_weights";
79  const std::string RESOURCES_USAGE_LIMITS = "limits";
80 public:
82  {
86  };
87 public:
88  RequestRouteMessage(const std::string& json="");
90 
91  bool serialize(std::string& json);
92  bool unserialize(const std::string& json);
93 
94  void clear(void);
95 
96  void setManagerRole(unsigned int managerRole_) {managerRole=managerRole_;}
97  unsigned int getManagerRole(void) const {return managerRole;}
98 
99  void setNodesNames(std::vector<std::string> nodesNames_) {nodesNames=nodesNames_;}
100  std::vector<std::string> getNodesNames(void) const {return nodesNames;}
101 
102  void setResourcesUsageAlgorithm(unsigned int resourcesUsageAlgorithm_) {resourcesUsageAlgorithm=resourcesUsageAlgorithm_;}
103  unsigned int getResourcesUsageAlgorithm(void) const {return resourcesUsageAlgorithm;}
104 
105  void setResourcesUsageAlgorithmWeights(const std::string& resourcesUsageAlgorithmWeights_) {resourcesUsageAlgorithmWeights=resourcesUsageAlgorithmWeights_;}
106  std::string getResourcesUsageAlgorithmWeights(void) const {return resourcesUsageAlgorithmWeights;}
107 
108  void setResourcesUsageLimits(const std::string& resourcesUsageLimits_) {resourcesUsageLimits=resourcesUsageLimits_;}
109  std::string getResourcesUsageLimits(void) const {return resourcesUsageLimits;}
110 private:
111  unsigned int managerRole;
112  std::vector<std::string> nodesNames;
113  unsigned int resourcesUsageAlgorithm;
114  std::string resourcesUsageAlgorithmWeights;
115  std::string resourcesUsageLimits;
116 
117  typedef IJsonSerializable inherited;
118 };
119 //-----------------------------------------------------------------------------
120 //-----------------------------------------------------------------------------
122 {
123 public:
125  {
130  };
131 public:
132  explicit HeartbeatMessage(std::vector<ClientWorkerItem>& queue_, const std::string& resources_="");
134 
135  bool serialize(std::string& json);
136  bool unserialize(const std::string& json);
137 
138  std::string build(const std::string& title=NODE_MSG_HEARTBEAT);
139  void extract(const std::string& message, const std::string& title=NODE_MSG_HEARTBEAT);
140 
141  void clear(void);
142 
143  void setResources(const std::string& resources_) {resources=resources_;}
144  std::string getResources(void) const {return resources;}
145 private:
146  void packToObject(Poco::JSON::Object& obj, const std::vector<ClientWorkerItem>& workerItem);
147  void unpackFromObject(Poco::JSON::Object& obj, std::vector<ClientWorkerItem>& workerItem);
148 
150  std::vector<ClientWorkerItem>& queue;
152  std::string resources;
153 
154  typedef IJsonSerializable inherited;
155 };
156 //-----------------------------------------------------------------------------
157 //-----------------------------------------------------------------------------
159 {
160 public:
162  {
167  };
168 public:
169  explicit PropertyMessage(const std::string& identity_="", const std::string& property_="");
171 
172  bool serialize(std::string& json);
173  bool unserialize(const std::string& json);
174 
175  std::string build(const std::string& title=NODE_MSG_PROPERTIES);
176  void extract(const std::string& message, const std::string& title=NODE_MSG_PROPERTIES);
177 
178  void clear(void);
179 
180  void setIdentity(const std::string& identity_) {identity=identity_;}
181  std::string getIdentity(void) const {return identity;}
182 
183  void setProperty(const std::string& property_) {property=property_;}
184  std::string getProperty(void) const {return property;}
185 private:
186  std::string identity;
187  std::string property;
188 
189  typedef IJsonSerializable inherited;
190 };
191 //-----------------------------------------------------------------------------
192 //-----------------------------------------------------------------------------
193 } // end namespace handlers
194 } // end namespace HCE
195 
196 #endif // ROUTE_MESSAGE_HPP