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

本文探讨ZooKeeper客户端如何使用ZKWatchManager和WatchRegistration管理Watch的注册和触发。详细介绍了各种事件(如NodeDataChanged, NodeCreate, NodeChildrenChanged, NodeDelete)对不同类型Watch的影响,并提到了源代码的可用性。" 111788292,10296538,以太网通信异常解决:差分电平与反射问题,"['以太网口差分电平', '硬件设计', '通信异常', '信号完整性']
摘要由CSDN通过智能技术生成

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值