public List<String> getChildren(CuratorFramework zk, String path, boolean watch) throws Exception { String normPath = PathUtils.normalize_path(path); if (watch) { return zk.getChildren().watched().forPath(normPath); } else { return zk.getChildren().forPath(normPath); } }
@Override public List<String> getChildren(String path, boolean watch) throws KeeperException, InterruptedException { try { return watch ? curator.getChildren().watched().forPath(path) : curator.getChildren().forPath(path); } catch ( Exception e ) { adjustException(e); } return null; // will never execute }
@Override public BackgroundPathable<List<String>> watched() { return new BackgroundPathableDecorator<>(inner.watched()); }
public List<String> getChild(String path) throws Exception { if (!exists(path)) { throw new RuntimeException(String.format("can not find any service node on path: %s", path)); } List<String> addressList = null; try { addressList = zookeeperClient.getChildren().watched().forPath(path); } catch (Exception e) { LOGGER.debug("node " + path + " does not exist"); return null; } return addressList; }
public List<String> getChildren(CuratorFramework zk, String path, boolean watch) throws Exception { String npath = PathUtils.normalize_path(path); if (watch) { return zk.getChildren().watched().forPath(npath); } else { return zk.getChildren().forPath(npath); } }
public static List<String> watchedGetChildren(CuratorFramework client, String path, Watcher watcher) throws Exception { /** * Get children and set the given watcher on the node. */ return client.getChildren().usingWatcher(watcher).forPath(path); } }
public static List<String> watchedGetChildren(CuratorFramework client, String path, Watcher watcher) throws Exception { /** * Get children and set the given watcher on the node. */ return client.getChildren().usingWatcher(watcher).forPath(path); } }
/** * 加载节点并监听节点变化 */ void loadNode() { final String nodePath = ZKPaths.makePath(configProfile.getVersionedRootNode(), node); final GetChildrenBuilder childrenBuilder = client.getChildren(); try { final List<String> children = childrenBuilder.watched().forPath(nodePath); if (children != null) { final Map<String, String> configs = new HashMap<>(); for (String child : children) { final Tuple<String, String> keyValue = loadKey(ZKPaths.makePath(nodePath, child)); if (keyValue != null) { configs.put(keyValue.getFirst(), keyValue.getSecond()); } } cleanAndPutAll(configs); } } catch (Exception e) { throw new RuntimeException(e); } if (getConfigLocalCache() != null) { getConfigLocalCache().saveLocalCache(this, getNode()); } }
/** * 加载节点并监听节点变化 */ void loadNode() { final String nodePath = ZKPaths.makePath(configProfile.getVersionedRootNode(), node); final GetChildrenBuilder childrenBuilder = client.getChildren(); try { final List<String> children = childrenBuilder.watched().forPath(nodePath); if (children != null) { final Map<String, String> configs = new HashMap<>(); for (String child : children) { final Tuple<String, String> keyValue = loadKey(ZKPaths.makePath(nodePath, child)); if (keyValue != null) { configs.put(keyValue.getFirst(), keyValue.getSecond()); } } cleanAndPutAll(configs); } } catch (Exception e) { throw new RuntimeException(e); } if (getConfigLocalCache() != null) { getConfigLocalCache().saveLocalCache(this, getNode()); } }