-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathResourceMonitor.h
114 lines (93 loc) · 3.28 KB
/
ResourceMonitor.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#ifndef MonitorFactoryResources_h_IS_INCLUDED
#define MonitorFactoryResources_h_IS_INCLUDED
#include"SystemManager/IncludeExtLibs.h"
#include <map>
namespace SystemManagerSpace
{
/**
* Retrieves resource consumptions from component factories.
* It is used internally in the SystemManager.
*/
class MonitorFactoryResources : public Thread
{
private:
typedef map<string, ProcessFactoryProxy*> MapProcessFactoryProxy;
typedef map<string, HostResources> MapComponentResources;
typedef map<string, HostInformation> MapComponentInformation;
private:
MapComponentResources mapComponentResources;
MapComponentInformation mapComponentFactories;
MapComponentInformation mapAddProcessFactory;
MapComponentInformation mapRemoveProcessFactory;
int monitorInterval;
Mutex guard;
Mutex updateFactoryProxyGuard;
bool monitorResources;
// These are shared with system manager to synchronize factory communication.
MapProcessFactoryProxy &mapHostProcessFactoryProxy;
Mutex &smMutexProxyGuard;
private:
ProcessFactoryProxy* getOrCreateFactoryProxy(const string &factoryHost, const int &factoryPort);
void updateFactoryMaps();
public:
/**
* Constructor for MonitorFactoryResources.
*
* @param mapFactoryProxy Maps component factory name with ProcessFactoryProxy and is shared with SystemManager.
* @param smMutex Mutex shared with SystemManager to access and update mapFactoryProxy.
* @param interval Monitor interval decides how frequent resources are polled from each ProcessFactory.
* @param autoStart autoStarts thread, default is true.
*/
MonitorFactoryResources(MapProcessFactoryProxy &mapFactoryProxy, Mutex &smMutex, int interval = 1000, bool autoStart = true);
/**
* Stops resource monitor.
*/
~MonitorFactoryResources();
/**
* Main loop that polls resources from ComponentFactories.
*/
virtual void run();
/**
* Shuts down monitor safely. Used by SystemManager.
*/
void Quit();
/**
* Adds factory to monitor.
*
* @param info HostInformation that describes ProcessFactory to add.
*/
void AddFactory(const HostInformation &info);
/**
* Removes factory from monitoring.
*
* @param info HostInformation that describes ProcessFactory to remove.
*/
void RemoveFactory(const HostInformation &info);
/**
* Retrieves all resources from all ComponentFactories including components.
*
* @return string String containing all resource information. Parse string with HostResourcesSpace::ParseHostResourcesFromString.
*/
string GetAllFactoryResources();
/**
* Retrieves resources from given componentName.
*
* @return HostResources HostResources for componentName.
*/
HostResources GetHostResources(const string &componentName);
/**
* Retrieves all resources from all ComponentFactories including components.
*
* @param mapResources Map of all the registered components with resource information.
*/
MapComponentResources GetMapAllResources();
/**
* Sets updated HostResources, received from ProcessFactory.
*
* @param HostInformation Factory's HostInformation
* @param HostResources Updated HostResources.
*/
void SetHostResources(HostInformation &factoryInfo, map<int, HostResources> &mapHostResources);
};
} // namespace SystemManagerSpace
#endif // MonitorFactoryResources_h_IS_INCLUDED