import org.apache.zookeeper.*;
public class ZooKeeperExample {
private static final String ZOOKEEPER_ADDRESS = "localhost:2181";
private static final int SESSION_TIMEOUT = 15000;
public static void main(String[] args) throws Exception {
ZooKeeper zooKeeper = new ZooKeeper(ZOOKEEPER_ADDRESS, SESSION_TIMEOUT, null);
String nodePath = "/example";
String nodeData = "Hello ZooKeeper!";
zooKeeper.create(nodePath, nodeData.getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
byte[] data = zooKeeper.getData(nodePath, false, null);
System.out.println("Node Data: " + new String(data));
String newData = "Hello World!";
zooKeeper.setData(nodePath, newData.getBytes(), -1);
zooKeeper.delete(nodePath, -1);
zooKeeper.close();
}
}