ZooKeeper Client 如何管理Watch(一):注册和存储Watch

ZooKeeper Client 使用ZKWatchManager和WatchRegistration两个类管理Client端Watch的注册和触发

  • ZKWatchManager:储存已经注册的Watch、查找事件触发的Watch
  • WatchRegistration:注册Watch到ZKWatchManager中
ZKWatchManager与WatchRegistration关系图:



ZKWatchManager如何存储Client端注册的Watch?
private final Map<String, Set<Watcher>> dataWatches =
            new HashMap<String, Set<Watcher>>();
        private final Map<String, Set<Watcher>> existWatches =
            new HashMap<String, Set<Watcher>>();
        private final Map<String, Set<Watcher>> childWatches =
            new HashMap<String, Set<Watcher>>();

        private volatile Watcher defaultWatcher;
它有3个 Map <String , Set <Watcher >>集合,dataWatches对应的是与Node数据变动的Watch,existWatches对应的是Node创建和删除的Watch,childWatches对应的是Node的子Node的变化的Watch。defaultWatcher用于存储创建ZooKeeper对象时传入的Watch。

ZKWatchManager如何查找事件触发的watches?
public Set<Watcher> materialize(Watcher.Event.KeeperState state,
                                        Watcher.Event.Eve
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值