Home | About | Sematext search-lucene.com search-hadoop.com
 Search Hadoop and all its subprojects:

Switch to Threaded View
Zookeeper >> mail # user >> the event is not nidified


Copy link to this message
-
Re: the event is not nidified
Hi Ted, thank you for your reply.

Can you tell me why I need to reset the watch? I think that is confusing.

Thanks,

LiuLei
2011/6/21 Ted Dunning <[EMAIL PROTECTED]>

> 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 <[EMAIL PROTECTED]>
>
> > 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
> >
>