public class ZooKeeperConnection
extends java.lang.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 java.lang.String |
_rcsid |
protected java.lang.String |
connectString |
protected java.lang.String |
lockNode |
protected byte[] |
nodeData |
protected java.lang.String |
nodePath |
protected int |
sessionTimeout |
protected org.apache.zookeeper.ZooKeeper |
zookeeper |
protected ZooKeeperConnection.ZooKeeperWatcher |
zookeeperWatcher |
| Constructor and Description |
|---|
ZooKeeperConnection(java.lang.String connectString,
int sessionTimeout)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
checkGlobalFlag(java.lang.String flagPath) |
boolean |
checkNodeExists(java.lang.String nodePath)
Check whether a node exists.
|
void |
clearGlobalFlag(java.lang.String flagPath) |
void |
close()
Close this connection.
|
void |
createChild(java.lang.String nodePath,
java.lang.String childName)
Create a persistent child of a node.
|
void |
createNode(java.lang.String nodePath,
byte[] nodeData)
Create a transient node.
|
protected void |
createPersistentPath(java.lang.String path,
byte[] data) |
protected java.lang.String |
createSequentialChild(java.lang.String mainNode,
java.lang.String childPrefix)
Create a node and a sequential child node.
|
protected void |
createSession() |
void |
deleteChild(java.lang.String nodePath,
java.lang.String childName)
Delete the child of a node.
|
void |
deleteNode()
Delete a node.
|
void |
deleteNodeChildren(java.lang.String nodePath)
Delete all a node's children.
|
java.util.List<java.lang.String> |
getChildren(java.lang.String nodePath)
Get the relative paths of all node's children.
|
byte[] |
getNodeData(java.lang.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(java.lang.String lockPath)
Obtain a non-ex-write lock, with wait.
|
boolean |
obtainNonExWriteLockNoWait(java.lang.String lockPath)
Obtain a non-ex-write lock, with no wait.
|
void |
obtainReadLock(java.lang.String lockPath)
Obtain a read lock, with wait.
|
boolean |
obtainReadLockNoWait(java.lang.String lockPath)
Obtain a read lock, with no wait.
|
void |
obtainWriteLock(java.lang.String lockPath)
Obtain a write lock, with wait.
|
boolean |
obtainWriteLockNoWait(java.lang.String lockPath)
Obtain a write lock, with no wait.
|
byte[] |
readData(java.lang.String resourcePath) |
void |
releaseLock()
Release the (saved) lock.
|
void |
setGlobalFlag(java.lang.String flagPath) |
void |
setNodeData(byte[] data)
Set node data.
|
void |
writeData(java.lang.String resourcePath,
byte[] data) |
static java.lang.String |
zooKeeperDecodeSafeName(java.lang.String input) |
static java.lang.String |
zooKeeperSafeName(java.lang.String input) |
public static final java.lang.String _rcsid
protected final java.lang.String connectString
protected final int sessionTimeout
protected org.apache.zookeeper.ZooKeeper zookeeper
protected ZooKeeperConnection.ZooKeeperWatcher zookeeperWatcher
protected java.lang.String lockNode
protected java.lang.String nodePath
protected byte[] nodeData
public ZooKeeperConnection(java.lang.String connectString,
int sessionTimeout)
throws ManifoldCFException,
java.lang.InterruptedException
ManifoldCFExceptionjava.lang.InterruptedExceptionprotected void createSession()
throws ManifoldCFException,
java.lang.InterruptedException
ManifoldCFExceptionjava.lang.InterruptedExceptionpublic void createNode(java.lang.String nodePath,
byte[] nodeData)
throws ManifoldCFException,
java.lang.InterruptedException
ManifoldCFExceptionjava.lang.InterruptedExceptionpublic boolean checkNodeExists(java.lang.String nodePath)
throws ManifoldCFException,
java.lang.InterruptedException
nodePath - is the path of the node.ManifoldCFExceptionjava.lang.InterruptedExceptionpublic byte[] getNodeData(java.lang.String nodePath)
throws ManifoldCFException,
java.lang.InterruptedException
nodePath - is the path of the node.ManifoldCFExceptionjava.lang.InterruptedExceptionpublic void setNodeData(byte[] data)
throws ManifoldCFException,
java.lang.InterruptedException
ManifoldCFExceptionjava.lang.InterruptedExceptionpublic void deleteNode()
throws ManifoldCFException,
java.lang.InterruptedException
ManifoldCFExceptionjava.lang.InterruptedExceptionpublic void deleteNodeChildren(java.lang.String nodePath)
throws ManifoldCFException,
java.lang.InterruptedException
ManifoldCFExceptionjava.lang.InterruptedExceptionpublic java.util.List<java.lang.String> getChildren(java.lang.String nodePath)
throws ManifoldCFException,
java.lang.InterruptedException
ManifoldCFExceptionjava.lang.InterruptedExceptionpublic void createChild(java.lang.String nodePath,
java.lang.String childName)
throws ManifoldCFException,
java.lang.InterruptedException
ManifoldCFExceptionjava.lang.InterruptedExceptionprotected void createPersistentPath(java.lang.String path,
byte[] data)
throws org.apache.zookeeper.KeeperException,
java.lang.InterruptedException
org.apache.zookeeper.KeeperExceptionjava.lang.InterruptedExceptionpublic void deleteChild(java.lang.String nodePath,
java.lang.String childName)
throws ManifoldCFException,
java.lang.InterruptedException
ManifoldCFExceptionjava.lang.InterruptedExceptionpublic boolean obtainWriteLockNoWait(java.lang.String lockPath)
throws ManifoldCFException,
java.lang.InterruptedException
lockPath - is the lock node path.ManifoldCFExceptionjava.lang.InterruptedExceptionpublic void obtainWriteLock(java.lang.String lockPath)
throws ManifoldCFException,
java.lang.InterruptedException
lockPath - is the lock node path.ManifoldCFExceptionjava.lang.InterruptedExceptionpublic boolean obtainNonExWriteLockNoWait(java.lang.String lockPath)
throws ManifoldCFException,
java.lang.InterruptedException
lockPath - is the lock node path.ManifoldCFExceptionjava.lang.InterruptedExceptionpublic void obtainNonExWriteLock(java.lang.String lockPath)
throws ManifoldCFException,
java.lang.InterruptedException
lockPath - is the lock node path.ManifoldCFExceptionjava.lang.InterruptedExceptionpublic boolean obtainReadLockNoWait(java.lang.String lockPath)
throws ManifoldCFException,
java.lang.InterruptedException
lockPath - is the lock node path.ManifoldCFExceptionjava.lang.InterruptedExceptionpublic void obtainReadLock(java.lang.String lockPath)
throws ManifoldCFException,
java.lang.InterruptedException
lockPath - is the lock node path.ManifoldCFExceptionjava.lang.InterruptedExceptionpublic void releaseLock()
throws ManifoldCFException,
java.lang.InterruptedException
ManifoldCFExceptionjava.lang.InterruptedExceptionpublic byte[] readData(java.lang.String resourcePath)
throws ManifoldCFException,
java.lang.InterruptedException
ManifoldCFExceptionjava.lang.InterruptedExceptionpublic void writeData(java.lang.String resourcePath,
byte[] data)
throws ManifoldCFException,
java.lang.InterruptedException
ManifoldCFExceptionjava.lang.InterruptedExceptionpublic void setGlobalFlag(java.lang.String flagPath)
throws ManifoldCFException,
java.lang.InterruptedException
ManifoldCFExceptionjava.lang.InterruptedExceptionpublic void clearGlobalFlag(java.lang.String flagPath)
throws ManifoldCFException,
java.lang.InterruptedException
ManifoldCFExceptionjava.lang.InterruptedExceptionpublic boolean checkGlobalFlag(java.lang.String flagPath)
throws ManifoldCFException,
java.lang.InterruptedException
ManifoldCFExceptionjava.lang.InterruptedExceptionpublic void close()
throws java.lang.InterruptedException
java.lang.InterruptedExceptionprotected void handleEphemeralNodeKeeperException(org.apache.zookeeper.KeeperException e,
boolean recreate)
throws ManifoldCFException,
java.lang.InterruptedException
ManifoldCFExceptionjava.lang.InterruptedExceptionprotected void handleKeeperException(org.apache.zookeeper.KeeperException e,
boolean recreate)
throws ManifoldCFException,
java.lang.InterruptedException
ManifoldCFExceptionjava.lang.InterruptedExceptionpublic static java.lang.String zooKeeperSafeName(java.lang.String input)
public static java.lang.String zooKeeperDecodeSafeName(java.lang.String input)
protected java.lang.String createSequentialChild(java.lang.String mainNode,
java.lang.String childPrefix)
throws org.apache.zookeeper.KeeperException,
java.lang.InterruptedException
org.apache.zookeeper.KeeperExceptionjava.lang.InterruptedException