ZooKeeperExt { public List<String> getChildrenExt( final String path, boolean watch, boolean sequenceSorted, boolean fullPath) throws KeeperException, InterruptedException { int attempt = 0; while (attempt < maxRetryAttempts) { try { List<String> childList = zooKeeper.getChildren(path, watch); if (sequenceSorted) { Collections.sort(childList, new Comparator<String>() { public int compare(String s1, String s2) { if ((s1.length() <= SEQUENCE_NUMBER_LENGTH) || (s2.length() <= SEQUENCE_NUMBER_LENGTH)) { throw new RuntimeException( "getChildrenExt: Invalid length for sequence " + " sorting > " + SEQUENCE_NUMBER_LENGTH + " for s1 (" + s1.length() + ") or s2 (" + s2.length() + ")"); } int s1sequenceNumber = Integer.parseInt( s1.substring(s1.length() - SEQUENCE_NUMBER_LENGTH)); int s2sequenceNumber = Integer.parseInt( s2.substring(s2.length() - SEQUENCE_NUMBER_LENGTH)); return s1sequenceNumber - s2sequenceNumber; } }); } if (fullPath) { List<String> fullChildList = new ArrayList<String>(); for (String child : childList) { fullChildList.add(path + "/" + child); } return fullChildList; } return childList; } catch (KeeperException.ConnectionLossException e) { LOG.warn("getChildrenExt: Connection loss on attempt " + attempt + ", waiting " + retryWaitMsecs + " msecs before retrying.", e); } ++attempt; Thread.sleep(retryWaitMsecs); } throw new IllegalStateException("createExt: Failed to create " + path + " after " + attempt + " tries!"); } ZooKeeperExt(String connectString,
                      int sessionTimeout,
                      int maxRetryAttempts,
                      int retryWaitMsecs,
                      Watcher watcher);  ZooKeeperExt(String connectString,
      int sessionTimeout,
      int maxRetryAttempts,
      int retryWaitMsecs,
      Watcher watcher,
      Progressable progressable); String createExt(
      final String path,
      byte[] data,
      List<ACL> acl,
      CreateMode createMode,
      boolean recursive); PathStat createOrSetExt(final String path,
      byte[] data,
      List<ACL> acl,
      CreateMode createMode,
      boolean recursive,
      int version); PathStat createOnceExt(final String path,
      byte[] data,
      List<ACL> acl,
      CreateMode createMode,
      boolean recursive); void deleteExt(final String path, int version, boolean recursive); Stat exists(String path, boolean watch); Stat exists(final String path, Watcher watcher); byte[] getData(final String path, Watcher watcher, Stat stat); byte[] getData(String path, boolean watch, Stat stat); List<String> getChildrenExt(
      final String path,
      boolean watch,
      boolean sequenceSorted,
      boolean fullPath); void close(); static final int SEQUENCE_NUMBER_LENGTH; }
@Test public void testGetChildrenExt() throws KeeperException, InterruptedException { if (zooKeeperExt == null) { System.out.println( "testGetChildrenExt: No prop.zookeeper.list set, skipping test"); return; } zooKeeperExt.createExt(BASE_PATH, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT, false); zooKeeperExt.createExt(BASE_PATH + "/b", null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_SEQUENTIAL, false); zooKeeperExt.createExt(BASE_PATH + "/a", null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_SEQUENTIAL, false); zooKeeperExt.createExt(BASE_PATH + "/d", null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_SEQUENTIAL, false); zooKeeperExt.createExt(BASE_PATH + "/c", null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_SEQUENTIAL, false); List<String> fullPathList = zooKeeperExt.getChildrenExt(BASE_PATH, false, false, true); for (String fullPath : fullPathList) { assertTrue(fullPath.contains(BASE_PATH + "/")); } List<String> sequenceOrderedList = zooKeeperExt.getChildrenExt(BASE_PATH, false, true, true); for (String fullPath : sequenceOrderedList) { assertTrue(fullPath.contains(BASE_PATH + "/")); } assertEquals(4, sequenceOrderedList.size()); assertTrue(sequenceOrderedList.get(0).contains("/b")); assertTrue(sequenceOrderedList.get(1).contains("/a")); assertTrue(sequenceOrderedList.get(2).contains("/d")); assertTrue(sequenceOrderedList.get(3).contains("/c")); }