国内最全IT社区平台 联系我们 | 收藏本站
华晨云阿里云优惠2
您当前位置:首页 > 服务器 > Zookeeper如何正确设置和获取watcher

Zookeeper如何正确设置和获取watcher

来源:程序员人生   发布时间:2014-12-24 08:30:27 阅读次数:3998次

 Zookeeper如何正确设置和获得watcher


Watcher 设置是开发中最多见的,需要弄清楚watcher的1些基本特点,对exists、getdata、getchild对节点的不同操作会收到不同的 watcher信息


state=⑴12 会话超时状态
state= ⑴13 认证失败状态
state=  1 连接建立中
state= 2 (暂时不清楚如何理解这个状态,ZOO_ASSOCIATING_STATE)
state=3 连接已建立状态
state= 999 无连接状态


type=1 创建节点事件
type=2 删除节点事件
type=3 更改节点事件
type=4 子节点列表变化事件
type= ⑴ 会话session事件
type=⑵ 监控被移除事件

父节点的变更和孙节点的变更都不会触发watcher,而对watcher本身节点和子节点的变更会触发watcher,具体参照下表。

操作 方法 触发watcher watcher state watcher type watcher path
Create当前节点 getdata × × × ×
getchildren 3 4
exists × × × ×
set当前节点 getdata 3 3
getchildren × × × ×
exists 3 3
delete当前节点 getdata 3 2
getchildren 3 2
exists 3 2
create子节点 getdata × × × ×
getchildren 3 4
exists × × × ×
set子节点 getdata × × × ×
getchildren × × × ×
exists × × × ×
delete子节点 getdata × × × ×
getchildren 3 4
exists × × × ×
恢复连接 getdata 1 ×
getchildren 1 ×
exists 1 ×
恢复连接session未超时 getdata ⑴12 ×
getchildren ⑴12 ×
exists ⑴12 ×
恢复连接session超时 getdata 3 ×
getchildren 3 ×
exists 3 ×

注:×表示否,√表示是。
更多参见 http://tech.uc.cn/?p=1189,不过该文章中第5节对event和state的说明有误,请仔细辨别。

生活不易,码农辛苦
如果您觉得本网站对您的学习有所帮助,可以手机扫描二维码进行捐赠
程序员人生
------分隔线----------------------------
分享到:
------分隔线----------------------------
关闭
程序员人生