use of org.apache.bookkeeper.meta.ZkVersion in project distributedlog by twitter.
the class SimpleLedgerAllocator method createAllocationData.
private static Future<Versioned<byte[]>> createAllocationData(final String allocatePath, final ZooKeeperClient zkc) {
try {
final Promise<Versioned<byte[]>> promise = new Promise<Versioned<byte[]>>();
zkc.get().create(allocatePath, DistributedLogConstants.EMPTY_BYTES, zkc.getDefaultACL(), CreateMode.PERSISTENT, new org.apache.zookeeper.AsyncCallback.Create2Callback() {
@Override
public void processResult(int rc, String path, Object ctx, String name, Stat stat) {
if (KeeperException.Code.OK.intValue() == rc) {
promise.setValue(new Versioned<byte[]>(DistributedLogConstants.EMPTY_BYTES, new ZkVersion(stat.getVersion())));
} else if (KeeperException.Code.NODEEXISTS.intValue() == rc) {
Utils.zkGetData(zkc, allocatePath, false).proxyTo(promise);
} else {
promise.setException(FutureUtils.zkException(KeeperException.create(KeeperException.Code.get(rc)), allocatePath));
}
}
}, null);
return promise;
} catch (ZooKeeperClient.ZooKeeperConnectionException e) {
return Future.exception(FutureUtils.zkException(e, allocatePath));
} catch (InterruptedException e) {
return Future.exception(FutureUtils.zkException(e, allocatePath));
}
}
Aggregations