I use Zookeeper 3.3.3 version.
I create "test" znode, and I add many children for the znode. I want to
listen EventType.NodeChildrenChanged event, when there is
EventType.NodeChildrenChanged event, I print the event information, example
below code:
public class DisplayGroup implements Watcher {
private static final int SESSION_TIMEOUT = 5000;
protected ZooKeeper zk;
public void connect(String hosts) throws IOException,
InterruptedException {
zk = new ZooKeeper(hosts, SESSION_TIMEOUT, this);
}
@Override
public void process(WatchedEvent event) {
System.out.println(this.getClass().getName() + ": " + event);
}
public void close() throws InterruptedException {
zk.close();
}
public void list(String groupName) throws KeeperException,
InterruptedException {
String path = "/" + groupName;
try {
List<String> children = zk.getChildren(path, true);
if (children.isEmpty()) {
System.out.printf("No members in group %s\n", groupName);
}
for (String child : children) {
System.out.println(child);
}
} catch (KeeperException.NoNodeException e) {
System.out.printf("Group %s does not exist\n", groupName);
}
}
public static void main(String[] args) throws Exception {
DisplayGroup listGroup = new DisplayGroup();
String connectString = "localhost:2181";
listGroup.connect(connectString);
listGroup.list("test");
Thread.sleep(Long.MAX_VALUE);
}
}
I add many children to the "test" znode, but the process() method of
DisplayGroup calss only is called one time, the output information is:
1308621717188
1308621719250
examples.DisplayGroup: WatchedEvent state:SyncConnected
type:NodeChildrenChanged path:/test
I want to know why the process() method of DisplayGroup calss is not called
many times when I add many children to the "test" znode?
Thanks,
LiuLei