public void start() throws Exception { childrenCache.start(); childrenCache.rebuild(); }
@Override public void childEvent(CuratorFramework client, PathChildrenCacheEvent event) throws Exception { PathChildrenCacheEvent.Type eventType = event.getType(); switch (eventType) { case CONNECTION_RECONNECTED: logger.info("Connection is reconection."); break; case CONNECTION_SUSPENDED: logger.info("Connection is suspended."); break; case CONNECTION_LOST: logger.warn("Connection error,waiting..."); return; case INITIALIZED: // countDownLatch.countDown(); logger.warn("Connection init ..."); default: // } // 任何节点的时机数据变动,都会rebuild,此处为一个"简单的"做法. cachedPath.rebuild(); rebuild(); countDownLatch.countDown(); }
@Override public void childEvent(CuratorFramework client, PathChildrenCacheEvent event) throws Exception { PathChildrenCacheEvent.Type eventType = event.getType(); switch (eventType) { case CONNECTION_RECONNECTED: logger.info("Connection is reconection."); break; case CONNECTION_SUSPENDED: logger.info("Connection is suspended."); break; case CONNECTION_LOST: logger.warn("Connection error,waiting..."); return; case INITIALIZED: // countDownLatch.countDown(); logger.warn("Connection init ..."); default: // } // 任何节点的时机数据变动,都会rebuild,此处为一个"简单的"做法. cachedPath.rebuild(); rebuild(); countDownLatch.countDown(); }
@Override public synchronized void start() { try { ZooKeeperUtils.createDefault(curator, partitionsPath, null); if (partitionCache == null) { partitionCache = new PathChildrenCache(curator, partitionsPath, true, false, executorService); partitionCache.getListenable().addListener(this); partitionCache.start(PathChildrenCache.StartMode.POST_INITIALIZED_EVENT); partitionCache.rebuild(); } } catch (Exception e) { throw FabricException.launderThrowable(e); } }
public void childEvent(CuratorFramework client, PathChildrenCacheEvent event) throws Exception { PathChildrenCacheEvent.Type eventType = event.getType(); ChildData childData = event.getData(); if (childData == null){ return; } String path = childData.getPath(); switch (eventType) { case CHILD_ADDED: listener.onAdd(path, childData.getData()); break; case CHILD_REMOVED: listener.onDelete(path); break; case CHILD_UPDATED: listener.onUpdate(path, childData.getData()); break; case CONNECTION_RECONNECTED: cacher.rebuild(); default: break; } } });