public class ZkConnection
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static byte[] |
NO_DATA
use this constant for the data argument to create empty nodes.
|
Constructor and Description |
---|
ZkConnection(ZooKeeperService service)
create instance using the given service to get ZooKeeper clients when needed.
|
Modifier and Type | Method and Description |
---|---|
void |
createNode(java.lang.String nodePath,
byte[] data)
create a persistent node with given data. fails if the parent node of the given path does not exist.
|
void |
createNode(java.lang.String nodePath,
byte[] data,
CreateMode mode)
create a node with given data. fails if the parent node of the given path does not exist.
|
void |
createPath(java.lang.String nodePath,
byte[] data)
create a persistent node with given data. creates the complete hierarchy if necessary.
|
void |
deleteNode(java.lang.String nodePath)
delete the given node.
|
void |
deleteTree(java.lang.String nodePath)
delete a complete node subtree starting from the given path.
|
void |
deleteTreeWithoutMultiOps(java.lang.String nodePath)
delete a complete node subtree, starting from the given path.
|
void |
disconnectZkSession()
Close current zookeeper client (session).
|
void |
ensurePathExists(java.lang.String path) |
Stat |
exists(java.lang.String nodePath)
Check if node exists.
|
Stat |
exists(java.lang.String nodePath,
long timeout)
Check if node exists wihin given timeout.
|
Stat |
exists(java.lang.String nodePath,
Watcher watcher)
Check if node exists and set a watcher.
|
java.util.List<java.lang.String> |
getChildrenSorted(java.lang.String nodePath)
get children from node, sorted by name.
|
byte[] |
getData(java.lang.String nodePath)
get data of node.
|
byte[] |
getData(java.lang.String nodePath,
Stat stat)
get data and stat of node.
|
java.util.List<java.lang.String> |
getLeafNodes(java.lang.String startNodePath)
get all leaf nodes (= nodes without children) starting from given node.
|
long |
getSessionId() |
Stat |
setData(java.lang.String nodePath,
byte[] nodeData)
update data on existing node.
|
Stat |
setData(java.lang.String nodePath,
byte[] nodeData,
int version)
update data on existing node if version does match.
|
public static final byte[] NO_DATA
public ZkConnection(ZooKeeperService service)
service
- ZooKeeper service.public long getSessionId()
public void createNode(java.lang.String nodePath, byte[] data) throws KeeperException
nodePath
- path for node to createdata
- data of node to createKeeperException
- errorpublic void createNode(java.lang.String nodePath, byte[] data, CreateMode mode) throws KeeperException
nodePath
- path for node to createdata
- data of node to createmode
- 'PERSISTENT' if we want a persistent node, 'EPHEMERAL' if we want an ephemeral nodeKeeperException
- errorpublic void createPath(java.lang.String nodePath, byte[] data) throws KeeperException
nodePath
- path for node to createdata
- data of node to createKeeperException
- errorpublic void ensurePathExists(java.lang.String path) throws KeeperException
path
- the path whose elements should be created as zookeeper nodes if not existentKeeperException
- error creating zookeeper nodespublic void deleteNode(java.lang.String nodePath) throws KeeperException
nodePath
- path for node to deleteKeeperException
- KeeperException.NoNodeException if node doesn't existpublic void deleteTreeWithoutMultiOps(java.lang.String nodePath) throws KeeperException
nodePath
- root node of tree to deleteKeeperException
- error deleting tree. State of subtree is quite undefined afterwards.public void deleteTree(java.lang.String nodePath) throws KeeperException
nodePath
- root node of tree to deleteKeeperException
- error deleting tree. State of subtree is quite undefined afterwards.public Stat exists(java.lang.String nodePath) throws KeeperException
nodePath
- path for node to check existenceKeeperException
- errorpublic Stat exists(java.lang.String nodePath, Watcher watcher) throws KeeperException
nodePath
- path for node to check existenceKeeperException
- errorpublic Stat exists(java.lang.String nodePath, long timeout) throws KeeperException
nodePath
- path for node to check existencetimeout
- timeout in milliseconds.KeeperException
- errorpublic Stat setData(java.lang.String nodePath, byte[] nodeData, int version) throws KeeperException
nodePath
- path for node to update datanodeData
- new dataversion
- the expected matching versionKeeperException
- KeeperException.NoNodeException if node doesn't existpublic Stat setData(java.lang.String nodePath, byte[] nodeData) throws KeeperException
nodePath
- path for node to update datanodeData
- new dataKeeperException
- KeeperException.NoNodeException if node doesn't existpublic byte[] getData(java.lang.String nodePath) throws KeeperException
nodePath
- the node path to get the dataKeeperException
- KeeperException.NoNodeException if node doesn't existpublic byte[] getData(java.lang.String nodePath, Stat stat) throws KeeperException
nodePath
- the node path to get the datastat
- contains the stat of the node after the callKeeperException
- KeeperException.NoNodeException if node doesn't existpublic java.util.List<java.lang.String> getChildrenSorted(java.lang.String nodePath) throws KeeperException
nodePath
- path of node to get the childrenKeeperException
- KeeperException.NoNodeException if node doesn't existpublic java.util.List<java.lang.String> getLeafNodes(java.lang.String startNodePath) throws KeeperException
startNodePath
- path of start nodeKeeperException
- KeeperException.NoNodeException if start node doesn't existpublic void disconnectZkSession() throws java.io.IOException, ClusterConfigException
java.io.IOException
ClusterConfigException