Zookeeper如何正确设置和获取watcher
2016-07-11 10:57
309 查看
http://blog.csdn.net/qq910894904/article/details/41726279
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,具体参照下表。
操作 | 方法 | 触发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 | -1 | × |
getchildren | √ | 1 | -1 | × | |
exists | √ | 1 | -1 | × | |
恢复连接session未超时 | getdata | √ | -112 | -1 | × |
getchildren | √ | -112 | -1 | × | |
exists | √ | -112 | -1 | × | |
恢复连接session超时 | getdata | √ | 3 | -1 | × |
getchildren | √ | 3 | -1 | × | |
exists | √ | 3 | -1 | × |
更多参见 http://tech.uc.cn/?p=1189,不过该文章中第五节对event和state的说明有误,请仔细辨别。
相关文章推荐
- R语言中描述统计量的多种方法summary()、describe()、str()等
- 用StringBuilder连接MYSQL字段时被清空的问题
- C/C++常考面试题(一):代码分析
- 文本闪烁函数
- HBase 修改TTL 属性释放空间
- 深入浅出Zookeeper之二Session建立
- 内核怎样管理你的内存【转】
- Eclipse内存溢出
- Oracle学习之常见错误整理
- go控制语句
- jQuery弹出窗口完整代码
- Genymotion模拟器出现Unable to create virtual device Fail to create SD card解决方法
- Android Fragment的生命周期
- 使用 Struts 2 开发 RESTful 服务
- 滴滴出行悄然提价 中国打车市场补贴战或将终结
- ViewStub用法
- hadoop: hdfs API示例
- linux内核分析之进程地址空间【转】
- android 线程学习
- 剑指offer(51)-字符流中第一个不重复的字符