public class GuaguaZooKeeper extends Object
| Modifier and Type | Class and Description |
|---|---|
static interface |
GuaguaZooKeeper.Filter
Filter path out
GuaguaZooKeeper.Filter.filter(String) return true. |
static class |
GuaguaZooKeeper.PathStat
Data structure for handling the output of createOrSet()
|
| Constructor and Description |
|---|
GuaguaZooKeeper(String connectString,
int sessionTimeout,
int maxRetryAttempts,
int retryWaitMsecs,
org.apache.zookeeper.Watcher watcher)
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).
|
GuaguaZooKeeper.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
|
GuaguaZooKeeper.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.
|
List<String> |
getChildrenExt(String path,
boolean watch,
boolean sequenceSorted,
boolean fullPath,
GuaguaZooKeeper.Filter filter)
Get the children of the path with extensions.
|
List<String> |
getChildrenExt(String path,
boolean watch,
boolean fullPath,
Comparator<String> childComparator)
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.
|
int |
getMaxRetryAttempts() |
long |
getRetryWaitMsecs() |
org.apache.zookeeper.ZooKeeper |
getZooKeeper() |
protected void |
retryDelay(int attemptCount)
Performs a retry delay if this is not the first attempt
|
protected <T> T |
retryOperation(GuaguaZooKeeperOperation<T> operation)
Perform the given operation, retrying if the connection fails
|
public GuaguaZooKeeper(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 - In case of any io exception to connect to zookeeper server.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.KeeperExceptionInterruptedException - Both KeeperException InterruptedException are thrown from ZooKeeper methods.NullPointerException - If path is null.public GuaguaZooKeeper.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 settingInterruptedExceptionorg.apache.zookeeper.KeeperException - Both KeeperException InterruptedException are thrown from ZooKeeper methods.public GuaguaZooKeeper.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 ancestorsInterruptedExceptionorg.apache.zookeeper.KeeperException - Both KeeperException InterruptedException are thrown from ZooKeeper methods.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()InterruptedExceptionorg.apache.zookeeper.KeeperException - Both KeeperException InterruptedException are thrown from ZooKeeper methods.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 fullPath, Comparator<String> childComparator) throws org.apache.zookeeper.KeeperException, InterruptedException
childComparator number
Extension 2: Get the full path instead of relative pathpath - path to znodewatch - set the watch?fullPath - if true, get the fully znode path backchildComparator - comparator to sort children.InterruptedExceptionorg.apache.zookeeper.KeeperException - Both KeeperException InterruptedException are thrown from ZooKeeper methods.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 backInterruptedExceptionorg.apache.zookeeper.KeeperException - Both KeeperException InterruptedException are thrown from ZooKeeper methods.public List<String> getChildrenExt(String path, boolean watch, boolean sequenceSorted, boolean fullPath, GuaguaZooKeeper.Filter filter) 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 backfilter - filter some path out if not null.InterruptedExceptionorg.apache.zookeeper.KeeperException - Both KeeperException InterruptedException are thrown from ZooKeeper methods.public void close()
throws InterruptedException
InterruptedException - in case of InterruptedException from ZooKeeper#close();protected <T> T retryOperation(GuaguaZooKeeperOperation<T> operation) throws org.apache.zookeeper.KeeperException, InterruptedException
org.apache.zookeeper.KeeperExceptionInterruptedExceptionprotected void retryDelay(int attemptCount)
attemptCount - the number of the attempts performed so farpublic org.apache.zookeeper.ZooKeeper getZooKeeper()
public int getMaxRetryAttempts()
public long getRetryWaitMsecs()
Copyright © 2019. All Rights Reserved.