hadoop-zookeeper-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Eric Bowman <ebow...@boboco.ie>
Subject Re: Watches
Date Thu, 04 Jun 2009 19:38:16 GMT
Avinash Lakshman wrote:
> Hi All
>
> I have a znode named /A. Now I will over time create znodes below it such
> /A/A1, /A/A2, ..., /A/An etc. Now every time I create this sub znode I need
> to have all my processes notified. Can I get by just setting one watch on
> /A? So my set up looks as follows:
>
> stat = zk_.exists(path + "/A", true);
> if ( stat == null )
>  {
>        zk_.create("/A", new byte[0], Ids.OPEN_ACL_UNSAFE,
> CreateMode.PERSISTENT);
>  }
>
> This doesn't seem to trigger any watch when I add the sub znodes. What am I
> doing wrong

Try:

zk_.watchChildren( "/A", true )

What you are doing watches changes to the data at /A, not its children.

>From the javadocs:


          getChildren

    public List <http://java.sun.com/javase/6/docs/api/java/util/List.html?is-external=true><String
<http://java.sun.com/javase/6/docs/api/java/lang/String.html?is-external=true>> *getChildren*(String
<http://java.sun.com/javase/6/docs/api/java/lang/String.html?is-external=true> path,
                                    Watcher <http://hadoop.apache.org/zookeeper/docs/current/api/org/apache/zookeeper/Watcher.html>
watcher)
                             throws KeeperException <http://hadoop.apache.org/zookeeper/docs/current/api/org/apache/zookeeper/KeeperException.html>,
                                    InterruptedException <http://java.sun.com/javase/6/docs/api/java/lang/InterruptedException.html?is-external=true>

    Return the list of the children of the node of the given path.

    If the watch is non-null and the call is successful (no exception is
    thrown), a watch will be left on the node with the given path. The
    watch willbe triggered by a successful operation that deletes the
    node of the given path or creates/delete a child under the node.


cheers,
Eric

-- 
Eric Bowman
Boboco Ltd
ebowman@boboco.ie
http://www.boboco.ie/ebowman/pubkey.pgp
+35318394189/+353872801532


Mime
View raw message