public class ZookeeperClient extends Object implements AutoCloseable
#close()
.Constructor and Description |
---|
ZookeeperClient(org.apache.curator.framework.CuratorFramework curator,
String root,
org.apache.zookeeper.CreateMode mode) |
Modifier and Type | Method and Description |
---|---|
void |
close() |
void |
create(String path)
Creates the given path without placing any data in.
|
void |
delete(String path)
Deletes the given node residing at the given path
|
Iterator<Map.Entry<String,byte[]>> |
entries()
Returns an iterator of (key, value) pairs residing under
root path. |
byte[] |
get(String path)
Returns a value corresponding to the given path if path exists in the cache, null otherwise.
|
byte[] |
get(String path,
boolean consistent)
Returns the value corresponding to the given key, null otherwise.
|
byte[] |
get(String path,
boolean consistent,
DataChangeVersion version)
Returns the value corresponding to the given key, null otherwise.
|
byte[] |
get(String path,
DataChangeVersion version)
Returns the value corresponding to the given key, null otherwise.
|
org.apache.curator.framework.recipes.cache.PathChildrenCache |
getCache() |
org.apache.zookeeper.CreateMode |
getMode() |
String |
getRoot() |
boolean |
hasPath(String path)
Returns true if path exists in the cache, false otherwise.
|
boolean |
hasPath(String path,
boolean consistent)
Returns true if path exists, false otherwise.
|
boolean |
hasPath(String path,
boolean consistent,
DataChangeVersion version)
Checks if the given path exists.
|
void |
put(String path,
byte[] data)
Puts the given byte sequence into the given path.
|
void |
put(String path,
byte[] data,
DataChangeVersion version)
Puts the given byte sequence into the given path.
|
byte[] |
putIfAbsent(String path,
byte[] data)
Puts the given byte sequence into the given path if path is does not exist.
|
void |
start()
Starts the client.
|
public ZookeeperClient(org.apache.curator.framework.CuratorFramework curator, String root, org.apache.zookeeper.CreateMode mode)
public void start() throws Exception
public org.apache.curator.framework.recipes.cache.PathChildrenCache getCache()
public String getRoot()
public org.apache.zookeeper.CreateMode getMode()
public boolean hasPath(String path)
path
- path to checkpublic boolean hasPath(String path, boolean consistent)
path
- path to checkconsistent
- whether the check should be consistentpublic boolean hasPath(String path, boolean consistent, DataChangeVersion version)
Stat
object, it increases each time znode data change is performed.
Link to Zookeeper documentation - https://zookeeper.apache.org/doc/r3.2.2/zookeeperProgrammers.html#sc_zkDataModel_znodespath
- path to checkconsistent
- whether the check should be consistentversion
- version holderpublic byte[] get(String path)
path
- target pathpublic byte[] get(String path, boolean consistent)
path
- target pathconsistent
- consistency flagpublic byte[] get(String path, DataChangeVersion version)
path
- target pathversion
- version holderpublic byte[] get(String path, boolean consistent, DataChangeVersion version)
Stat
object, it increases each time znode data change is performed.
Link to Zookeeper documentation - https://zookeeper.apache.org/doc/r3.2.2/zookeeperProgrammers.html#sc_zkDataModel_znodespath
- target pathconsistent
- consistency checkversion
- version holderpublic void create(String path)
path
- target pathpublic void put(String path, byte[] data)
path
- target pathdata
- data to storepublic void put(String path, byte[] data, DataChangeVersion version)
KeeperException.BadVersionException
.
We catch such exception and re-throw it as VersionMismatchException
.
Link to documentation - https://zookeeper.apache.org/doc/r3.2.2/zookeeperProgrammers.html#sc_zkDataModel_znodespath
- target pathdata
- data to storeversion
- version holderpublic byte[] putIfAbsent(String path, byte[] data)
path
- target pathdata
- data to storepublic void delete(String path)
path
- target path to deletepublic Iterator<Map.Entry<String,byte[]>> entries()
root
path.public void close() throws Exception
close
in interface AutoCloseable
Exception
Copyright © 1970 The Apache Software Foundation. All rights reserved.