分享

Zookeeper如何正确设置和获取watcher

bob007 发表于 2015-9-17 19:08:50 [显示全部楼层] 回帖奖励 阅读模式 关闭右栏 0 11701
Zookeeper如何正确设置和获取watcher

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


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


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

对父节点的变更以及孙节点的变更都不会触发watcher,而对watcher本身节点以及子节点的变更会触发watcher,具体参照下表。
操作方法触发watcherwatcher statewatcher typewatcher path
Create当前节点getdata××××
getchildren34
exists××××
set当前节点getdata33
getchildren××××
exists33
delete当前节点getdata32
getchildren32
exists32
create子节点getdata××××
getchildren34
exists××××
set子节点getdata××××
getchildren××××
exists××××
delete子节点getdata××××
getchildren34
exists××××
恢复连接getdata1-1×
getchildren1-1×
exists1-1×
恢复连接session未超时getdata-112-1×
getchildren-112-1×
exists-112-1×
恢复连接session超时getdata3-1×
getchildren3-1×
exists3-1×
注:×表示否,√表示是。
更多参见 http://tech.uc.cn/?p=1189,不过该文章中第五节对event和state的说明有误,请仔细辨别。

没找到任何评论,期待你打破沉寂

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

推荐上一条 /2 下一条