# Class ZooKeeperRetry

java.lang.Object
org.apache.zookeeper.ZooKeeper
org.apache.zookeeper.retry.ZooKeeperRetry

All Implemented Interfaces:
  `AutoCloseable`

public class ZooKeeperRetry extends ZooKeeper
A Class which extends `ZooKeeper` and will automatically retry calls to zookeeper if a `KeeperException.ConnectionLossException` occurs.

## Nested Class Summary

### Nested classes/interfaces inherited from class ZooKeeper

`ZooKeeper.States, ZooKeeper.WatchRegistration`

## Field Summary

### Fields inherited from class ZooKeeper

`cnxn, hostProvider, SECURE_CLIENT, ZOOKEEPER_CLIENT_CNXN_SOCKET`

## Constructor Summary

Constructors
Constructor
Description
`ZooKeeperRetry(String connectString, int sessionTimeout, Watcher watcher)`
`ZooKeeperRetry(String connectString, int sessionTimeout, Watcher watcher, long sessionId, byte[] sessionPasswd)`

## Method Summary

Modifier and Type
Method
Description
`void`
`close()`
Close this client object.
`String`
`create(String path, byte[] data, List<ACL> acl, CreateMode createMode)`
Create a node with the given path.
`void`
`delete(String path, int version)`
Delete the node with the given path.
`Stat`
`exists(String path, boolean watch)`
Return the stat of the node of the given path.
`Stat`
`exists(String path, Watcher watcher)`
Return the stat of the node of the given path.
`List<ACL>`
`getACL(String path, Stat stat)`
Return the ACL and stat of the node of the given path.
`List<String>`
`getChildren(String path, boolean watch)`
Return the list of the children of the node of the given path.
`List<String>`
`getChildren(String path, Watcher watcher)`
Return the list of the children of the node of the given path.
`byte[]`
`getData(String path, boolean watch, Stat stat)`
Return the data and the stat of the node of the given path.
`byte[]`
`getData(String path, Watcher watcher, Stat stat)`
Return the data and the stat of the node of the given path.
`Stat`
`setACL(String path, 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.
`Stat`
`setData(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`
`setRetryLimit(int limit)`
`boolean`
`testConnection()`

### Methods inherited from class ZooKeeper

`addAuthInfo, addWatch, addWatch, addWatch, addWatch, close, create, create, create, create, create, delete, exists, exists, getACL, getAllChildrenNumber, getAllChildrenNumber, getChildren, getChildren, getChildren, getChildren, getChildren, getChildren, getChildWatches, getClientConfig, getConfig, getConfig, getConfig, getConfig, getData, getData, getDataWatches, getEphemerals, getEphemerals, getEphemerals, getEphemerals, getExistWatches, getPersistentRecursiveWatches, getPersistentWatches, getSaslClient, getSessionId, getSessionPasswd, getSessionTimeout, getState, getTestable, multi, multi, multiInternal, multiInternal, register, removeAllWatches, removeAllWatches, removeWatches, removeWatches, setACL, setData, sync, sync, testableLocalSocketAddress, testableRemoteSocketAddress, testableWaitForShutdown, toString, transaction, updateServerList, whoAmI`

### Methods inherited from class Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

## Constructor Details

### ZooKeeperRetry

public ZooKeeperRetry(String connectString, int sessionTimeout, Watcher watcher) throws IOException

Parameters:
  `connectString` -
  `sessionTimeout` -
  `watcher` -
Throws:
  `IOException`

### ZooKeeperRetry

public ZooKeeperRetry(String connectString, int sessionTimeout, Watcher watcher, long sessionId, byte[] sessionPasswd) throws IOException

Parameters:
  `connectString` -
  `sessionTimeout` -
  `watcher` -
  `sessionId` -
  `sessionPasswd` -
Throws:
  `IOException`

## Method Details

### close

public void close() throws InterruptedException
Description copied from class: `ZooKeeper`
Close this client object. Once the client is closed, its session becomes invalid. All the ephemeral nodes in the ZooKeeper server associated with the session will be removed. The watches left on those nodes (and on their parents) will be triggered.

Added in 3.5.3: try-with-resources may be used instead of calling close directly.

This method does not wait for all internal threads to exit. Use the `ZooKeeper.close(int)` method to wait for all resources to be released

Specified by:
  `close` in interface `AutoCloseable`
Overrides:
  `close` in class `ZooKeeper`
Throws:
  `InterruptedException`

### create

public String create(String path, byte[] data, List<ACL> acl, CreateMode createMode) throws KeeperException, InterruptedException
Description copied from class: `ZooKeeper`
Create a node with the given path. The node data will be the given data, and node acl will be the given acl.

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.

Overrides:
  `create` in class `ZooKeeper`
Parameters:
  `path` - the path for the node
  `data` - the initial data for the node
  `acl` - the acl for the node
  `createMode` - specifying whether the node to be created is ephemeral and/or sequential
Returns:
  the actual path of the created node
Throws:
  `KeeperException` - if the server returns a non-zero error code
  `InterruptedException` - if the transaction is interrupted

### delete

public void delete(String path, int version) throws InterruptedException, KeeperException
Description copied from class: `ZooKeeper`
Delete the node with the given path. The call will succeed if such a node exists, and the given version matches the node's version (if the given version is -1, it matches any node's versions).

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.

Overrides:
  `delete` in class `ZooKeeper`
Parameters:
  `path` - the path of the node to be deleted.
  `version` - the expected node version.
Throws:
  `InterruptedException` - IF the server transaction is interrupted
  `KeeperException` - If the server signals an error with a non-zero return code.

### exists

public Stat exists(String path, boolean watch) throws KeeperException, InterruptedException
Description copied from class: `ZooKeeper`
Return the stat of the node of the given path. Return null if no such a node exists.

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.

Overrides:
  `exists` in class `ZooKeeper`
Parameters:
  `path` - the node path
  `watch` - whether need to watch this node
Returns:
  the stat of the node of the given path; return null if no such a node exists.
Throws:
  `KeeperException` - If the server signals an error
  `InterruptedException` - If the server transaction is interrupted.

### exists

public Stat exists(String path, Watcher watcher) throws KeeperException, InterruptedException
Description copied from class: `ZooKeeper`
Return the stat of the node of the given path. Return null if no such a node exists.

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.

Overrides:
  `exists` in class `ZooKeeper`
Parameters:
  `path` - the node path
  `watcher` - explicit watcher
Returns:
  the stat of the node of the given path; return null if no such a node exists.
Throws:
  `KeeperException` - If the server signals an error
  `InterruptedException` - If the server transaction is interrupted.

### getACL

public List<ACL> getACL(String path, Stat stat) throws KeeperException, InterruptedException
Description copied from class: `ZooKeeper`
Return the ACL and stat of the node of the given path.

A KeeperException with error code KeeperException.NoNode will be thrown if no node with the given path exists.

Overrides:
  `getACL` in class `ZooKeeper`
Parameters:
  `path` - the given path for the node
  `stat` - the stat of the node will be copied to this parameter if not null.
Returns:
  the ACL array of the given node.
Throws:
  `KeeperException` - If the server signals an error with a non-zero error code.
  `InterruptedException` - If the server transaction is interrupted.

### getChildren

public List<String> getChildren(String path, boolean watch) throws KeeperException, InterruptedException
Description copied from class: `ZooKeeper`
Return the list of the children of the node of the given path.

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 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.

Overrides:
  `getChildren` in class `ZooKeeper`
Parameters:
  `path` - the node path
  `watch` - whether need to watch this node
Returns:
  an unordered array of children of the node with the given path
Throws:
  `KeeperException` - If the server signals an error with a non-zero error code.
  `InterruptedException` - If the server transaction is interrupted.

### getChildren

public List<String> getChildren(String path, Watcher watcher) throws KeeperException, InterruptedException
Description copied from class: `ZooKeeper`
Return the list of the children of the node of the given path.

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 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.

Overrides:
  `getChildren` in class `ZooKeeper`
Parameters:
  `path` -
  `watcher` - explicit watcher
Returns:
  an unordered array of children of the node with the given path
Throws:
  `KeeperException` - If the server signals an error with a non-zero error code.
  `InterruptedException` - If the server transaction is interrupted.

### getData

public byte[] getData(String path, boolean watch, Stat stat) throws KeeperException, InterruptedException
Description copied from class: `ZooKeeper`
Return the data and the stat of the node of the given path.

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.

Overrides:
  `getData` in class `ZooKeeper`
Parameters:
  `path` - the given path
  `watch` - whether need to watch this node
  `stat` - the stat of the node
Returns:
  the data of the node
Throws:
  `KeeperException` - If the server signals an error with a non-zero error code
  `InterruptedException` - If the server transaction is interrupted.

### getData

public byte[] getData(String path, Watcher watcher, Stat stat) throws KeeperException, InterruptedException
Description copied from class: `ZooKeeper`
Return the data and the stat of the node of the given path.

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.

Overrides:
  `getData` in class `ZooKeeper`
Parameters:
  `path` - the given path
  `watcher` - explicit watcher
  `stat` - the stat of the node
Returns:
  the data of the node
Throws:
  `KeeperException` - If the server signals an error with a non-zero error code
  `InterruptedException` - If the server transaction is interrupted.

### setACL

public Stat setACL(String path, List<ACL> acl, int aclVersion) throws KeeperException, InterruptedException
Description copied from class: `ZooKeeper`
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. Return the stat of the node.

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.

Overrides:
  `setACL` in class `ZooKeeper`
Parameters:
  `path` - the given path for the node
  `acl` - the given acl for the node
  `aclVersion` - the given acl version of the node
Returns:
  the stat of the node.
Throws:
  `KeeperException` - If the server signals an error with a non-zero error code.
  `InterruptedException` - If the server transaction is interrupted.

### setData

public Stat setData(String path, byte[] data, int version) throws KeeperException, InterruptedException
Description copied from class: `ZooKeeper`
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). Return the stat of the node.

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.

Overrides:
  `setData` in class `ZooKeeper`
Parameters:
  `path` - the path of the node
  `data` - the data to set
  `version` - the expected matching version
Returns:
  the state of the node
Throws:
  `KeeperException` - If the server signals an error with a non-zero error code.
  `InterruptedException` - If the server transaction is interrupted.

### setRetryLimit

public void setRetryLimit(int limit)

Parameters:
  `limit` -

### testConnection

public boolean testConnection()

Returns:
  true if successfully connected to zookeeper