Java Code Examples for org.apache.zookeeper.AsyncCallback#StringCallback
The following examples show how to use
org.apache.zookeeper.AsyncCallback#StringCallback .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LedgerAllocatorPool.java From distributedlog with Apache License 2.0 | 5 votes |
private void createAllocators(int numAllocators) throws InterruptedException, IOException { final AtomicInteger numPendings = new AtomicInteger(numAllocators); final AtomicInteger numFailures = new AtomicInteger(0); final CountDownLatch latch = new CountDownLatch(1); AsyncCallback.StringCallback createCallback = new AsyncCallback.StringCallback() { @Override public void processResult(int rc, String path, Object ctx, String name) { if (KeeperException.Code.OK.intValue() != rc) { numFailures.incrementAndGet(); latch.countDown(); return; } if (numPendings.decrementAndGet() == 0 && numFailures.get() == 0) { latch.countDown(); } } }; for (int i = 0; i < numAllocators; i++) { zkc.get().create(poolPath + "/A", new byte[0], zkc.getDefaultACL(), CreateMode.PERSISTENT_SEQUENTIAL, createCallback, null); } latch.await(); if (numFailures.get() > 0) { throw new IOException("Failed to create " + numAllocators + " allocators."); } }
Example 2
Source File: LedgerAllocatorPool.java From distributedlog with Apache License 2.0 | 5 votes |
private void createAllocators(int numAllocators) throws InterruptedException, IOException { final AtomicInteger numPendings = new AtomicInteger(numAllocators); final AtomicInteger numFailures = new AtomicInteger(0); final CountDownLatch latch = new CountDownLatch(1); AsyncCallback.StringCallback createCallback = new AsyncCallback.StringCallback() { @Override public void processResult(int rc, String path, Object ctx, String name) { if (KeeperException.Code.OK.intValue() != rc) { numFailures.incrementAndGet(); latch.countDown(); return; } if (numPendings.decrementAndGet() == 0 && numFailures.get() == 0) { latch.countDown(); } } }; for (int i = 0; i < numAllocators; i++) { zkc.get().create(poolPath + "/A", new byte[0], zkc.getDefaultACL(), CreateMode.PERSISTENT_SEQUENTIAL, createCallback, null); } latch.await(); if (numFailures.get() > 0) { throw new IOException("Failed to create " + numAllocators + " allocators."); } }
Example 3
Source File: ZookeeperClient.java From ignite with Apache License 2.0 | 5 votes |
/** * @param path Path. * @param data Data. * @param createMode Create mode. * @param cb Callback. */ private void createAsync(String path, byte[] data, CreateMode createMode, AsyncCallback.StringCallback cb) { if (data == null) data = EMPTY_BYTES; CreateOperation op = new CreateOperation(path, data, createMode, cb); zk.create(path, data, ZK_ACL, createMode, new CreateCallbackWrapper(op), null); }
Example 4
Source File: ZookeeperClient.java From ignite with Apache License 2.0 | 5 votes |
/** * @param path path. * @param data Data. * @param createMode Create mode. * @param cb Callback. */ CreateOperation(String path, byte[] data, CreateMode createMode, AsyncCallback.StringCallback cb) { this.path = path; this.data = data; this.createMode = createMode; this.cb = cb; }
Example 5
Source File: ZooKeeperConnection.java From util with Apache License 2.0 | 5 votes |
public void create( final String path, final byte[] data, final List<ACL> acl, final CreateMode createMode, final AsyncCallback.StringCallback cb, final Object ctx ) { zooKeeper.create(path, data, acl, createMode, cb, ctx); }
Example 6
Source File: AdminResource.java From pulsar with Apache License 2.0 | 4 votes |
protected void zkCreateOptimisticAsync(ZooKeeper zk, String path, byte[] content, AsyncCallback.StringCallback callback) { ZkUtils.asyncCreateFullPathOptimistic(zk, path, content, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT, callback, null); }
Example 7
Source File: ZooKeeperImpl.java From hbase-indexer with Apache License 2.0 | 4 votes |
@Override public void create(String path, byte[] data, List<ACL> acl, CreateMode createMode, AsyncCallback.StringCallback cb, Object ctx) { delegate.create(path, data, acl, createMode, cb, ctx); }
Example 8
Source File: ZKUtil.java From hbase with Apache License 2.0 | 3 votes |
/** * Async creates the specified node with the specified data. * * <p>Throws an exception if the node already exists. * * <p>The node created is persistent and open access. * * @param zkw zk reference * @param znode path of node to create * @param data data of node to create * @param cb the callback to use for the creation * @param ctx the context to use for the creation */ public static void asyncCreate(ZKWatcher zkw, String znode, byte [] data, final AsyncCallback.StringCallback cb, final Object ctx) { zkw.getRecoverableZooKeeper().getZooKeeper().create(znode, data, createACL(zkw, znode), CreateMode.PERSISTENT, cb, ctx); }
Example 9
Source File: ZooKeeperItf.java From hbase-indexer with Apache License 2.0 | votes |
void create(String path, byte[] data, List<ACL> acl, CreateMode createMode, AsyncCallback.StringCallback cb, Object ctx);