forked from zliu1020-zz/Fault-Tolerance
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CreateZNode.java
47 lines (38 loc) · 1.15 KB
/
CreateZNode.java
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
import java.io.*;
import java.util.*;
import org.apache.thrift.*;
import org.apache.thrift.server.*;
import org.apache.thrift.transport.*;
import org.apache.thrift.protocol.*;
import org.apache.zookeeper.*;
import org.apache.zookeeper.data.*;
import org.apache.curator.*;
import org.apache.curator.retry.*;
import org.apache.curator.framework.*;
import org.apache.curator.utils.*;
import org.apache.log4j.*;
public class CreateZNode {
static Logger log;
public static void main(String [] args) throws Exception {
BasicConfigurator.configure();
log = Logger.getLogger(StorageNode.class.getName());
if (args.length != 2) {
System.err.println("Usage: java CreateZKNode zkconnectstring zknode");
System.exit(-1);
}
CuratorFramework curClient =
CuratorFrameworkFactory.builder()
.connectString(args[0])
.retryPolicy(new RetryNTimes(10, 1000))
.connectionTimeoutMs(1000)
.sessionTimeoutMs(10000)
.build();
curClient.start();
Runtime.getRuntime().addShutdownHook(new Thread() {
public void run() {
curClient.close();
}
});
ZKPaths.mkdirs(curClient.getZookeeperClient().getZooKeeper(), args[1]);
}
}