public interface IZkClient extends Closeable
| 限定符和类型 | 接口和说明 |
|---|---|
static interface |
IZkClient.DataUpdater
A CAS operation
|
| 限定符和类型 | 字段和说明 |
|---|---|
static int |
DEFAULT_CONNECTION_TIMEOUT |
static int |
DEFAULT_SESSION_TIMEOUT |
| 限定符和类型 | 方法和说明 |
|---|---|
void |
cas(String path,
IZkClient.DataUpdater updater)
Updates data of an existing znode.
|
void |
close()
Close the client.
|
void |
connect(long timeout,
org.apache.zookeeper.Watcher watcher)
Connect to ZooKeeper.
|
int |
countChildren(String path)
Counts number of children for the given path.
|
String |
create(String path,
byte[] data,
org.apache.zookeeper.CreateMode mode)
Create a node.
|
void |
createEphemeral(String path)
Create an ephemeral node with empty data
|
void |
createEphemeral(String path,
byte[] data)
Create an ephemeral node.
|
String |
createEphemeralSequential(String path,
byte[] data)
Create an ephemeral, sequential node.
|
void |
createPersistent(String path)
Create a persistent node with empty data (null)
|
void |
createPersistent(String path,
boolean createParents)
Create a persistent node with empty data (null)
If the createParents is true, neither
ZkNodeExistsException nor ZkNoNodeException were throwed. |
void |
createPersistent(String path,
byte[] data)
Create a persistent node.
|
String |
createPersistentSequential(String path,
byte[] data)
Create a persistent, sequental node.
|
boolean |
delete(String path)
delete a node
|
boolean |
deleteRecursive(String path)
delete a node with all children
|
boolean |
exists(String path)
check the node exists
|
List<String> |
getChildren(String path)
get the children for the node
|
long |
getCreationTime(String path)
get the node creation time (unix milliseconds)
|
org.apache.zookeeper.ZooKeeper |
getZooKeeper()
get the inner zookeeper client
|
boolean |
isConnected()
check the connecting state of zookeeper client
|
List<?> |
multi(Iterable<?> ops)
multi operation for zookeeper 3.4.x
|
int |
numberOfListeners()
all watcher number in this connection
|
byte[] |
readData(String path)
read the data for the node
|
byte[] |
readData(String path,
boolean returnNullIfPathNotExists)
read the data for the node
|
byte[] |
readData(String path,
org.apache.zookeeper.data.Stat stat)
read the data and stat for the node
|
List<String> |
subscribeChildChanges(String path,
IZkChildListener listener)
subscribe the changing for children
|
void |
subscribeDataChanges(String path,
IZkDataListener listener)
subscribe the data changing for the node
|
void |
subscribeStateChanges(IZkStateListener listener)
subscribe the connection state
|
void |
unsubscribeAll()
unsubscribe all listeners for all path and connection state
|
void |
unsubscribeChildChanges(String path,
IZkChildListener childListener)
unsubscribe the child listener
|
void |
unsubscribeDataChanges(String path,
IZkDataListener dataListener)
unsubscribe the data changing for the node
|
void |
unsubscribeStateChanges(IZkStateListener stateListener)
unsubscribe the connection state
|
boolean |
waitForKeeperState(org.apache.zookeeper.Watcher.Event.KeeperState keeperState,
long time,
TimeUnit timeUnit)
wait some time for the state
|
boolean |
waitUntilConnected()
wait for the connected state.
|
boolean |
waitUntilConnected(long time,
TimeUnit timeUnit)
wait for the connected state
|
boolean |
waitUntilExists(String path,
TimeUnit timeUnit,
long time)
wait some unit until the node exists
|
org.apache.zookeeper.data.Stat |
writeData(String path,
byte[] data)
write the data for the node
|
org.apache.zookeeper.data.Stat |
writeData(String path,
byte[] data,
int expectedVersion)
write the data for the node
|
static final int DEFAULT_CONNECTION_TIMEOUT
static final int DEFAULT_SESSION_TIMEOUT
void close()
close 在接口中 AutoCloseableclose 在接口中 CloseableZkInterruptedException - if interrupted while closingvoid connect(long timeout,
org.apache.zookeeper.Watcher watcher)
timeout - max waiting time(ms) until connectedwatcher - default watcherZkInterruptedException - if the connection timed out due to thread interruptionZkTimeoutException - if the connection timed outIllegalStateException - if the connection timed out due to thread interruptionint countChildren(String path)
path - zk pathString create(String path, byte[] data, org.apache.zookeeper.CreateMode mode)
path - zk pathdata - node datamode - create mode CreateModeIllegalArgumentException - if called from anything except the ZooKeeper event
threadZkException - if any ZooKeeper exception occurredvoid createEphemeral(String path)
path - zk pathZkInterruptedException - if operation was interrupted, or a required reconnection
got interruptedIllegalArgumentException - if called from anything except the ZooKeeper event
threadZkException - if any ZooKeeper exception occurredvoid createEphemeral(String path, byte[] data)
path - the path for the nodedata - node dataZkInterruptedException - if operation was interrupted, or a required reconnection
got interruptedIllegalArgumentException - if called from anything except the ZooKeeper event
threadZkException - if any ZooKeeper exception occurredString createEphemeralSequential(String path, byte[] data)
path - the path for the nodedata - the data for the nodeZkInterruptedException - if operation was interrupted, or a required reconnection
got interruptedIllegalArgumentException - if called from anything except the ZooKeeper event
threadZkException - if any ZooKeeper exception occurredvoid createPersistent(String path)
path - the path for the nodeZkNodeExistsException - if the node existsZkNoNodeException - if the parent node not existsZkInterruptedException - if operation was interrupted, or a required reconnection
got interruptedIllegalArgumentException - if called from anything except the ZooKeeper event
threadZkException - if any ZooKeeper exception occurredRuntimeException - any other exceptioncreatePersistent(String, boolean)void createPersistent(String path, boolean createParents)
If the createParents is true, neither ZkNodeExistsException nor ZkNoNodeException were throwed.
path - the path for the nodecreateParents - if true all parent dirs are created as well and no
ZkNodeExistsException is thrown in case the path already existsZkInterruptedException - if operation was interrupted, or a required reconnection
got interruptedIllegalArgumentException - if called from anything except the ZooKeeper event
threadZkException - if any ZooKeeper exception occurredRuntimeException - any other exceptionvoid createPersistent(String path, byte[] data)
path - the path for the nodedata - node dataZkInterruptedException - if operation was interrupted, or a required reconnection
got interruptedIllegalArgumentException - if called from anything except the ZooKeeper event
threadZkException - if any ZooKeeper exception occurredRuntimeException - any other exceptionString createPersistentSequential(String path, byte[] data)
path - the path for the nodedata - node dataZkInterruptedException - if operation was interrupted, or a required reconnection
got interruptedIllegalArgumentException - if called from anything except the ZooKeeper event
threadZkException - if any ZooKeeper exception occurredRuntimeException - any other exceptionboolean delete(String path)
path - the path for the nodeboolean deleteRecursive(String path)
path - the path for the nodeboolean exists(String path)
path - the path for the nodeList<String> getChildren(String path)
path - the path for the nodelong getCreationTime(String path)
path - the path for the nodeint numberOfListeners()
byte[] readData(String path)
path - the path for the nodeZkNoNodeException - if the node not existsreadData(String, boolean)byte[] readData(String path, boolean returnNullIfPathNotExists)
path - the path for the nodereturnNullIfPathNotExists - if true no ZkNoNodeException thrownbyte[] readData(String path, org.apache.zookeeper.data.Stat stat)
path - the path for the nodestat - the stat for the nodereadData(String, boolean)List<String> subscribeChildChanges(String path, IZkChildListener listener)
path - the path for the nodelistener - the listenerIZkChildListenervoid subscribeDataChanges(String path, IZkDataListener listener)
path - the path for the nodelistener - the data changing listenerIZkDataListenervoid subscribeStateChanges(IZkStateListener listener)
listener - the connection listenerIZkStateListenervoid unsubscribeAll()
void unsubscribeChildChanges(String path, IZkChildListener childListener)
path - the path for the nodechildListener - the listenervoid unsubscribeDataChanges(String path, IZkDataListener dataListener)
path - the path for the nodedataListener - the data changing listenervoid unsubscribeStateChanges(IZkStateListener stateListener)
stateListener - the connection listenervoid cas(String path, IZkClient.DataUpdater updater)
IZkClient.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.path - the path for the nodeupdater - Updater that creates the new contents.boolean waitForKeeperState(org.apache.zookeeper.Watcher.Event.KeeperState keeperState,
long time,
TimeUnit timeUnit)
keeperState - the statetime - some timetimeUnit - the time unitkeeperState before the end timeboolean waitUntilConnected()
throws ZkInterruptedException
waitForKeeperState(KeeperState.SyncConnected, Integer.MAX_VALUE, TimeUnit.MILLISECONDS);
ZkInterruptedException - the thread was interruptedwaitForKeeperState(org.apache.zookeeper.Watcher.Event.KeeperState, long, java.util.concurrent.TimeUnit)boolean waitUntilConnected(long time,
TimeUnit timeUnit)
time - soem timetimeUnit - the time unitboolean waitUntilExists(String path, TimeUnit timeUnit, long time)
path - the path for the nodetimeUnit - the time unittime - some timeorg.apache.zookeeper.data.Stat writeData(String path, byte[] data)
path - the path for the nodedata - the data for the nodeorg.apache.zookeeper.data.Stat writeData(String path, byte[] data, int expectedVersion)
path - the path for the nodedata - the data for the nodeexpectedVersion - the version for the nodecas(String, com.github.zkclient.IZkClient.DataUpdater)List<?> multi(Iterable<?> ops)
ops - operationsZooKeeper.multi(Iterable),
Op,
OpResultorg.apache.zookeeper.ZooKeeper getZooKeeper()
boolean isConnected()
Copyright © 2019. All rights reserved.