use of org.apache.curator.framework.api.CreateBuilder in project pravega by pravega.
the class ZKStoreHelper method createZNodeIfNotExist.
CompletableFuture<Void> createZNodeIfNotExist(final String path, final byte[] data, final boolean createParent) {
final CompletableFuture<Void> result = new CompletableFuture<>();
try {
CreateBuilder createBuilder = client.create();
BackgroundCallback callback = callback(x -> result.complete(null), e -> {
if (e instanceof StoreException.DataExistsException) {
result.complete(null);
} else {
result.completeExceptionally(e);
}
}, path);
if (createParent) {
createBuilder.creatingParentsIfNeeded().inBackground(callback, executor).forPath(path, data);
} else {
createBuilder.inBackground(callback, executor).forPath(path, data);
}
} catch (Exception e) {
result.completeExceptionally(StoreException.create(StoreException.Type.UNKNOWN, e, path));
}
return result;
}
Aggregations