-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGroupManager.h
66 lines (51 loc) · 2.08 KB
/
GroupManager.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
#ifndef MembershipManager_GroupManager_h_IsIncluded
#define MembershipManager_GroupManager_h_IsIncluded
#include<map>
#include<sstream>
#include<fstream>
#include "MembershipManager/IncludeExtLibs.h"
using namespace std;
// --------------------------------------------------------
// class GroupManager
// - keeps the groups up-to-date.
// - GroupName == ServiceName
//--------------------------------------------------------
class GroupManager : public GroupManagerInterface, public Thread
{
private:
typedef set<string> SetGroup;
typedef map<string, SetGroup> MapComponentNameGroups;
typedef map<string, HostInformation> MapHostInformation;
typedef map<string, GroupInformation> MapGroupInformation;
typedef map<string, int64> MapAliveCheck;
public:
GroupManager(bool autoStart = false);
~GroupManager();
void StopGroupManager(bool waitForTermination = true);
virtual int LeaveGroup(HostInformation hostInfo, string groupName);
virtual GroupInformation JoinGroup(HostInformation hostInfo, string groupName);
virtual GroupInformation GroupChange(HostInformation hostInfo, string currentGroupName, string newGroupName);
virtual GroupInformation GetGroupInformation(string groupName);
virtual GroupInformation AliveChecker(HostInformation hostInfo, string currentGroupName);
virtual MapGroupInformation GetAllGroupInformation();
protected:
virtual void run();
private:
inline void lock() { mutexUpdate_.lock(); }
inline void unlock() { mutexUpdate_.unlock(); }
inline void wakeAll() { waitForChanges_.wakeAll(); }
private:
bool removeHostFromGroup(const HostInformation &hostInfo, const string &groupName);
bool addHostToGroup(const HostInformation &hostInfo, const string &groupName);
int addOrUpdateHostInfo(const HostInformation &hostInfo);
void createOrUpdateTimeStamp(string componentName);
private:
MapGroupInformation mapGroupInformation_;
MapHostInformation mapHostInformation_;
MapAliveCheck mapAliveCheck_;
MapComponentNameGroups mapComponentNameGroups_;
Mutex mutexUpdate_;
WaitCondition waitForChanges_;
bool runThread_;
};
#endif