-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMaster.cpp
executable file
·74 lines (62 loc) · 1.71 KB
/
Master.cpp
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
#include"Master.h"
#include<iostream>
#include "TaskManager.h"
#include "server.h"
#include <sstream>
extern EventEngine *evEngGlobal;
Master::Master()
{
}
void Master::startMaster()
{
std::cout<<"\nMaster Started\nReady To take Events";
}
void Master::handleCliMessage(Buffer &buffer)
{
CliControlMessage msg;
msg.decode(buffer);
switch(msg.subType){
case CLI_CONTROL_START_TASK:
startTaskManager(evEngGlobal->getFreeGroup(),msg);
break;
case CLI_CONTROL_SHOW_GROUPS:
ShowCliRequest::showGroups();
}
}
void Master::stopTaskManager(TaskManager * tm,std::string& output)
{
std::cout<<"\nTASK DONE"<<"\nOUTPUTFILE: "<<output;
//tm->printStats();
delete tm;
}
void Master::startTaskManager(int groupId, CliControlMessage& msg)
{
if(groupId == -1) {
std::cout<<"\nNo Group Available";
return; //do nothing
}
TaskManager *tm = new TaskManager(groupId, msg.taskType, msg.inputFile, msg.delimiter, msg.taskTimeOut);
tm->start();
std::cout<<"\n Start Task";
}
void ShowCliRequest::showGroups()
{
std::tr1::unordered_map<groupId, std::set<clientFd> >::iterator it;
std::stringstream ss;
if( evEngGlobal->groupClientMap.size() == 0){
ss<<"\nNo Groups and Clients Registered";
}
for (it = evEngGlobal->groupClientMap.begin(); it!= evEngGlobal->groupClientMap.end(); it++) {
if(it->first == -1) continue;
ss<<"\nGROUP ID: "<<it->first;
ss<<", NUMBER OF CLIENTS: "<<(it->second).size();
}
char buf[500];
CliControlMessage climsg;
climsg.reqType = CLI_CONTROL_MESSAGE;
climsg.subType = CLI_CONTROL_GROUPS;
climsg.stats = ss.str();
Buffer buffer(buf,512);
climsg.encode(buffer);
evEngGlobal->sendMessage(evEngGlobal->cliFd, buf, buffer.getSize());
}