neptune wrote:
I have a question. I registered a Watcher on a parent znode("/foo").
I create child znode("/foo/bar1") using a zookeeper console.
Test program received Children changed event. But there is no API getting
added znode.
ZooKeeper.getChildren() method returns all children in a parent node.

getChildren is the correct way to access. When you get a notification you don't know if one thing changed, or many. You are just getting a notification that something has changed since you originally set the watch. You need to determine what has changed. Typically it works like this:

1) getchildren(parent, watch)
2) process the result of get children call
3) wait for notification
4) when you get notification from 3), call getchildren(parent, watch) again, notice that you are both getting the children and resetting the watch. Without this step (test and set) you might miss notifications of change. 5) compare the data from 4 with the data from 1 - process any changes (added/removed nodes).

See the recipes page for real world examples.


Reply via email to