SMILA 1.0 API documentation

org.eclipse.smila.zookeeper
Class ZkConnection

java.lang.Object
  extended by org.eclipse.smila.zookeeper.ZkConnection

public class ZkConnection
extends java.lang.Object

wrapper of ZooKeeper client that executes a number of ZooKeeper operation with handling for ConnectionLoss errors.


Field Summary
static byte[] NO_DATA
          use this constant for the data argument to create empty nodes.
 
Constructor Summary
ZkConnection(ZooKeeperService service)
          create instance using the given service to get ZooKeeper clients when needed.
 
Method Summary
 void createNode(java.lang.String nodePath, byte[] data)
          create a persistent node with given data.
 void createNode(java.lang.String nodePath, byte[] data, CreateMode mode)
          create a node with given data.
 void createPath(java.lang.String nodePath, byte[] data)
          create a persistent node with given data.
 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 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, 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.
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NO_DATA

public static final byte[] NO_DATA
use this constant for the data argument to create empty nodes.

Constructor Detail

ZkConnection

public ZkConnection(ZooKeeperService service)
create instance using the given service to get ZooKeeper clients when needed.

Parameters:
service - ZooKeeper service.
Method Detail

getSessionId

public long getSessionId()
Returns:
sessionId of underlying zookeeper client.

createNode

public void createNode(java.lang.String nodePath,
                       byte[] data)
                throws KeeperException
create a persistent node with given data. fails if the parent node of the given path does not exist.

Parameters:
nodePath - path for node to create
data - data of node to create
Throws:
KeeperException - error

createNode

public void createNode(java.lang.String nodePath,
                       byte[] data,
                       CreateMode mode)
                throws KeeperException
create a node with given data. fails if the parent node of the given path does not exist.

Parameters:
nodePath - path for node to create
data - data of node to create
mode - 'PERSISTENT' if we want a persistent node, 'EPHEMERAL' if we want an ephemeral node
Throws:
KeeperException - error

createPath

public void createPath(java.lang.String nodePath,
                       byte[] data)
                throws KeeperException
create a persistent node with given data. creates the complete hierarchy if necessary.

Parameters:
nodePath - path for node to create
data - data of node to create
Throws:
KeeperException - error

ensurePathExists

public void ensurePathExists(java.lang.String path)
                      throws KeeperException
Parameters:
path - the path whose elements should be created as zookeeper nodes if not existent
Throws:
KeeperException - error creating zookeeper nodes

deleteNode

public void deleteNode(java.lang.String nodePath)
                throws KeeperException
delete the given node.

Parameters:
nodePath - path for node to delete
Throws:
KeeperException - KeeperException.NoNodeException if node doesn't exist

deleteTree

public void deleteTree(java.lang.String nodePath)
                throws KeeperException
delete a complete node subtree, starting from the given path.

Parameters:
nodePath - root node of tree to delete
Throws:
KeeperException - error deleting tree. State of subtree is quite undefined afterwards.

exists

public Stat exists(java.lang.String nodePath)
            throws KeeperException
Check if node exists.

Parameters:
nodePath - path for node to check existence
Returns:
Stat of node to exist, 'null' if no such node exists.
Throws:
KeeperException - error

exists

public Stat exists(java.lang.String nodePath,
                   Watcher watcher)
            throws KeeperException
Check if node exists and set a watcher.

Parameters:
nodePath - path for node to check existence
Returns:
Stat of node to exist, 'null' if no such node exists.
Throws:
KeeperException - error

setData

public Stat setData(java.lang.String nodePath,
                    byte[] nodeData,
                    int version)
             throws KeeperException
update data on existing node if version does match.

Parameters:
nodePath - path for node to update data
nodeData - new data
version - the expected matching version
Throws:
KeeperException - KeeperException.NoNodeException if node doesn't exist

setData

public Stat setData(java.lang.String nodePath,
                    byte[] nodeData)
             throws KeeperException
update data on existing node.

Parameters:
nodePath - path for node to update data
nodeData - new data
Throws:
KeeperException - KeeperException.NoNodeException if node doesn't exist

getData

public byte[] getData(java.lang.String nodePath)
               throws KeeperException
get data of node.

Parameters:
nodePath - the node path to get the data
Returns:
node data
Throws:
KeeperException - KeeperException.NoNodeException if node doesn't exist

getData

public byte[] getData(java.lang.String nodePath,
                      Stat stat)
               throws KeeperException
get data and stat of node.

Parameters:
nodePath - the node path to get the data
stat - contains the stat of the node after the call
Returns:
node data
Throws:
KeeperException - KeeperException.NoNodeException if node doesn't exist

getChildrenSorted

public java.util.List<java.lang.String> getChildrenSorted(java.lang.String nodePath)
                                                   throws KeeperException
get children from node, sorted by name.

Parameters:
nodePath - path of node to get the children
Returns:
sorted list of children
Throws:
KeeperException - KeeperException.NoNodeException if node doesn't exist

disconnectZkSession

public void disconnectZkSession()
                         throws java.io.IOException,
                                ClusterConfigException
Close current zookeeper client (session).

Throws:
java.io.IOException
ClusterConfigException

SMILA 1.0 API documentation