hce-node application  1.4.3
HCE Hierarchical Cluster Engine node application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ResourceUsageManager.hpp
Go to the documentation of this file.
1 
14 #ifndef RESOURCE_USAGE_COLLECTION_HPP
15 #define RESOURCE_USAGE_COLLECTION_HPP
16 
17 #include "ClientWorkerItem.hpp"
18 #include "LoggerStream.hpp"
19 
20 namespace HCE
21 {
22 namespace handlers
23 {
24 //-----------------------------------------------------------------------------
26 {
27  enum {MAX_SIZE=10};
28 
29  struct Weights
30  {
31  Weights(void) :prev(0.0), last(0.0), diff(0.0), stepIndex(0), listWeights() {}
32  double prev;
33  double last;
34  double diff;
35  size_t stepIndex;
36  std::vector<double> listWeights;
37  };
38 public:
41 
42  void add(const std::string& identity, ResourceUsageCollection& collection, const ResourceUsageData& resourceUsageData, size_t maxSize=MAX_SIZE);
43  void add(const std::string& identity, ResourceUsageCollection& collection, const std::string& resources, size_t maxSize=MAX_SIZE);
44 
45  ResourceUsageData calculateAverage(const std::string& identity, ResourceUsageCollection& collection);
46 
47  bool isAllowedRange(const std::string& identity, double maxAllowedRange);
48 
49  void setMaxSize(size_t maxSize_);
50  size_t getMaxSize(void) const {return maxSize;}
51 
52  size_t nextStep(const std::string& identity);
53  size_t prevStep(const std::string& identity);
54 
55  void setLastWeight(const std::string& identity, double weight);
56  double getLastWeight(const std::string& identity);
57 
58  void setListWeights(const std::string& identity, const std::vector<double>& listWeights);
59  std::vector<double> getListWeights(const std::string& identity);
60 
61 protected:
62  ResourceUsageData averageValue(ResourceUsageCollection& collection, size_t count);
63 private:
65  size_t maxSize;
67  std::vector<size_t> steps;
69  std::map<std::string, Weights> weights; // key is identity
70  //Logger stream use now as log buffer
71  HCE::LoggerStream& logger;
72 };
73 //-----------------------------------------------------------------------------
74 //-----------------------------------------------------------------------------
75 } // end namespace handlers
76 } // end namespace HCE
77 
78 #endif // RESOURCE_USAGE_COLLECTION_HPP