Reputation: 4458
With the fluent API of Curator, we can create a znode synchronously by invoking something like:
client.create().withMode(CreateMode.PERSISTENT).forPath("/mypath", new byte[0]);
I would like to know how we can execute the same operation asynchronously while specifying the create mode?
Upvotes: 0
Views: 298
Reputation: 2956
If you're on Java 8 and ZooKeeper 3.5.x, the latest version of Curator (note: I'm the main author) has a new DSL for async. You can read about it here: http://curator.apache.org/curator-x-async/index.html
E.g.
AsyncCuratorFramework async = AsyncCuratorFramework.wrap(client);
async.checkExists().forPath(somePath).thenAccept(stat -> mySuccessOperation(stat));
Upvotes: 1
Reputation: 4458
We can execute the given create operation asynchronously while specifying the create mode like below,
client.create()
.withMode(CreateMode.PERSISTENT)
.inBackground()
.forPath("/mypath", new byte[0]);
Upvotes: 1