I write Wacher class, I call zk.getData(path, watch, null) in process()
method, example below code:
public class AppVersionMappingChildrenNodeWatcher implements Watcher {
private ZooKeeperManager zooKeeperManager;
protected Logger logger = LoggerFactory.getLogger(this.getClass());
//process biz when some child added or deleted
@Override
public void process(WatchedEvent event) {
//open a watcher
String path = event.getPath();
logger.info("notify path:"+path);
String value = "";
try {
value = zk.getData(path, watcher, null);
logger.info("reMonitor for zookeeper in AppVersionMappingWatcher
success,value is:"+value);
} catch (Exception e) {
//TODO:huangdou.c: i will lost this machine in this zookeeper
call back group
logger.error("reOpen watcher failure, this machine will be lost.
please restart");
}
}
}
If zk.getData(path, watcher, null) throw Exception, the watch will be not
left on the node with the given path. The watch will be not triggered by a
successful operation that sets data on the node, or deletes the node, So my
application will never be notified when the data is changed on the node,
how I can handle the Exception?
Thanks,
LiuLei