-
Notifications
You must be signed in to change notification settings - Fork 0
/
zk_config.cpp
76 lines (61 loc) · 1.5 KB
/
zk_config.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
//////////////////////////
// Filename: zk_config.cpp
// Author: Martin Almaraz
// Date: Tue Apr 4 18:25:19 PDT 2017
//////////////////////////
#include "zk_config.h"
#include "Server.h"
using namespace std;
zk_config::zk_config()
{
this->tickTime = "2000";
this->dataDir = "/var/lib/zookeeper/";
this->clientPort = "2181";
this->initLimit = "5";
this->syncLimit = "2";
this->numServers = 0;
}
void zk_config::buildConfig(string configName)
{
this->configName = configName;
ofstream file;
file.open(configName + ".cfg", ios::out);
file << "tickTime=" << this->tickTime << endl
<< "dataDir=" << this->dataDir << endl
<< "clientPort=" << this->clientPort << endl
<< "initLimit=" << this->initLimit << endl
<< "syncLimit=" << this->syncLimit << endl;
for(int i = 0; i < this->numServers; i++)
{
file << servers[i] << endl;
}
file.close();
}
void zk_config::setTickTime(string tickTime)
{
this->tickTime = tickTime;
}
void zk_config::setDataDir(string dataDir)
{
this->dataDir = dataDir;
}
void zk_config::setClientPort(string clientPort)
{
this->clientPort = clientPort;
}
void zk_config::setInitLimit(string initLimit)
{
this->initLimit = initLimit;
}
void zk_config::setSyncLimit(string syncLimit)
{
this->syncLimit = syncLimit;
}
void zk_config::setNumServers(int numServers)
{
this->numServers = numServers;
}
void zk_config::addNode(Server server)
{
this->servers.push_back(server.build());
}