public class ZooKeeperConnection extends Object
Modifier and Type | Class and Description |
---|---|
protected static class |
ZooKeeperConnection.ExistsWatcher
Watcher class for exists state changes, so we get notified about deletions of lock request nodes.
|
protected static class |
ZooKeeperConnection.ZooKeeperWatcher
Watcher class for zookeeper, so we get notified about zookeeper events.
|
Modifier and Type | Field and Description |
---|---|
static String |
_rcsid |
protected String |
connectString |
protected String |
lockNode |
protected byte[] |
nodeData |
protected String |
nodePath |
protected int |
sessionTimeout |
protected org.apache.zookeeper.ZooKeeper |
zookeeper |
protected ZooKeeperConnection.ZooKeeperWatcher |
zookeeperWatcher |
Constructor and Description |
---|
ZooKeeperConnection(String connectString,
int sessionTimeout)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
boolean |
checkGlobalFlag(String flagPath) |
boolean |
checkNodeExists(String nodePath)
Check whether a node exists.
|
void |
clearGlobalFlag(String flagPath) |
void |
close()
Close this connection.
|
void |
createChild(String nodePath,
String childName)
Create a persistent child of a node.
|
void |
createNode(String nodePath,
byte[] nodeData)
Create a transient node.
|
protected String |
createSequentialChild(String mainNode,
String childPrefix)
Create a node and a sequential child node.
|
protected void |
createSession() |
void |
deleteChild(String nodePath,
String childName)
Delete the child of a node.
|
void |
deleteNode()
Delete a node.
|
void |
deleteNodeChildren(String nodePath)
Delete all a node's children.
|
List<String> |
getChildren(String nodePath)
Get the relative paths of all node's children.
|
byte[] |
getNodeData(String nodePath)
Get node data.
|
protected void |
handleEphemeralNodeKeeperException(org.apache.zookeeper.KeeperException e,
boolean recreate)
Handle keeper exceptions that may involve ephemeral node creation.
|
protected void |
handleKeeperException(org.apache.zookeeper.KeeperException e,
boolean recreate)
Handle keeper exceptions that don't involve ephemeral node creation.
|
void |
obtainNonExWriteLock(String lockPath)
Obtain a non-ex-write lock, with wait.
|
boolean |
obtainNonExWriteLockNoWait(String lockPath)
Obtain a non-ex-write lock, with no wait.
|
void |
obtainReadLock(String lockPath)
Obtain a read lock, with wait.
|
boolean |
obtainReadLockNoWait(String lockPath)
Obtain a read lock, with no wait.
|
void |
obtainWriteLock(String lockPath)
Obtain a write lock, with wait.
|
boolean |
obtainWriteLockNoWait(String lockPath)
Obtain a write lock, with no wait.
|
byte[] |
readData(String resourcePath) |
void |
releaseLock()
Release the (saved) lock.
|
void |
setGlobalFlag(String flagPath) |
void |
setNodeData(byte[] data)
Set node data.
|
void |
writeData(String resourcePath,
byte[] data) |
static String |
zooKeeperDecodeSafeName(String input) |
static String |
zooKeeperSafeName(String input) |
public static final String _rcsid
protected final String connectString
protected final int sessionTimeout
protected org.apache.zookeeper.ZooKeeper zookeeper
protected ZooKeeperConnection.ZooKeeperWatcher zookeeperWatcher
protected String lockNode
protected String nodePath
protected byte[] nodeData
public ZooKeeperConnection(String connectString, int sessionTimeout) throws ManifoldCFException, InterruptedException
protected void createSession() throws ManifoldCFException, InterruptedException
public void createNode(String nodePath, byte[] nodeData) throws ManifoldCFException, InterruptedException
public boolean checkNodeExists(String nodePath) throws ManifoldCFException, InterruptedException
nodePath
- is the path of the node.ManifoldCFException
InterruptedException
public byte[] getNodeData(String nodePath) throws ManifoldCFException, InterruptedException
nodePath
- is the path of the node.ManifoldCFException
InterruptedException
public void setNodeData(byte[] data) throws ManifoldCFException, InterruptedException
public void deleteNode() throws ManifoldCFException, InterruptedException
public void deleteNodeChildren(String nodePath) throws ManifoldCFException, InterruptedException
public List<String> getChildren(String nodePath) throws ManifoldCFException, InterruptedException
public void createChild(String nodePath, String childName) throws ManifoldCFException, InterruptedException
public void deleteChild(String nodePath, String childName) throws ManifoldCFException, InterruptedException
public boolean obtainWriteLockNoWait(String lockPath) throws ManifoldCFException, InterruptedException
lockPath
- is the lock node path.ManifoldCFException
InterruptedException
public void obtainWriteLock(String lockPath) throws ManifoldCFException, InterruptedException
lockPath
- is the lock node path.ManifoldCFException
InterruptedException
public boolean obtainNonExWriteLockNoWait(String lockPath) throws ManifoldCFException, InterruptedException
lockPath
- is the lock node path.ManifoldCFException
InterruptedException
public void obtainNonExWriteLock(String lockPath) throws ManifoldCFException, InterruptedException
lockPath
- is the lock node path.ManifoldCFException
InterruptedException
public boolean obtainReadLockNoWait(String lockPath) throws ManifoldCFException, InterruptedException
lockPath
- is the lock node path.ManifoldCFException
InterruptedException
public void obtainReadLock(String lockPath) throws ManifoldCFException, InterruptedException
lockPath
- is the lock node path.ManifoldCFException
InterruptedException
public void releaseLock() throws ManifoldCFException, InterruptedException
public byte[] readData(String resourcePath) throws ManifoldCFException, InterruptedException
public void writeData(String resourcePath, byte[] data) throws ManifoldCFException, InterruptedException
public void setGlobalFlag(String flagPath) throws ManifoldCFException, InterruptedException
public void clearGlobalFlag(String flagPath) throws ManifoldCFException, InterruptedException
public boolean checkGlobalFlag(String flagPath) throws ManifoldCFException, InterruptedException
public void close() throws InterruptedException
InterruptedException
protected void handleEphemeralNodeKeeperException(org.apache.zookeeper.KeeperException e, boolean recreate) throws ManifoldCFException, InterruptedException
protected void handleKeeperException(org.apache.zookeeper.KeeperException e, boolean recreate) throws ManifoldCFException, InterruptedException
protected String createSequentialChild(String mainNode, String childPrefix) throws org.apache.zookeeper.KeeperException, InterruptedException
org.apache.zookeeper.KeeperException
InterruptedException