/**
* This is a helper function for launching a set of servers
*
* @param numServers
* @return
* @throws IOException
* @throws InterruptedException
*/
private Servers LaunchServers(int numServers) throws IOException, InterruptedException {
int SERVER_COUNT = numServers;
Servers svrs = new Servers();
final int clientPorts[] = new int[SERVER_COUNT];
StringBuilder sb = new StringBuilder();
for(int i = 0; i < SERVER_COUNT; i++) {
clientPorts[i] = PortAssignment.unique();
sb.append("server."+i+"=127.0.0.1:"+PortAssignment.unique()+":"+PortAssignment.unique()+"\n");
}
String quorumCfgSection = sb.toString();
MainThread mt[] = new MainThread[SERVER_COUNT];
ZooKeeper zk[] = new ZooKeeper[SERVER_COUNT];
for(int i = 0; i < SERVER_COUNT; i++) {
mt[i] = new MainThread(i, clientPorts[i], quorumCfgSection);
mt[i].start();
zk[i] = new ZooKeeper("127.0.0.1:" + clientPorts[i], ClientBase.CONNECTION_TIMEOUT, this);
}
waitForAll(zk, States.CONNECTED);
svrs.mt = mt;
svrs.zk = zk;
return svrs;
}
QuorumPeerMainTest.java 文件源码
java
阅读 33
收藏 0
点赞 0
评论 0
项目:ZooKeeper
作者:
评论列表
文章目录