import org.apache.zookeeper.*;
import org.apache.zookeeper.data.Stat;
public class ZooKeeperExample implements Watcher {
private static final String ZOOKEEPER_ADDRESS = "localhost:2181";
private static final int SESSION_TIMEOUT = 3000;
private ZooKeeper zooKeeper;
public void connect() throws Exception {
zooKeeper = new ZooKeeper(ZOOKEEPER_ADDRESS, SESSION_TIMEOUT, this);
}
public void createZNode(String path, byte[] data) throws Exception {
zooKeeper.create(path, data, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
}
public void deleteZNode(String path) throws Exception {
zooKeeper.delete(path, -1);
}
public byte[] getZNodeData(String path) throws Exception {
Stat stat = new Stat();
return zooKeeper.getData(path, false, stat);
}
public void process(WatchedEvent event) {
}
}