zookeeper-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ted Dunning <ted.dunn...@gmail.com>
Subject Re: the event is not nidified
Date Tue, 21 Jun 2011 03:20:12 GMT
Note the part about "and clear the watch"

http://zookeeper.apache.org/doc/r3.1.2/zookeeperProgrammers.html#sc_zkDataMode_watches

your process method must reset the watch.  This behavior is intentional and
quite important for ZK to work correctly.

2011/6/21 lei liu <liulei412@gmail.com>

> 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
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message