Home
Cloud
Big Data
CI
Install
Samples
Java
Ubuntu
Maven
Archive
ZooKeeper
|
Curator Framework: Check if a zNode exists [checkExists]
Notes
Example
Notes:
The code bellow let you check if a path exists in ZooKeeper.
Calling the method "
CuratorFramework::checkExists
" will return a "
Stat
" object.
If the path doesn't exist it will return "
null
".
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 check if a path exists in ZooKeeper:
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::checkExists final String path = "/abc/abc1"; final Stat stat = curatorFramework.checkExists().forPath(path); System.out.println(stat); // -- CuratorFramework::close curatorFramework.close();
© 2010-2022
mti
tek