|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.I0Itec.zkclient.ZkClient
public class ZkClient
Abstracts the interaction with zookeeper and allows permanent (not just one time) watches on nodes in ZooKeeper
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface org.apache.zookeeper.Watcher |
---|
org.apache.zookeeper.Watcher.Event |
Field Summary | |
---|---|
protected org.I0Itec.zkclient.IZkConnection |
_connection
|
Constructor Summary | |
---|---|
ZkClient(org.I0Itec.zkclient.IZkConnection connection)
|
|
ZkClient(org.I0Itec.zkclient.IZkConnection connection,
int connectionTimeout)
|
|
ZkClient(org.I0Itec.zkclient.IZkConnection zkConnection,
int connectionTimeout,
ZkSerializer zkSerializer)
|
|
ZkClient(java.lang.String serverstring)
|
|
ZkClient(java.lang.String zkServers,
int connectionTimeout)
|
|
ZkClient(java.lang.String zkServers,
int sessionTimeout,
int connectionTimeout)
|
|
ZkClient(java.lang.String zkServers,
int sessionTimeout,
int connectionTimeout,
ZkSerializer zkSerializer)
|
Method Summary | ||
---|---|---|
void |
close()
Close the client. |
|
void |
connect(long maxMsToWaitUntilConnected,
org.apache.zookeeper.Watcher watcher)
Connect to ZooKeeper. |
|
int |
countChildren(java.lang.String path)
Counts number of children for the given path. |
|
java.lang.String |
create(java.lang.String path,
java.lang.Object data,
org.apache.zookeeper.CreateMode mode)
Create a node. |
|
void |
createEphemeral(java.lang.String path)
Create an ephemeral node. |
|
void |
createEphemeral(java.lang.String path,
java.lang.Object data)
Create an ephemeral node. |
|
java.lang.String |
createEphemeralSequential(java.lang.String path,
java.lang.Object data)
Create an ephemeral, sequential node. |
|
void |
createPersistent(java.lang.String path)
Create a persistent node. |
|
void |
createPersistent(java.lang.String path,
boolean createParents)
Create a persistent node. |
|
void |
createPersistent(java.lang.String path,
java.lang.Object data)
Create a persistent node. |
|
java.lang.String |
createPersistentSequential(java.lang.String path,
java.lang.Object data)
Create a persistent, sequental node. |
|
boolean |
delete(java.lang.String path)
|
|
boolean |
deleteRecursive(java.lang.String path)
|
|
boolean |
exists(java.lang.String path)
|
|
protected boolean |
exists(java.lang.String path,
boolean watch)
|
|
java.util.List<java.lang.String> |
getChildren(java.lang.String path)
|
|
protected java.util.List<java.lang.String> |
getChildren(java.lang.String path,
boolean watch)
|
|
long |
getCreationTime(java.lang.String path)
|
|
protected java.util.Set<IZkDataListener> |
getDataListener(java.lang.String path)
|
|
ZkLock |
getEventLock()
Returns a mutex all zookeeper events are synchronized aginst. |
|
boolean |
getShutdownTrigger()
|
|
int |
numberOfListeners()
|
|
void |
process(org.apache.zookeeper.WatchedEvent event)
|
|
|
readData(java.lang.String path)
|
|
|
readData(java.lang.String path,
boolean returnNullIfPathNotExists)
|
|
|
readData(java.lang.String path,
org.apache.zookeeper.data.Stat stat)
|
|
protected
|
readData(java.lang.String path,
org.apache.zookeeper.data.Stat stat,
boolean watch)
|
|
|
retryUntilConnected(java.util.concurrent.Callable<T> callable)
|
|
void |
setCurrentState(org.apache.zookeeper.Watcher.Event.KeeperState currentState)
|
|
void |
setShutdownTrigger(boolean triggerState)
|
|
void |
setZkSerializer(ZkSerializer zkSerializer)
|
|
void |
showFolders(java.io.OutputStream output)
|
|
java.util.List<java.lang.String> |
subscribeChildChanges(java.lang.String path,
IZkChildListener listener)
|
|
void |
subscribeDataChanges(java.lang.String path,
IZkDataListener listener)
|
|
void |
subscribeStateChanges(IZkStateListener listener)
|
|
void |
unsubscribeAll()
|
|
void |
unsubscribeChildChanges(java.lang.String path,
IZkChildListener childListener)
|
|
void |
unsubscribeDataChanges(java.lang.String path,
IZkDataListener dataListener)
|
|
void |
unsubscribeStateChanges(IZkStateListener stateListener)
|
|
|
updateDataSerialized(java.lang.String path,
DataUpdater<T> updater)
Updates data of an existing znode. |
|
boolean |
waitForKeeperState(org.apache.zookeeper.Watcher.Event.KeeperState keeperState,
long time,
java.util.concurrent.TimeUnit timeUnit)
|
|
void |
waitUntilConnected()
|
|
boolean |
waitUntilConnected(long time,
java.util.concurrent.TimeUnit timeUnit)
|
|
boolean |
waitUntilExists(java.lang.String path,
java.util.concurrent.TimeUnit timeUnit,
long time)
|
|
java.util.List<java.lang.String> |
watchForChilds(java.lang.String path)
Installs a child watch for the given path. |
|
void |
watchForData(java.lang.String path)
|
|
void |
writeData(java.lang.String path,
java.lang.Object object)
|
|
void |
writeData(java.lang.String path,
java.lang.Object datat,
int expectedVersion)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected org.I0Itec.zkclient.IZkConnection _connection
Constructor Detail |
---|
public ZkClient(java.lang.String serverstring)
public ZkClient(java.lang.String zkServers, int connectionTimeout)
public ZkClient(java.lang.String zkServers, int sessionTimeout, int connectionTimeout)
public ZkClient(java.lang.String zkServers, int sessionTimeout, int connectionTimeout, ZkSerializer zkSerializer)
public ZkClient(org.I0Itec.zkclient.IZkConnection connection)
public ZkClient(org.I0Itec.zkclient.IZkConnection connection, int connectionTimeout)
public ZkClient(org.I0Itec.zkclient.IZkConnection zkConnection, int connectionTimeout, ZkSerializer zkSerializer)
Method Detail |
---|
public void setZkSerializer(ZkSerializer zkSerializer)
public java.util.List<java.lang.String> subscribeChildChanges(java.lang.String path, IZkChildListener listener)
public void unsubscribeChildChanges(java.lang.String path, IZkChildListener childListener)
public void subscribeDataChanges(java.lang.String path, IZkDataListener listener)
public void unsubscribeDataChanges(java.lang.String path, IZkDataListener dataListener)
public void subscribeStateChanges(IZkStateListener listener)
public void unsubscribeStateChanges(IZkStateListener stateListener)
public void unsubscribeAll()
public void createPersistent(java.lang.String path) throws ZkInterruptedException, java.lang.IllegalArgumentException, ZkException, java.lang.RuntimeException
path
-
ZkInterruptedException
- if operation was interrupted, or a required reconnection got interrupted
java.lang.IllegalArgumentException
- if called from anything except the ZooKeeper event thread
ZkException
- if any ZooKeeper exception occurred
java.lang.RuntimeException
- if any other exception occurspublic void createPersistent(java.lang.String path, boolean createParents) throws ZkInterruptedException, java.lang.IllegalArgumentException, ZkException, java.lang.RuntimeException
path
- createParents
- if true all parent dirs are created as well and no ZkNodeExistsException
is thrown in case the
path already exists
ZkInterruptedException
- if operation was interrupted, or a required reconnection got interrupted
java.lang.IllegalArgumentException
- if called from anything except the ZooKeeper event thread
ZkException
- if any ZooKeeper exception occurred
java.lang.RuntimeException
- if any other exception occurspublic void createPersistent(java.lang.String path, java.lang.Object data) throws ZkInterruptedException, java.lang.IllegalArgumentException, ZkException, java.lang.RuntimeException
path
- data
-
ZkInterruptedException
- if operation was interrupted, or a required reconnection got interrupted
java.lang.IllegalArgumentException
- if called from anything except the ZooKeeper event thread
ZkException
- if any ZooKeeper exception occurred
java.lang.RuntimeException
- if any other exception occurspublic java.lang.String createPersistentSequential(java.lang.String path, java.lang.Object data) throws ZkInterruptedException, java.lang.IllegalArgumentException, ZkException, java.lang.RuntimeException
path
- data
-
ZkInterruptedException
- if operation was interrupted, or a required reconnection got interrupted
java.lang.IllegalArgumentException
- if called from anything except the ZooKeeper event thread
ZkException
- if any ZooKeeper exception occurred
java.lang.RuntimeException
- if any other exception occurspublic void createEphemeral(java.lang.String path) throws ZkInterruptedException, java.lang.IllegalArgumentException, ZkException, java.lang.RuntimeException
path
-
ZkInterruptedException
- if operation was interrupted, or a required reconnection got interrupted
java.lang.IllegalArgumentException
- if called from anything except the ZooKeeper event thread
ZkException
- if any ZooKeeper exception occurred
java.lang.RuntimeException
- if any other exception occurspublic java.lang.String create(java.lang.String path, java.lang.Object data, org.apache.zookeeper.CreateMode mode) throws ZkInterruptedException, java.lang.IllegalArgumentException, ZkException, java.lang.RuntimeException
path
- data
- mode
-
ZkInterruptedException
- if operation was interrupted, or a required reconnection got interrupted
java.lang.IllegalArgumentException
- if called from anything except the ZooKeeper event thread
ZkException
- if any ZooKeeper exception occurred
java.lang.RuntimeException
- if any other exception occurspublic void createEphemeral(java.lang.String path, java.lang.Object data) throws ZkInterruptedException, java.lang.IllegalArgumentException, ZkException, java.lang.RuntimeException
path
- data
-
ZkInterruptedException
- if operation was interrupted, or a required reconnection got interrupted
java.lang.IllegalArgumentException
- if called from anything except the ZooKeeper event thread
ZkException
- if any ZooKeeper exception occurred
java.lang.RuntimeException
- if any other exception occurspublic java.lang.String createEphemeralSequential(java.lang.String path, java.lang.Object data) throws ZkInterruptedException, java.lang.IllegalArgumentException, ZkException, java.lang.RuntimeException
path
- data
-
ZkInterruptedException
- if operation was interrupted, or a required reconnection got interrupted
java.lang.IllegalArgumentException
- if called from anything except the ZooKeeper event thread
ZkException
- if any ZooKeeper exception occurred
java.lang.RuntimeException
- if any other exception occurspublic void process(org.apache.zookeeper.WatchedEvent event)
process
in interface org.apache.zookeeper.Watcher
public java.util.List<java.lang.String> getChildren(java.lang.String path)
protected java.util.List<java.lang.String> getChildren(java.lang.String path, boolean watch)
public int countChildren(java.lang.String path)
path
-
protected boolean exists(java.lang.String path, boolean watch)
public boolean exists(java.lang.String path)
public boolean deleteRecursive(java.lang.String path)
public boolean waitUntilExists(java.lang.String path, java.util.concurrent.TimeUnit timeUnit, long time) throws ZkInterruptedException
ZkInterruptedException
protected java.util.Set<IZkDataListener> getDataListener(java.lang.String path)
public void showFolders(java.io.OutputStream output)
public void waitUntilConnected() throws ZkInterruptedException
ZkInterruptedException
public boolean waitUntilConnected(long time, java.util.concurrent.TimeUnit timeUnit) throws ZkInterruptedException
ZkInterruptedException
public boolean waitForKeeperState(org.apache.zookeeper.Watcher.Event.KeeperState keeperState, long time, java.util.concurrent.TimeUnit timeUnit) throws ZkInterruptedException
ZkInterruptedException
public <T> T retryUntilConnected(java.util.concurrent.Callable<T> callable) throws ZkInterruptedException, java.lang.IllegalArgumentException, ZkException, java.lang.RuntimeException
T
- callable
-
ZkInterruptedException
- if operation was interrupted, or a required reconnection got interrupted
java.lang.IllegalArgumentException
- if called from anything except the ZooKeeper event thread
ZkException
- if any ZooKeeper exception occurred
java.lang.RuntimeException
- if any other exception occurs from invoking the Callablepublic void setCurrentState(org.apache.zookeeper.Watcher.Event.KeeperState currentState)
public ZkLock getEventLock()
public boolean delete(java.lang.String path)
public <T> T readData(java.lang.String path)
public <T> T readData(java.lang.String path, boolean returnNullIfPathNotExists)
public <T> T readData(java.lang.String path, org.apache.zookeeper.data.Stat stat)
protected <T> T readData(java.lang.String path, org.apache.zookeeper.data.Stat stat, boolean watch)
public void writeData(java.lang.String path, java.lang.Object object)
public <T> void updateDataSerialized(java.lang.String path, DataUpdater<T> updater)
DataUpdater
that is
passed into this method, which returns the new content. The new content is only written back to ZooKeeper if
nobody has modified the given znode in between. If a concurrent change has been detected the new data of the
znode is passed to the updater once again until the new contents can be successfully written back to ZooKeeper.
T
- path
- The path of the znode.updater
- Updater that creates the new contents.public void writeData(java.lang.String path, java.lang.Object datat, int expectedVersion)
public void watchForData(java.lang.String path)
public java.util.List<java.lang.String> watchForChilds(java.lang.String path)
path
-
public void connect(long maxMsToWaitUntilConnected, org.apache.zookeeper.Watcher watcher) throws ZkInterruptedException, ZkTimeoutException, java.lang.IllegalStateException
maxMsToWaitUntilConnected
- watcher
-
ZkInterruptedException
- if the connection timed out due to thread interruption
ZkTimeoutException
- if the connection timed out
java.lang.IllegalStateException
- if the connection timed out due to thread interruptionpublic long getCreationTime(java.lang.String path)
public void close() throws ZkInterruptedException
ZkInterruptedException
public void setShutdownTrigger(boolean triggerState)
public boolean getShutdownTrigger()
public int numberOfListeners()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |