zk的watcher模型(下)
watcher在zk server中实现 WatcherManager存储管理 属性: private final Map<String, Set<Watcher>> watchTable = new HashMap<String, Set<Watcher>>(); 路径和watcher的对应关系 private final Map<Watcher, Set<String>> watch2Paths = new HashMap<Watcher, Set<String>>(); watcher和路径集合的对应关系 方法: 使用synchronized同步方法,不够灵活,线程不能中断,效率不够高 public synchronized int size() { int result = 0; for (Set<Watcher> watches : watchTable.values()) { result += watches.size(); } return result; } 添加watcher @Override public synchronized boolean addWatch(String path, Watcher watcher) { if (isDeadWatcher(watcher)) { LOG.debug("Ignoring addWatch with