在Zookeeper节点操作-1使用了同步返回,这里举几个节点操作回调接口的函数。
在这篇里添加了NodeChildrenChanged事件,该事件是对节点下的子节点的创建和删除进行监听。
注意事项:临时节点下不能创建子节点
package ghs.zook;
import java.io.IOException;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.apache.zookeeper.*;
import org.apache.zookeeper.data.Stat;
public class ZooKeeperTest implements Watcher{
public static final String CONNECTION_STR = "10.1.1.165:2181,10.1.1.165:2182,10.1.1.165:2183";
public static final int SESSION_TIME_OUT = 5000;
private CountDownLatch latch = new CountDownLatch(1);
public static final String ROOT = "/zk-root";
private ZooKeeper zk = null;
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
ZooKeeperTest zooTest = new ZooKeeperTest();
zooTest.createConnection();
if(zooTest.exists(ROOT) == null) {
zooTe