/** * The asynchronous version of getChildren. * * @see #getChildren(String, Watcher) */ public void getChildren(final String path, Watcher watcher, ChildrenCallback cb, Object ctx) { final String clientPath = path; PathUtils.validatePath(clientPath); // the watch contains the un-chroot path WatchRegistration wcb = null; if (watcher != null) { wcb = new ChildWatchRegistration(watcher, clientPath); } final String serverPath = prependChroot(clientPath); RequestHeader h = new RequestHeader(); h.setType(ZooDefs.OpCode.getChildren); GetChildrenRequest request = new GetChildrenRequest(); request.setPath(serverPath); request.setWatch(watcher != null); GetChildrenResponse response = new GetChildrenResponse(); cnxn.queuePacket(h, new ReplyHeader(), request, response, cb, clientPath, serverPath, ctx, wcb); }
/** * The Asynchronous version of getChildren. The request doesn't actually * until the asynchronous callback is called. * * @see #getChildren(String, Watcher) */ public void getChildren(final String path, Watcher watcher, ChildrenCallback cb, Object ctx) { final String clientPath = path; PathUtils.validatePath(clientPath); // the watch contains the un-chroot path WatchRegistration wcb = null; if (watcher != null) { wcb = new ChildWatchRegistration(watcher, clientPath); } final String serverPath = prependChroot(clientPath); RequestHeader h = new RequestHeader(); h.setType(ZooDefs.OpCode.getChildren); GetChildrenRequest request = new GetChildrenRequest(); request.setPath(serverPath); request.setWatch(watcher != null); GetChildrenResponse response = new GetChildrenResponse(); cnxn.queuePacket(h, new ReplyHeader(), request, response, cb, clientPath, serverPath, ctx, wcb); }
@Override public void startService() { zookeeper.getChildren(ZKDistributedJobEngine.NODES_PATH, watcher, new ChildrenCallback() { @Override public void processResult(int rc, String path, Object ctx, List<String> children) { // TODO Auto-generated method stub } }, null); // / load job information loadAllJobs(); // run scheduler for all jobs scheduleJobs(); }
@Test public void testSync() throws Exception { try { LOG.info("Starting ZK:" + (new Date()).toString()); opsCount = new CountDownLatch(limit); ZooKeeper zk = createClient(); LOG.info("Beginning test:" + (new Date()).toString()); for(int i = 0; i < 100; i++) zk.create("/test" + i, new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT, this, results); zk.sync("/test", this, results); for(int i = 0; i < 100; i++) zk.delete("/test" + i, 0, this, results); for(int i = 0; i < 100; i++) zk.getChildren("/", new NullWatcher(), (ChildrenCallback)this, results); for(int i = 0; i < 100; i++) zk.getChildren("/", new NullWatcher(), (Children2Callback)this, results); LOG.info("Submitted all operations:" + (new Date()).toString()); if(!opsCount.await(10000, TimeUnit.MILLISECONDS)) Assert.fail("Haven't received all confirmations" + opsCount.getCount()); for(int i = 0; i < limit ; i++){ Assert.assertEquals(0, (int) results.get(i)); } } catch (IOException e) { System.out.println(e.toString()); } }
@Test public void testSync() throws Exception { try { LOG.info("Starting ZK:" + (new Date()).toString()); opsCount = new CountDownLatch(limit); ZooKeeper zk = createClient(); LOG.info("Beginning test:" + (new Date()).toString()); for(int i = 0; i < 50; i++) zk.create("/test" + i, new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT, (StringCallback)this, results); for(int i = 50; i < 100; i++) { zk.create("/test" + i, new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT, (Create2Callback)this, results); } zk.sync("/test", this, results); for(int i = 0; i < 100; i++) zk.delete("/test" + i, 0, this, results); for(int i = 0; i < 100; i++) zk.getChildren("/", new NullWatcher(), (ChildrenCallback)this, results); for(int i = 0; i < 100; i++) zk.getChildren("/", new NullWatcher(), (Children2Callback)this, results); LOG.info("Submitted all operations:" + (new Date()).toString()); if(!opsCount.await(10000, TimeUnit.MILLISECONDS)) Assert.fail("Haven't received all confirmations" + opsCount.getCount()); for(int i = 0; i < limit ; i++){ Assert.assertEquals(0, (int) results.get(i)); } } catch (IOException e) { System.out.println(e.toString()); } }
@Override public void getChildren(final String path, final Watcher watcher, final ChildrenCallback cb, final Object ctx) { executor.execute(() -> { mutex.lock(); if (getProgrammedFailStatus()) { mutex.unlock(); cb.processResult(failReturnCode.intValue(), path, ctx, null); return; } else if (stopped) { mutex.unlock(); cb.processResult(KeeperException.Code.ConnectionLoss, path, ctx, null); return; } List<String> children = Lists.newArrayList(); for (String item : tree.tailMap(path).keySet()) { if (!item.startsWith(path)) { break; } else { if (path.length() >= item.length()) { continue; } String child = item.substring(path.length() + 1); if (!child.contains("/")) { children.add(child); } } } mutex.unlock(); cb.processResult(0, path, ctx, children); if (watcher != null) { watchers.put(path, watcher); } }); }
@Test public void testSync() throws Exception { try { LOG.info("Starting ZK:" + (new Date()).toString()); opsCount = new CountDownLatch(limit); ZooKeeper zk = createClient(); LOG.info("Beginning test:" + (new Date()).toString()); for(int i = 0; i < 100; i++) zk.create("/test" + i, new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT, this, results); zk.sync("/test", this, results); for(int i = 0; i < 100; i++) zk.delete("/test" + i, 0, this, results); for(int i = 0; i < 100; i++) zk.getChildren("/", new NullWatcher(), (ChildrenCallback)this, results); for(int i = 0; i < 100; i++) zk.getChildren("/", new NullWatcher(), (Children2Callback)this, results); LOG.info("Submitted all operations:" + (new Date()).toString()); if(!opsCount.await(10000, TimeUnit.MILLISECONDS)) fail("Haven't received all confirmations" + opsCount.getCount()); for(int i = 0; i < limit ; i++){ assertEquals(0, (int) results.get(i)); } } catch (IOException e) { System.out.println(e.toString()); } }
/** * The asynchronous version of getChildren. * * @see #getChildren(String, boolean) */ public void getChildren(String path, boolean watch, ChildrenCallback cb, Object ctx) { getChildren(path, watch ? watchManager.defaultWatcher : null, cb, ctx); }
public void readBookies(ChildrenCallback callback) { bk.getZkHandle().getChildren( BOOKIE_REGISTRATION_PATH, this, callback, null); }
/** * The Asynchronous version of getChildren. The request doesn't actually * until the asynchronous callback is called. * * @see #getChildren(String, boolean) */ public void getChildren(String path, boolean watch, ChildrenCallback cb, Object ctx) { getChildren(path, watch ? watchManager.defaultWatcher : null, cb, ctx); }