@InterfaceAudience.Public
public class ZooKeeper
extends java.lang.Object
Once a connection to a server is established, a session ID is assigned to the client. The client will send heart beats to the server periodically to keep the session valid.
The application can call ZooKeeper APIs through a client as long as the session ID of the client remains valid.
If for some reason, the client fails to send heart beats to the server for a prolonged period of time (exceeding the sessionTimeout value, for instance), the server will expire the session, and the session ID will become invalid. The client object will no longer be usable. To make ZooKeeper API calls, the application must create a new client object.
If the ZooKeeper server the client currently connects to fails or otherwise does not respond, the client will automatically try to connect to another server before its session ID expires. If successful, the application can continue to use the client.
The ZooKeeper API methods are either synchronous or asynchronous. Synchronous methods blocks until the server has responded. Asynchronous methods just queue the request for sending and return immediately. They take a callback object that will be executed either on successful execution of the request or on error with an appropriate return code (rc) indicating the error.
Some successful ZooKeeper API calls can leave watches on the "data nodes" in the ZooKeeper server. Other successful ZooKeeper API calls can trigger those watches. Once a watch is triggered, an event will be delivered to the client which left the watch at the first place. Each watch can be triggered only once. Thus, up to one event will be delivered to a client for every watch it leaves.
A client needs an object of a class implementing Watcher interface for processing the events delivered to the client. When a client drops the current connection and re-connects to a server, all the existing watches are considered as being triggered but the undelivered events are lost. To emulate this, the client will generate a special event to tell the event handler a connection has been dropped. This special event has EventType None and KeeperState Disconnected.
Modifier and Type | Class and Description |
---|---|
static class |
ZooKeeper.States |
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
ZOOKEEPER_CLIENT_CNXN_SOCKET |
Constructor and Description |
---|
ZooKeeper(java.lang.String connectString,
int sessionTimeout,
Watcher watcher)
To create a ZooKeeper client object, the application needs to pass a
connection string containing a comma separated list of host:port pairs,
each corresponding to a ZooKeeper server.
|
ZooKeeper(java.lang.String connectString,
int sessionTimeout,
Watcher watcher,
boolean canBeReadOnly)
To create a ZooKeeper client object, the application needs to pass a
connection string containing a comma separated list of host:port pairs,
each corresponding to a ZooKeeper server.
|
ZooKeeper(java.lang.String connectString,
int sessionTimeout,
Watcher watcher,
long sessionId,
byte[] sessionPasswd)
To create a ZooKeeper client object, the application needs to pass a
connection string containing a comma separated list of host:port pairs,
each corresponding to a ZooKeeper server.
|
ZooKeeper(java.lang.String connectString,
int sessionTimeout,
Watcher watcher,
long sessionId,
byte[] sessionPasswd,
boolean canBeReadOnly)
To create a ZooKeeper client object, the application needs to pass a
connection string containing a comma separated list of host:port pairs,
each corresponding to a ZooKeeper server.
|
Modifier and Type | Method and Description |
---|---|
void |
addAuthInfo(java.lang.String scheme,
byte[] auth)
Add the specified scheme:auth information to this connection.
|
void |
close()
Close this client object.
|
java.lang.String |
create(java.lang.String path,
byte[] data,
java.util.List<ACL> acl,
CreateMode createMode)
Create a node with the given path.
|
void |
create(java.lang.String path,
byte[] data,
java.util.List<ACL> acl,
CreateMode createMode,
AsyncCallback.StringCallback cb,
java.lang.Object ctx)
The asynchronous version of create.
|
void |
delete(java.lang.String path,
int version)
Delete the node with the given path.
|
void |
delete(java.lang.String path,
int version,
AsyncCallback.VoidCallback cb,
java.lang.Object ctx)
The asynchronous version of delete.
|
Stat |
exists(java.lang.String path,
boolean watch)
Return the stat of the node of the given path.
|
void |
exists(java.lang.String path,
boolean watch,
AsyncCallback.StatCallback cb,
java.lang.Object ctx)
The asynchronous version of exists.
|
Stat |
exists(java.lang.String path,
Watcher watcher)
Return the stat of the node of the given path.
|
void |
exists(java.lang.String path,
Watcher watcher,
AsyncCallback.StatCallback cb,
java.lang.Object ctx)
The asynchronous version of exists.
|
java.util.List<ACL> |
getACL(java.lang.String path,
Stat stat)
Return the ACL and stat of the node of the given path.
|
void |
getACL(java.lang.String path,
Stat stat,
AsyncCallback.ACLCallback cb,
java.lang.Object ctx)
The asynchronous version of getACL.
|
java.util.List<java.lang.String> |
getChildren(java.lang.String path,
boolean watch)
Return the list of the children of the node of the given path.
|
void |
getChildren(java.lang.String path,
boolean watch,
AsyncCallback.Children2Callback cb,
java.lang.Object ctx)
The asynchronous version of getChildren.
|
void |
getChildren(java.lang.String path,
boolean watch,
AsyncCallback.ChildrenCallback cb,
java.lang.Object ctx)
The asynchronous version of getChildren.
|
java.util.List<java.lang.String> |
getChildren(java.lang.String path,
boolean watch,
Stat stat)
For the given znode path return the stat and children list.
|
java.util.List<java.lang.String> |
getChildren(java.lang.String path,
Watcher watcher)
Return the list of the children of the node of the given path.
|
void |
getChildren(java.lang.String path,
Watcher watcher,
AsyncCallback.Children2Callback cb,
java.lang.Object ctx)
The asynchronous version of getChildren.
|
void |
getChildren(java.lang.String path,
Watcher watcher,
AsyncCallback.ChildrenCallback cb,
java.lang.Object ctx)
The asynchronous version of getChildren.
|
java.util.List<java.lang.String> |
getChildren(java.lang.String path,
Watcher watcher,
Stat stat)
For the given znode path return the stat and children list.
|
void |
getData(java.lang.String path,
boolean watch,
AsyncCallback.DataCallback cb,
java.lang.Object ctx)
The asynchronous version of getData.
|
byte[] |
getData(java.lang.String path,
boolean watch,
Stat stat)
Return the data and the stat of the node of the given path.
|
void |
getData(java.lang.String path,
Watcher watcher,
AsyncCallback.DataCallback cb,
java.lang.Object ctx)
The asynchronous version of getData.
|
byte[] |
getData(java.lang.String path,
Watcher watcher,
Stat stat)
Return the data and the stat of the node of the given path.
|
org.apache.zookeeper.client.ZooKeeperSaslClient |
getSaslClient() |
long |
getSessionId()
The session id for this ZooKeeper client instance.
|
byte[] |
getSessionPasswd()
The session password for this ZooKeeper client instance.
|
int |
getSessionTimeout()
The negotiated session timeout for this ZooKeeper client instance.
|
ZooKeeper.States |
getState() |
org.apache.zookeeper.Testable |
getTestable() |
java.util.List<org.apache.zookeeper.OpResult> |
multi(java.lang.Iterable<org.apache.zookeeper.Op> ops)
Executes multiple ZooKeeper operations or none of them.
|
void |
multi(java.lang.Iterable<org.apache.zookeeper.Op> ops,
AsyncCallback.MultiCallback cb,
java.lang.Object ctx)
The asynchronous version of multi.
|
void |
register(Watcher watcher)
Specify the default watcher for the connection (overrides the one
specified during construction).
|
Stat |
setACL(java.lang.String path,
java.util.List<ACL> acl,
int aclVersion)
Set the ACL for the node of the given path if such a node exists and the
given aclVersion matches the acl version of the node.
|
void |
setACL(java.lang.String path,
java.util.List<ACL> acl,
int version,
AsyncCallback.StatCallback cb,
java.lang.Object ctx)
The asynchronous version of setACL.
|
Stat |
setData(java.lang.String path,
byte[] data,
int version)
Set the data for the node of the given path if such a node exists and the
given version matches the version of the node (if the given version is
-1, it matches any node's versions).
|
void |
setData(java.lang.String path,
byte[] data,
int version,
AsyncCallback.StatCallback cb,
java.lang.Object ctx)
The asynchronous version of setData.
|
void |
sync(java.lang.String path,
AsyncCallback.VoidCallback cb,
java.lang.Object ctx)
Asynchronous sync.
|
java.lang.String |
toString()
String representation of this ZooKeeper client.
|
Transaction |
transaction()
A Transaction is a thin wrapper on the
multi(java.lang.Iterable<org.apache.zookeeper.Op>) method
which provides a builder object that can be used to construct
and commit an atomic set of operations. |
public static final java.lang.String ZOOKEEPER_CLIENT_CNXN_SOCKET
public ZooKeeper(java.lang.String connectString, int sessionTimeout, Watcher watcher) throws java.io.IOException
Session establishment is asynchronous. This constructor will initiate connection to the server and return immediately - potentially (usually) before the session is fully established. The watcher argument specifies the watcher that will be notified of any changes in state. This notification can come at any point before or after the constructor call has returned.
The instantiated ZooKeeper client object will pick an arbitrary server from the connectString and attempt to connect to it. If establishment of the connection fails, another server in the connect string will be tried (the order is non-deterministic, as we random shuffle the list), until a connection is established. The client will continue attempts until the session is explicitly closed.
Added in 3.2.0: An optional "chroot" suffix may also be appended to the connection string. This will run the client commands while interpreting all paths relative to this root (similar to the unix chroot command).
connectString
- comma separated host:port pairs, each corresponding to a zk
server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002" If
the optional chroot suffix is used the example would look
like: "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002/app/a"
where the client would be rooted at "/app/a" and all paths
would be relative to this root - ie getting/setting/etc...
"/foo/bar" would result in operations being run on
"/app/a/foo/bar" (from the server perspective).sessionTimeout
- session timeout in millisecondswatcher
- a watcher object which will be notified of state changes, may
also be notified for node eventsjava.io.IOException
- in cases of network failurejava.lang.IllegalArgumentException
- if an invalid chroot path is specifiedpublic ZooKeeper(java.lang.String connectString, int sessionTimeout, Watcher watcher, boolean canBeReadOnly) throws java.io.IOException
Session establishment is asynchronous. This constructor will initiate connection to the server and return immediately - potentially (usually) before the session is fully established. The watcher argument specifies the watcher that will be notified of any changes in state. This notification can come at any point before or after the constructor call has returned.
The instantiated ZooKeeper client object will pick an arbitrary server from the connectString and attempt to connect to it. If establishment of the connection fails, another server in the connect string will be tried (the order is non-deterministic, as we random shuffle the list), until a connection is established. The client will continue attempts until the session is explicitly closed.
Added in 3.2.0: An optional "chroot" suffix may also be appended to the connection string. This will run the client commands while interpreting all paths relative to this root (similar to the unix chroot command).
connectString
- comma separated host:port pairs, each corresponding to a zk
server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002" If
the optional chroot suffix is used the example would look
like: "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002/app/a"
where the client would be rooted at "/app/a" and all paths
would be relative to this root - ie getting/setting/etc...
"/foo/bar" would result in operations being run on
"/app/a/foo/bar" (from the server perspective).sessionTimeout
- session timeout in millisecondswatcher
- a watcher object which will be notified of state changes, may
also be notified for node eventscanBeReadOnly
- (added in 3.4) whether the created client is allowed to go to
read-only mode in case of partitioning. Read-only mode
basically means that if the client can't find any majority
servers but there's partitioned server it could reach, it
connects to one in read-only mode, i.e. read requests are
allowed while write requests are not. It continues seeking for
majority in the background.java.io.IOException
- in cases of network failurejava.lang.IllegalArgumentException
- if an invalid chroot path is specifiedpublic ZooKeeper(java.lang.String connectString, int sessionTimeout, Watcher watcher, long sessionId, byte[] sessionPasswd) throws java.io.IOException
Session establishment is asynchronous. This constructor will initiate connection to the server and return immediately - potentially (usually) before the session is fully established. The watcher argument specifies the watcher that will be notified of any changes in state. This notification can come at any point before or after the constructor call has returned.
The instantiated ZooKeeper client object will pick an arbitrary server from the connectString and attempt to connect to it. If establishment of the connection fails, another server in the connect string will be tried (the order is non-deterministic, as we random shuffle the list), until a connection is established. The client will continue attempts until the session is explicitly closed (or the session is expired by the server).
Added in 3.2.0: An optional "chroot" suffix may also be appended to the connection string. This will run the client commands while interpreting all paths relative to this root (similar to the unix chroot command).
Use getSessionId()
and getSessionPasswd()
on an established
client connection, these values must be passed as sessionId and
sessionPasswd respectively if reconnecting. Otherwise, if not
reconnecting, use the other constructor which does not require these
parameters.
connectString
- comma separated host:port pairs, each corresponding to a zk
server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002"
If the optional chroot suffix is used the example would look
like: "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002/app/a"
where the client would be rooted at "/app/a" and all paths
would be relative to this root - ie getting/setting/etc...
"/foo/bar" would result in operations being run on
"/app/a/foo/bar" (from the server perspective).sessionTimeout
- session timeout in millisecondswatcher
- a watcher object which will be notified of state changes, may
also be notified for node eventssessionId
- specific session id to use if reconnectingsessionPasswd
- password for this sessionjava.io.IOException
- in cases of network failurejava.lang.IllegalArgumentException
- if an invalid chroot path is specifiedjava.lang.IllegalArgumentException
- for an invalid list of ZooKeeper hostspublic ZooKeeper(java.lang.String connectString, int sessionTimeout, Watcher watcher, long sessionId, byte[] sessionPasswd, boolean canBeReadOnly) throws java.io.IOException
Session establishment is asynchronous. This constructor will initiate connection to the server and return immediately - potentially (usually) before the session is fully established. The watcher argument specifies the watcher that will be notified of any changes in state. This notification can come at any point before or after the constructor call has returned.
The instantiated ZooKeeper client object will pick an arbitrary server from the connectString and attempt to connect to it. If establishment of the connection fails, another server in the connect string will be tried (the order is non-deterministic, as we random shuffle the list), until a connection is established. The client will continue attempts until the session is explicitly closed (or the session is expired by the server).
Added in 3.2.0: An optional "chroot" suffix may also be appended to the connection string. This will run the client commands while interpreting all paths relative to this root (similar to the unix chroot command).
Use getSessionId()
and getSessionPasswd()
on an established
client connection, these values must be passed as sessionId and
sessionPasswd respectively if reconnecting. Otherwise, if not
reconnecting, use the other constructor which does not require these
parameters.
connectString
- comma separated host:port pairs, each corresponding to a zk
server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002"
If the optional chroot suffix is used the example would look
like: "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002/app/a"
where the client would be rooted at "/app/a" and all paths
would be relative to this root - ie getting/setting/etc...
"/foo/bar" would result in operations being run on
"/app/a/foo/bar" (from the server perspective).sessionTimeout
- session timeout in millisecondswatcher
- a watcher object which will be notified of state changes, may
also be notified for node eventssessionId
- specific session id to use if reconnectingsessionPasswd
- password for this sessioncanBeReadOnly
- (added in 3.4) whether the created client is allowed to go to
read-only mode in case of partitioning. Read-only mode
basically means that if the client can't find any majority
servers but there's partitioned server it could reach, it
connects to one in read-only mode, i.e. read requests are
allowed while write requests are not. It continues seeking for
majority in the background.java.io.IOException
- in cases of network failurejava.lang.IllegalArgumentException
- if an invalid chroot path is specifiedpublic org.apache.zookeeper.client.ZooKeeperSaslClient getSaslClient()
public org.apache.zookeeper.Testable getTestable()
public long getSessionId()
public byte[] getSessionPasswd()
public int getSessionTimeout()
public void addAuthInfo(java.lang.String scheme, byte[] auth)
scheme
- auth
- public void register(Watcher watcher)
watcher
- public void close() throws java.lang.InterruptedException
java.lang.InterruptedException
public java.lang.String create(java.lang.String path, byte[] data, java.util.List<ACL> acl, CreateMode createMode) throws KeeperException, java.lang.InterruptedException
The flags argument specifies whether the created node will be ephemeral or not.
An ephemeral node will be removed by the ZooKeeper automatically when the session associated with the creation of the node expires.
The flags argument can also specify to create a sequential node. The actual path name of a sequential node will be the given path plus a suffix "i" where i is the current sequential number of the node. The sequence number is always fixed length of 10 digits, 0 padded. Once such a node is created, the sequential number will be incremented by one.
If a node with the same actual path already exists in the ZooKeeper, a KeeperException with error code KeeperException.NodeExists will be thrown. Note that since a different actual path is used for each invocation of creating sequential node with the same path argument, the call will never throw "file exists" KeeperException.
If the parent node does not exist in the ZooKeeper, a KeeperException with error code KeeperException.NoNode will be thrown.
An ephemeral node cannot have children. If the parent node of the given path is ephemeral, a KeeperException with error code KeeperException.NoChildrenForEphemerals will be thrown.
This operation, if successful, will trigger all the watches left on the node of the given path by exists and getData API calls, and the watches left on the parent node by getChildren API calls.
If a node is created successfully, the ZooKeeper server will trigger the watches on the path left by exists calls, and the watches on the parent of the node by getChildren calls.
The maximum allowable size of the data array is 1 MB (1,048,576 bytes). Arrays larger than this will cause a KeeperExecption to be thrown.
path
- the path for the nodedata
- the initial data for the nodeacl
- the acl for the nodecreateMode
- specifying whether the node to be created is ephemeral
and/or sequentialKeeperException
- if the server returns a non-zero error codeKeeperException.InvalidACLException
- if the ACL is invalid, null, or emptyjava.lang.InterruptedException
- if the transaction is interruptedjava.lang.IllegalArgumentException
- if an invalid path is specifiedpublic void create(java.lang.String path, byte[] data, java.util.List<ACL> acl, CreateMode createMode, AsyncCallback.StringCallback cb, java.lang.Object ctx)
create(String, byte[], List, CreateMode)
public void delete(java.lang.String path, int version) throws java.lang.InterruptedException, KeeperException
A KeeperException with error code KeeperException.NoNode will be thrown if the nodes does not exist.
A KeeperException with error code KeeperException.BadVersion will be thrown if the given version does not match the node's version.
A KeeperException with error code KeeperException.NotEmpty will be thrown if the node has children.
This operation, if successful, will trigger all the watches on the node of the given path left by exists API calls, and the watches on the parent node left by getChildren API calls.
path
- the path of the node to be deleted.version
- the expected node version.java.lang.InterruptedException
- IF the server transaction is interruptedKeeperException
- If the server signals an error with a non-zero
return code.java.lang.IllegalArgumentException
- if an invalid path is specifiedpublic java.util.List<org.apache.zookeeper.OpResult> multi(java.lang.Iterable<org.apache.zookeeper.Op> ops) throws java.lang.InterruptedException, KeeperException
On success, a list of results is returned.
On failure, an exception is raised which contains partial results and
error details, see KeeperException.getResults()
Note: The maximum allowable size of all of the data arrays in all of the setData operations in this single request is typically 1 MB (1,048,576 bytes). This limit is specified on the server via jute.maxbuffer. Requests larger than this will cause a KeeperException to be thrown.
ops
- An iterable that contains the operations to be done.
These should be created using the factory methods on Op
.ops
input
operations.java.lang.InterruptedException
- If the operation was interrupted.
The operation may or may not have succeeded, but will not have
partially succeeded if this exception is thrown.KeeperException
- If the operation could not be completed
due to some error in doing one of the specified ops.java.lang.IllegalArgumentException
- if an invalid path is specifiedpublic void multi(java.lang.Iterable<org.apache.zookeeper.Op> ops, AsyncCallback.MultiCallback cb, java.lang.Object ctx)
multi(Iterable)
public Transaction transaction()
multi(java.lang.Iterable<org.apache.zookeeper.Op>)
method
which provides a builder object that can be used to construct
and commit an atomic set of operations.public void delete(java.lang.String path, int version, AsyncCallback.VoidCallback cb, java.lang.Object ctx)
delete(String, int)
public Stat exists(java.lang.String path, Watcher watcher) throws KeeperException, java.lang.InterruptedException
If the watch is non-null and the call is successful (no exception is thrown), a watch will be left on the node with the given path. The watch will be triggered by a successful operation that creates/delete the node or sets the data on the node.
path
- the node pathwatcher
- explicit watcherKeeperException
- If the server signals an errorjava.lang.InterruptedException
- If the server transaction is interrupted.java.lang.IllegalArgumentException
- if an invalid path is specifiedpublic Stat exists(java.lang.String path, boolean watch) throws KeeperException, java.lang.InterruptedException
If the watch is true and the call is successful (no exception is thrown), a watch will be left on the node with the given path. The watch will be triggered by a successful operation that creates/delete the node or sets the data on the node.
path
- the node pathwatch
- whether need to watch this nodeKeeperException
- If the server signals an errorjava.lang.InterruptedException
- If the server transaction is interrupted.public void exists(java.lang.String path, Watcher watcher, AsyncCallback.StatCallback cb, java.lang.Object ctx)
exists(String, Watcher)
public void exists(java.lang.String path, boolean watch, AsyncCallback.StatCallback cb, java.lang.Object ctx)
exists(String, boolean)
public byte[] getData(java.lang.String path, Watcher watcher, Stat stat) throws KeeperException, java.lang.InterruptedException
If the watch is non-null and the call is successful (no exception is thrown), a watch will be left on the node with the given path. The watch will be triggered by a successful operation that sets data on the node, or deletes the node.
A KeeperException with error code KeeperException.NoNode will be thrown if no node with the given path exists.
path
- the given pathwatcher
- explicit watcherstat
- the stat of the nodeKeeperException
- If the server signals an error with a non-zero error codejava.lang.InterruptedException
- If the server transaction is interrupted.java.lang.IllegalArgumentException
- if an invalid path is specifiedpublic byte[] getData(java.lang.String path, boolean watch, Stat stat) throws KeeperException, java.lang.InterruptedException
If the watch is true and the call is successful (no exception is thrown), a watch will be left on the node with the given path. The watch will be triggered by a successful operation that sets data on the node, or deletes the node.
A KeeperException with error code KeeperException.NoNode will be thrown if no node with the given path exists.
path
- the given pathwatch
- whether need to watch this nodestat
- the stat of the nodeKeeperException
- If the server signals an error with a non-zero error codejava.lang.InterruptedException
- If the server transaction is interrupted.public void getData(java.lang.String path, Watcher watcher, AsyncCallback.DataCallback cb, java.lang.Object ctx)
getData(String, Watcher, Stat)
public void getData(java.lang.String path, boolean watch, AsyncCallback.DataCallback cb, java.lang.Object ctx)
getData(String, boolean, Stat)
public Stat setData(java.lang.String path, byte[] data, int version) throws KeeperException, java.lang.InterruptedException
This operation, if successful, will trigger all the watches on the node of the given path left by getData calls.
A KeeperException with error code KeeperException.NoNode will be thrown if no node with the given path exists.
A KeeperException with error code KeeperException.BadVersion will be thrown if the given version does not match the node's version.
The maximum allowable size of the data array is 1 MB (1,048,576 bytes). Arrays larger than this will cause a KeeperException to be thrown.
path
- the path of the nodedata
- the data to setversion
- the expected matching versionjava.lang.InterruptedException
- If the server transaction is interrupted.KeeperException
- If the server signals an error with a non-zero error code.java.lang.IllegalArgumentException
- if an invalid path is specifiedpublic void setData(java.lang.String path, byte[] data, int version, AsyncCallback.StatCallback cb, java.lang.Object ctx)
setData(String, byte[], int)
public java.util.List<ACL> getACL(java.lang.String path, Stat stat) throws KeeperException, java.lang.InterruptedException
A KeeperException with error code KeeperException.NoNode will be thrown if no node with the given path exists.
path
- the given path for the nodestat
- the stat of the node will be copied to this parameter if
not null.java.lang.InterruptedException
- If the server transaction is interrupted.KeeperException
- If the server signals an error with a non-zero error code.java.lang.IllegalArgumentException
- if an invalid path is specifiedpublic void getACL(java.lang.String path, Stat stat, AsyncCallback.ACLCallback cb, java.lang.Object ctx)
getACL(String, Stat)
public Stat setACL(java.lang.String path, java.util.List<ACL> acl, int aclVersion) throws KeeperException, java.lang.InterruptedException
A KeeperException with error code KeeperException.NoNode will be thrown if no node with the given path exists.
A KeeperException with error code KeeperException.BadVersion will be thrown if the given aclVersion does not match the node's aclVersion.
path
- the given path for the nodeacl
- the given acl for the nodeaclVersion
- the given acl version of the nodejava.lang.InterruptedException
- If the server transaction is interrupted.KeeperException
- If the server signals an error with a non-zero error code.KeeperException.InvalidACLException
- If the acl is invalide.java.lang.IllegalArgumentException
- if an invalid path is specifiedpublic void setACL(java.lang.String path, java.util.List<ACL> acl, int version, AsyncCallback.StatCallback cb, java.lang.Object ctx)
setACL(String, List, int)
public java.util.List<java.lang.String> getChildren(java.lang.String path, Watcher watcher) throws KeeperException, java.lang.InterruptedException
If the watch is non-null and the call is successful (no exception is thrown), a watch will be left on the node with the given path. The watch willbe triggered by a successful operation that deletes the node of the given path or creates/delete a child under the node.
The list of children returned is not sorted and no guarantee is provided as to its natural or lexical order.
A KeeperException with error code KeeperException.NoNode will be thrown if no node with the given path exists.
path
- watcher
- explicit watcherjava.lang.InterruptedException
- If the server transaction is interrupted.KeeperException
- If the server signals an error with a non-zero error code.java.lang.IllegalArgumentException
- if an invalid path is specifiedpublic java.util.List<java.lang.String> getChildren(java.lang.String path, boolean watch) throws KeeperException, java.lang.InterruptedException
If the watch is true and the call is successful (no exception is thrown), a watch will be left on the node with the given path. The watch willbe triggered by a successful operation that deletes the node of the given path or creates/delete a child under the node.
The list of children returned is not sorted and no guarantee is provided as to its natural or lexical order.
A KeeperException with error code KeeperException.NoNode will be thrown if no node with the given path exists.
path
- watch
- java.lang.InterruptedException
- If the server transaction is interrupted.KeeperException
- If the server signals an error with a non-zero error code.public void getChildren(java.lang.String path, Watcher watcher, AsyncCallback.ChildrenCallback cb, java.lang.Object ctx)
getChildren(String, Watcher)
public void getChildren(java.lang.String path, boolean watch, AsyncCallback.ChildrenCallback cb, java.lang.Object ctx)
getChildren(String, boolean)
public java.util.List<java.lang.String> getChildren(java.lang.String path, Watcher watcher, Stat stat) throws KeeperException, java.lang.InterruptedException
If the watch is non-null and the call is successful (no exception is thrown), a watch will be left on the node with the given path. The watch willbe triggered by a successful operation that deletes the node of the given path or creates/delete a child under the node.
The list of children returned is not sorted and no guarantee is provided as to its natural or lexical order.
A KeeperException with error code KeeperException.NoNode will be thrown if no node with the given path exists.
path
- watcher
- explicit watcherstat
- stat of the znode designated by pathjava.lang.InterruptedException
- If the server transaction is interrupted.KeeperException
- If the server signals an error with a non-zero error code.java.lang.IllegalArgumentException
- if an invalid path is specifiedpublic java.util.List<java.lang.String> getChildren(java.lang.String path, boolean watch, Stat stat) throws KeeperException, java.lang.InterruptedException
If the watch is true and the call is successful (no exception is thrown), a watch will be left on the node with the given path. The watch willbe triggered by a successful operation that deletes the node of the given path or creates/delete a child under the node.
The list of children returned is not sorted and no guarantee is provided as to its natural or lexical order.
A KeeperException with error code KeeperException.NoNode will be thrown if no node with the given path exists.
path
- watch
- stat
- stat of the znode designated by pathjava.lang.InterruptedException
- If the server transaction is interrupted.KeeperException
- If the server signals an error with a non-zero
error code.public void getChildren(java.lang.String path, Watcher watcher, AsyncCallback.Children2Callback cb, java.lang.Object ctx)
getChildren(String, Watcher, Stat)
public void getChildren(java.lang.String path, boolean watch, AsyncCallback.Children2Callback cb, java.lang.Object ctx)
getChildren(String, boolean, Stat)
public void sync(java.lang.String path, AsyncCallback.VoidCallback cb, java.lang.Object ctx)
path
- cb
- a handler for the callbackctx
- context to be provided to the callbackjava.lang.IllegalArgumentException
- if an invalid path is specifiedpublic ZooKeeper.States getState()
public java.lang.String toString()
toString
in class java.lang.Object
Copyright © 2018 The Apache Software Foundation