public List<String> list(String path) { path = "/" + path; try { if(_curator.checkExists().forPath(path)==null) { return new ArrayList<String>(); } else { return _curator.getChildren().forPath(path); } } catch(Exception e) { throw new RuntimeException(e); } }
try nodes = (watcher != null) ? client.getChildren().usingWatcher(watcher).forPath(path) : client.getChildren().forPath(path);
/** * Register callback notifications when child node added/deleted for a znode * * @param path */ @SuppressWarnings("restriction") public void registerChildrenCallback(String path) { try { transport.getZKHandle().getChildren().usingWatcher(watcher).inBackground((BackgroundCallback)watcher).forPath(path); } catch (Exception e) { LOGGER.error( "Exception while registering childrencallback for " + path, e); } }
private synchronized void sync(boolean watched) throws Exception { if ( watched ) { client.getChildren().usingWatcher(watcher).inBackground(callback).forPath(path); } else { client.getChildren().inBackground(callback).forPath(path); } }
public List<String> call() { try { return transport.getZKHandle().getChildren() .inBackground((BackgroundCallback)watcher) .forPath(path); } catch (Exception e) { LOGGER.error( e.getMessage(), e); } return null; } });
private void wathPath(String nodePath) { try { this.watchPathDataChange(nodePath); GetChildrenBuilder childrenBuilder = client.getChildren(); try { List<String> children = null; if (StringUtils.isEmpty(nodePath)) { children = childrenBuilder.watched().forPath(null); } else { children = childrenBuilder.watched().forPath(nodePath); } this.watchChildDataChange(children, nodePath); } catch (Exception e) { throw Throwables.propagate(e); } } catch (Exception e) { logger.error("load zk config error namespace={}", configOption.getNameSpace()); logger.error("load config error", e); throw new RuntimeException("load zk error"); } }
/** * Set watch on each child node to receive notifications on node data * change/creation/deletion notifications * * @param path */ @SuppressWarnings("restriction") public void getChildrenAndSetWatch(String path) { List<String> children = null; try { children = transport.getZKHandle().getChildren().usingWatcher(watcher) .forPath(path); for (String child : children) { String childnodePath = (new StringBuilder()).append(path) .append("/").append(child).toString(); transport.getZKHandle().checkExists().usingWatcher(watcher) .forPath(childnodePath); getChildrenAndSetWatch(childnodePath); } }catch(NoNodeException nee){ LOGGER.warn( " NoNodeException While setting children watch for " + path + nee.getMessage()); } catch (Exception e) { LOGGER.error( " Exception While setting watch on " + path, e); } }
private void getChildren() throws Exception { BackgroundCallback callback = new BackgroundCallback() { @Override public void processResult(CuratorFramework client, CuratorEvent event) throws Exception { if ( event.getResultCode() == KeeperException.Code.OK.intValue() ) { checkLeadership(event.getChildren()); } } }; client.getChildren().inBackground(callback).forPath(latchPath); }
private void loadConfig(String nodePath) { try { if (StringUtils.isNotEmpty(nodePath)) { loadData(nodePath); } GetChildrenBuilder childrenBuilder = client.getChildren(); try { List<String> children = null; if (StringUtils.isEmpty(nodePath)) { children = childrenBuilder.watched().forPath(null); } else { children = childrenBuilder.watched().forPath(nodePath); } loadChildsConfig(children, nodePath); } catch (Exception e) { throw Throwables.propagate(e); } } catch (Exception e) { logger.error("load zk config error namespace={}", configOption.getNameSpace()); logger.error("load config error", e); this.client.close(); throw new RuntimeException("load zk error"); } }
protected List<String> getChildren() throws Exception { return client.getChildren().forPath(queuePath); }
void refresh(final RefreshMode mode) throws Exception { ensurePath.ensure(client.getZookeeperClient()); final BackgroundCallback callback = new BackgroundCallback() { @Override public void processResult(CuratorFramework client, CuratorEvent event) throws Exception { processChildren(event.getChildren(), mode); } }; client.getChildren().usingWatcher(childrenWatcher).inBackground(callback).forPath(path); }
@VisibleForTesting protected List<String> getChildrenForEntering() throws Exception { return client.getChildren().forPath(barrierPath); }
List<String> children = null; try { children = getZKHandle().getChildren().usingWatcher(this) .forPath(path);
public static List<String> getSortedChildren(CuratorFramework client, String basePath, final String lockName, final LockInternalsSorter sorter) throws Exception { List<String> children = client.getChildren().forPath(basePath); List<String> sortedList = Lists.newArrayList(children); Collections.sort ( sortedList, new Comparator<String>() { @Override public int compare(String lhs, String rhs) { return sorter.fixForSorting(lhs, lockName).compareTo(sorter.fixForSorting(rhs, lockName)); } } ); return sortedList; }
List<String> children = client.getChildren().usingWatcher(watcher).forPath(leasesPath); if ( !children.contains(nodeName) )
private int getNumPartitions() { try { String topicBrokersPath = partitionPath(); List<String> children = _curator.getChildren().forPath(topicBrokersPath); return children.size(); } catch (Exception e) { throw new RuntimeException(e); } }
public List<String> getChildren(String path) { try { if (!exists(path)) return null; return m_curator.getChildren().forPath(path); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new RuntimeException(e); } }
/** * Return a list of all current nodes participating in the semaphore * * @return list of nodes * @throws Exception ZK errors, interruptions, etc. */ public Collection<String> getParticipantNodes() throws Exception { return client.getChildren().forPath(ZKPaths.makePath(leasesPath, LEASE_BASE_NAME)); }
public List<KafkaTopic> listTopics(String zookeeperUri) { List<KafkaTopic> kafkaTopics = null; // Get the updated status for the cluster from zookeeper CuratorFramework curatorClient = getCuratorClient(zookeeperUri); if (curatorClient != null) { try { kafkaTopics = new ArrayList<KafkaTopic>(); for (String topic : curatorClient.getChildren().forPath("/brokers/topics")) { KafkaTopic kafkaTopic = new KafkaTopic(); kafkaTopic.setName(topic); kafkaTopics.add(kafkaTopic); } } catch (Exception ex) { ex.printStackTrace(); } } return kafkaTopics; }