Reputation: 10954
This is the method to get data of a znode.
public byte[] getData(String path,
boolean watch,
Stat stat)
throws KeeperException,
InterruptedException;
I am curious about the second argument boolean watch
, mostly I put false
there. But what will Zookeeper do if I pass true
? As far as I see, a default watcher will be called. What does it do?
Upvotes: 2
Views: 3724
Reputation: 5387
If pass true for watch if the data of the znode changes, or the znode is deleted an event will be sent to the client. The client will invoke the default watcher (that you pass to construct the Zookeeper client object) object's process method will be called. process method is passed the WatchedEvent object. We may get eventType, the znode path (if the event is specific to the znode) etc. from the event object. If event type is something like "NodeDataChanged" for example, a call may be be made to Zookeeper to get the modified data and re-establish the watch. Basically, The default watcher implements the "process" method, and the "process" method has the logic about what to do with the event.
You may check the below links: http://zookeeper.apache.org/doc/r3.4.1/api/org/apache/zookeeper/WatchedEvent.html https://zookeeper.apache.org/doc/r3.3.3/api/org/apache/zookeeper/Watcher.html
BTW, zkclient is much simpler zookeeper client library. You may try that also http://mvnrepository.com/artifact/com.101tec/zkclient
Upvotes: 1