just to expand on mahadev's answer a little bit: the basic guarantee is that you will see the watch event before you see the change. so let's say you call getChildren( "/foo", w, acb, ctx) twice and while you do that another client creates a child of /foo. there are three scenarios:

1) the create happens before the first call to getChildren: in this case there is no watch event because the first call to getChildren will list the new child. 2) the create happens after the first call to getChildren and before the second call: in this case the watch event callback will happen at the client before acb is invoked for the result of the second getChildren call. in other words, the first callback to acb for the result of the first getChildren call will not list the newly created child, then you will get a callback on w to say that the list of children of /foo has changed, then you will get second callback on acb for the result of the second call that will list the newly created child. 3) the create happens after the second call to getChildren: in this case acb will be invoked once for each invocation of getChildren and both times acb will have the same list of children, then you will get a callback on w to say that the list of children of /foo has changed.


ben

Mahadev Konar wrote:
Hi martin,
 a call like getchildren(final String path, Watcher watcher,
ChildrenCallback cb, Object ctx)

Means that set a watch on this node for any further changes on the server. A
client will see the response to getchildren data before the above watch is
fired.
Hope that helps.

Thanks
mahadev


On 2/10/10 6:59 PM, "Martin Traverso" <mtrave...@gmail.com> wrote:

What are the ordering guarantees for asynchronous callbacks vs watcher
notifications (Java API) when both are used in the same call? E.g.,
for getChildren(final String path, Watcher watcher, ChildrenCallback cb,
Object ctx)

Will the callback always be invoked before the watcher if there is a state
change on the server at about the same time the call is made?

I *think* that's what's implied by the documentation, but I'm not sure I'm
reading it right:

"All completions for asynchronous calls and watcher callbacks will be made
in order, one at a time. The caller can do any processing they wish, but no
other callbacks will be processed during that time." (
http://hadoop.apache.org/zookeeper/docs/r3.2.2/zookeeperProgrammers.html#Java+
Binding
)

Thanks!

Martin


Reply via email to