public class NodeKeeper extends Object implements org.apache.zookeeper.Watcher
| Constructor and Description |
|---|
NodeKeeper(String connectionString,
int sessionTimeout,
Properties properties)
NodeKeeper enables a ZooKeeper connection.
|
NodeKeeper(String connectionString,
int sessionTimeout,
Properties properties,
String startNode)
NodeKeeper enables a ZooKeeper connection.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addDataHandler(DataHandler dataHandler)
Adds a data handler that is used to read and write node data
|
void |
addListener(String pathPattern,
NodeListener listener)
Appends a listener to the pathPattern.
|
<T> void |
deleteNode(Node<T> node)
delete the node from ZooKeeper
|
DataHandler |
getDataHandler(Class clazz) |
org.apache.zookeeper.ZooKeeper |
getZooKeeper()
returns the ZooKeeper connection if it is connected
|
boolean |
hasChildren(String path) |
<T> Set<Node<T>> |
listChildrenNodes(String path,
Class<T> clazz) |
List<DataHandler> |
listDataHandlers() |
int |
nbOfChildren(String path) |
void |
process(org.apache.zookeeper.WatchedEvent watchedEvent) |
<T> Node<T> |
readNode(String path,
Class<T> clazz)
read node to ZooKeeper, return null if it does not exist
|
void |
removeListener(String pathPattern,
NodeListener listener) |
void |
shutdown()
shut down ZooKeeper connection
|
void |
startListeners() |
<T> void |
writeNode(Node<T> node,
Class<T> clazz)
write node to ZooKeeper, create parent nodes recursively if they do not exist
|
public NodeKeeper(String connectionString, int sessionTimeout, Properties properties) throws InterruptedException, NodeKeeperException, IOException
connectionString - comma-separated list of url-strings of ZooKeeper serverssessionTimeout - sessionTimeout for connectionproperties - should be persisted at the end to guarantee clean node versioning (on re-startup)IOExceptionInterruptedExceptionNodeKeeperExceptionpublic NodeKeeper(String connectionString, int sessionTimeout, Properties properties, String startNode) throws InterruptedException, IOException, NodeKeeperException
connectionString - comma-separated list of url-strings of ZooKeeper serverssessionTimeout - sessionTimeout for connectionproperties - should be persisted at the end to guarantee clean node versioning (on re-startup)startNode - juts children of this node and the node itself are taken into accountIOExceptionInterruptedExceptionNodeKeeperExceptionpublic void startListeners()
throws InterruptedException,
NodeKeeperException,
IOException
public void process(org.apache.zookeeper.WatchedEvent watchedEvent)
process in interface org.apache.zookeeper.Watcherpublic org.apache.zookeeper.ZooKeeper getZooKeeper()
public void shutdown()
throws InterruptedException
InterruptedExceptionpublic <T> Node<T> readNode(String path, Class<T> clazz) throws InterruptedException, NodeKeeperException, IOException
T - class of the node, is handled by handlerpath - path of the nodeclazz - class of the node, is handled by handlerInterruptedExceptionNodeKeeperExceptionIOExceptionpublic <T> void writeNode(Node<T> node, Class<T> clazz) throws InterruptedException, NodeKeeperException, IOException
T - the handler for writing the datanode - the node that should be writtenclazz - InterruptedExceptionNodeKeeperExceptionIOExceptionpublic <T> void deleteNode(Node<T> node) throws InterruptedException, NodeKeeperException
T - the class for the handler (not used in this method)node - a node instanceInterruptedExceptionNodeKeeperExceptionpublic <T> Set<Node<T>> listChildrenNodes(String path, Class<T> clazz) throws InterruptedException, NodeKeeperException
public int nbOfChildren(String path) throws NodeKeeperException, InterruptedException
public boolean hasChildren(String path) throws NodeKeeperException, InterruptedException
public void addListener(String pathPattern, NodeListener listener) throws NodeKeeperException
pathPattern - a regular expression that declares the node the listener is listen to.listener - a implementation of the NodeListener interface that handles the node events create, update and delete.NodeKeeperExceptionpublic void removeListener(String pathPattern, NodeListener listener)
public void addDataHandler(DataHandler dataHandler)
dataHandler - public DataHandler getDataHandler(Class clazz)
public List<DataHandler> listDataHandlers()
Copyright © 2014. All Rights Reserved.