public class ZooKeeperExt extends Object
Modifier and Type | Class and Description |
---|---|
static class |
ZooKeeperExt.PathStat
Data structure for handling the output of createOrSet()
|
Modifier and Type | Field and Description |
---|---|
static int |
SEQUENCE_NUMBER_LENGTH
Length of the ZK sequence number
|
Constructor and Description |
---|
ZooKeeperExt(String connectString,
int sessionTimeout,
int maxRetryAttempts,
int retryWaitMsecs,
org.apache.zookeeper.Watcher watcher)
Constructor to connect to ZooKeeper, does not make progress
|
ZooKeeperExt(String connectString,
int sessionTimeout,
int maxRetryAttempts,
int retryWaitMsecs,
org.apache.zookeeper.Watcher watcher,
org.apache.hadoop.util.Progressable progressable)
Constructor to connect to ZooKeeper, make progress
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Close this client object.
|
String |
createExt(String path,
byte[] data,
List<org.apache.zookeeper.data.ACL> acl,
org.apache.zookeeper.CreateMode createMode,
boolean recursive)
Provides a possibility of a creating a path consisting of more than one
znode (not atomic).
|
ZooKeeperExt.PathStat |
createOnceExt(String path,
byte[] data,
List<org.apache.zookeeper.data.ACL> acl,
org.apache.zookeeper.CreateMode createMode,
boolean recursive)
Create a znode if there is no other znode there
|
ZooKeeperExt.PathStat |
createOrSetExt(String path,
byte[] data,
List<org.apache.zookeeper.data.ACL> acl,
org.apache.zookeeper.CreateMode createMode,
boolean recursive,
int version)
Create a znode.
|
void |
deleteExt(String path,
int version,
boolean recursive)
Delete a path recursively.
|
org.apache.zookeeper.data.Stat |
exists(String path,
boolean watch)
Return the stat of the node of the given path.
|
org.apache.zookeeper.data.Stat |
exists(String path,
org.apache.zookeeper.Watcher watcher)
Return the stat of the node of the given path.
|
List<String> |
getChildrenExt(String path,
boolean watch,
boolean sequenceSorted,
boolean fullPath)
Get the children of the path with extensions.
|
byte[] |
getData(String path,
boolean watch,
org.apache.zookeeper.data.Stat stat)
Return the data and the stat of the node of the given path.
|
byte[] |
getData(String path,
org.apache.zookeeper.Watcher watcher,
org.apache.zookeeper.data.Stat stat)
Return the data and the stat of the node of the given path.
|
public static final int SEQUENCE_NUMBER_LENGTH
public ZooKeeperExt(String connectString, int sessionTimeout, int maxRetryAttempts, int retryWaitMsecs, org.apache.zookeeper.Watcher watcher) throws IOException
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 millisecondsmaxRetryAttempts
- Max retry attempts during connection lossretryWaitMsecs
- Msecs to wait when retrying due to connection
losswatcher
- A watcher object which will be notified of state changes,
may also be notified for node eventsIOException
public ZooKeeperExt(String connectString, int sessionTimeout, int maxRetryAttempts, int retryWaitMsecs, org.apache.zookeeper.Watcher watcher, org.apache.hadoop.util.Progressable progressable) throws IOException
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 millisecondsmaxRetryAttempts
- Max retry attempts during connection lossretryWaitMsecs
- Msecs to wait when retrying due to connection
losswatcher
- A watcher object which will be notified of state changes,
may also be notified for node eventsprogressable
- Makes progress for longer operationsIOException
public String createExt(String path, byte[] data, List<org.apache.zookeeper.data.ACL> acl, org.apache.zookeeper.CreateMode createMode, boolean recursive) throws org.apache.zookeeper.KeeperException, InterruptedException
path
- path to createdata
- data to set on the final znodeacl
- acls on each znode createdcreateMode
- only affects the final znoderecursive
- if true, creates all ancestorsorg.apache.zookeeper.KeeperException
InterruptedException
public ZooKeeperExt.PathStat createOrSetExt(String path, byte[] data, List<org.apache.zookeeper.data.ACL> acl, org.apache.zookeeper.CreateMode createMode, boolean recursive, int version) throws org.apache.zookeeper.KeeperException, InterruptedException
path
- path to createdata
- data to set on the final znodeacl
- acls on each znode createdcreateMode
- only affects the final znoderecursive
- if true, creates all ancestorsversion
- Version to set if settingInterruptedException
org.apache.zookeeper.KeeperException
public ZooKeeperExt.PathStat createOnceExt(String path, byte[] data, List<org.apache.zookeeper.data.ACL> acl, org.apache.zookeeper.CreateMode createMode, boolean recursive) throws org.apache.zookeeper.KeeperException, InterruptedException
path
- path to createdata
- data to set on the final znodeacl
- acls on each znode createdcreateMode
- only affects the final znoderecursive
- if true, creates all ancestorsInterruptedException
org.apache.zookeeper.KeeperException
public void deleteExt(String path, int version, boolean recursive) throws InterruptedException, org.apache.zookeeper.KeeperException
path
- path to remove (i.e. /tmp will remove /tmp/1 and /tmp/2)version
- expected version (-1 for all)recursive
- if true, remove all children, otherwise behave like
remove()InterruptedException
org.apache.zookeeper.KeeperException
public org.apache.zookeeper.data.Stat exists(String path, boolean watch) throws org.apache.zookeeper.KeeperException, 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 nodeorg.apache.zookeeper.KeeperException
- If the server signals an errorInterruptedException
- If the server transaction is interrupted.public org.apache.zookeeper.data.Stat exists(String path, org.apache.zookeeper.Watcher watcher) throws org.apache.zookeeper.KeeperException, 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 watcherorg.apache.zookeeper.KeeperException
- If the server signals an errorInterruptedException
- If the server transaction is interrupted.IllegalArgumentException
- if an invalid path is specifiedpublic byte[] getData(String path, org.apache.zookeeper.Watcher watcher, org.apache.zookeeper.data.Stat stat) throws org.apache.zookeeper.KeeperException, 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 nodeorg.apache.zookeeper.KeeperException
- If the server signals an error with a non-zero
error codeInterruptedException
- If the server transaction is interrupted.IllegalArgumentException
- if an invalid path is specifiedpublic byte[] getData(String path, boolean watch, org.apache.zookeeper.data.Stat stat) throws org.apache.zookeeper.KeeperException, 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 nodeorg.apache.zookeeper.KeeperException
- If the server signals an error with a non-zero
error codeInterruptedException
- If the server transaction is interrupted.public List<String> getChildrenExt(String path, boolean watch, boolean sequenceSorted, boolean fullPath) throws org.apache.zookeeper.KeeperException, InterruptedException
path
- path to znodewatch
- set the watch?sequenceSorted
- sort by the sequence numberfullPath
- if true, get the fully znode path backInterruptedException
org.apache.zookeeper.KeeperException
public void close() throws InterruptedException
InterruptedException
Copyright © 2011-2020 The Apache Software Foundation. All Rights Reserved.