Home
Cloud
Big Data
CI
Install
Samples
Java
Ubuntu
Maven
Archive
ZooKeeper
|
Curator Framework: Delete a zNode [delete]
Notes
Example
Notes:
The code bellow let you delete a zNode.
You will get this error if the zNode doesn't exist in ZooKeeper:
org.apache.zookeeper.KeeperException$NoNodeException: KeeperErrorCode = NoNode for /path
You will get this error if the zNode is not empty (contains children):
org.apache.zookeeper.KeeperException$NotEmptyException: KeeperErrorCode = Directory not empty for /path
In order for the code bellow to work:
► Make sure to update the "
CONNECT_STRING
" variable with your information.
Example
Here's an example of how to delete a zNode:
final String CONNECT_STRING = "localhost:2181"; final int SESSION_TIMEOUT_MS = Integer.valueOf(60 * 1000); final int CONNECTION_TIMEOUT_MS = Integer.valueOf(15 * 1000); final RetryPolicy RETRY_POLICY = new RetryOneTime(1000); // -- CuratorFrameworkFactory::newClient final CuratorFramework curatorFramework = CuratorFrameworkFactory.newClient(CONNECT_STRING, SESSION_TIMEOUT_MS, CONNECTION_TIMEOUT_MS, RETRY_POLICY); // -- CuratorFramework::start curatorFramework.start(); // -- CuratorFramework::delete final String path = "/abc"; curatorFramework.delete().forPath(path); // -- CuratorFramework::close curatorFramework.close();
© 2010-2022
mti
tek