本文整理汇总了Java中org.apache.zookeeper.AsyncCallback.ChildrenCallback类的典型用法代码示例。如果您正苦于以下问题:Java ChildrenCallback类的具体用法?Java ChildrenCallback怎么用?Java ChildrenCallback使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ChildrenCallback类属于org.apache.zookeeper.AsyncCallback包,在下文中一共展示了ChildrenCallback类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getChildren
import org.apache.zookeeper.AsyncCallback.ChildrenCallback; //导入依赖的package包/类
/**
* 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);
}
示例2: getChildren
import org.apache.zookeeper.AsyncCallback.ChildrenCallback; //导入依赖的package包/类
/**
* 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);
}
示例3: startService
import org.apache.zookeeper.AsyncCallback.ChildrenCallback; //导入依赖的package包/类
@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();
}
示例4: testSync
import org.apache.zookeeper.AsyncCallback.ChildrenCallback; //导入依赖的package包/类
@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());
}
}
示例5: testSync
import org.apache.zookeeper.AsyncCallback.ChildrenCallback; //导入依赖的package包/类
@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());
}
}
示例6: getChildren
import org.apache.zookeeper.AsyncCallback.ChildrenCallback; //导入依赖的package包/类
@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);
}
});
}
示例7: testSync
import org.apache.zookeeper.AsyncCallback.ChildrenCallback; //导入依赖的package包/类
@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());
}
}
示例8: readBookies
import org.apache.zookeeper.AsyncCallback.ChildrenCallback; //导入依赖的package包/类
public void readBookies(ChildrenCallback callback) {
bk.getZkHandle().getChildren( BOOKIE_REGISTRATION_PATH, this, callback, null);
}