Hi Avinash,
  For watching just one node zoo_exist(path, true) would help you watching
that node. But if you want to see what there was some addition on /A you
should better use getChildren() api.

Also, with your code

>> stat = zk_.exists(path + "/A", true);
>>> if ( stat == null )
>>>  {
>>>        zk_.create("/A", new byte[0], Ids.OPEN_ACL_UNSAFE,
>>> CreateMode.PERSISTENT);
>>>  }
>>> 

Shouldn't it be zk.exists("/A" + path) ?

Also you would create zk.create("/A" + path) ?

No?

Also for more information on the watches you can read in the programmer
manual at 
http://hadoop.apache.org/zookeeper/docs/r3.1.1/

And also the javadocs should give you an idea.


Hope this helps.
Mahadev

On 6/4/09 12:40 PM, "Avinash Lakshman" <avinash.laksh...@gmail.com> wrote:

> I want to get notified whenever any sub znode is created under /A. Only one
> process amongst many will create these sub znodes. But everyone needs to be
> notified about this.
> 
> Cheers
> Avinash
> 
> On Thu, Jun 4, 2009 at 12:38 PM, Eric Bowman <ebow...@boboco.ie> wrote:
> 
>> 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><S
>> tring
>> <
>> 
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/Watc
>> her.html>
>> watcher)
>>                             throws KeeperException <
>> http://hadoop.apache.org/zookeeper/docs/current/api/org/apache/zookeeper/Keep
>> erException.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
>> ebow...@boboco.ie
>> http://www.boboco.ie/ebowman/pubkey.pgp
>> +35318394189/+353872801532<http://www.boboco.ie/ebowman/pubkey.pgp%0A+3531839
>> 4189/+353872801532>
>> 
>> 

Reply via email to