You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@zookeeper.apache.org by Hanson Char <ha...@gmail.com> on 2008/12/10 09:19:54 UTC

Missing statement in DataMonitor example ?

I wonder if there is a missing statement (bug?) in the example:

 http://hadoop.apache.org/zookeeper/docs/r3.0.1/javaExample.html#sc_DataMonitor

public void process(WatchedEvent event) {
           ...
           case SyncConnected:
               // Everything is happy. Lets kick things off
               // again by checking the existence of the znode
               break;

               ...

According to the comment, shouldn't ZooKeeper.exists be invoked ?  Like so:

           case SyncConnected:
               // Everything is happy. Lets kick things off
               // again by checking the existence of the znode
               zk.exists(znode, true, this, null);
               break;

Or am I missing something ?

Regards,
Hanson

Re: Missing statement in DataMonitor example ?

Posted by Patrick Hunt <ph...@apache.org>.
Hi Hanson, I think that the code is OK in this situation, however the 
comment is misleading.

In ZooKeeper version 3 watches are re-registered when the client 
reconnects to a server. See this section of the docs:
http://hadoop.apache.org/zookeeper/docs/r3.0.1/zookeeperProgrammers.html#ch_zkWatches

Specifically this:

"Watches will not be received while disconnected from a server. When a 
client reconnects, any previously registered watches will be 
reregistered and triggered if needed."

I have created a jira to improve these docs:
https://issues.apache.org/jira/browse/ZOOKEEPER-253

Thanks for bringing this to our attention!

Patrick

Hanson Char wrote:
> I wonder if there is a missing statement (bug?) in the example:
> 
>  http://hadoop.apache.org/zookeeper/docs/r3.0.1/javaExample.html#sc_DataMonitor
> 
> public void process(WatchedEvent event) {
>            ...
>            case SyncConnected:
>                // Everything is happy. Lets kick things off
>                // again by checking the existence of the znode
>                break;
> 
>                ...
> 
> According to the comment, shouldn't ZooKeeper.exists be invoked ?  Like so:
> 
>            case SyncConnected:
>                // Everything is happy. Lets kick things off
>                // again by checking the existence of the znode
>                zk.exists(znode, true, this, null);
>                break;
> 
> Or am I missing something ?
> 
> Regards,
> Hanson