I use the Curator to program the Zookeeper.I want to watch the sub-znodes of zonde.My code looks like:
CuratorFramework frameWork = CuratorFrameworkFactory.builder()
.retryPolicy(new RetryNTimes(3, 1000))
.connectString("127.0.0.1:2181").build();
frameWork.start();
CuratorWatcher watcher = new CuratorWatcher () {
@Override
public void process(WatchedEvent event) throws Exception {
System.out.println("event :" + event);
}
};
frameWork.getChildren().usingWatcher(watcher).forPath("/aa");
frameWork.setData().forPath("/aa/dd", "asdfd".getBytes());
When the setdata for "/aa/dd" is called, I want the watcher is triggered.But failed, does anyone have idea please?
Curator has a recipe that does this. Please see TreeCache: http://curator.apache.org/curator-recipes/tree-cache.html