Package org.apache.curator
Class RetryLoop
java.lang.Object
org.apache.curator.RetryLoop
Mechanism to perform an operation on Zookeeper that is safe against disconnections and "recoverable" errors.
If an exception occurs during the operation, the RetryLoop will process it, check with the current retry policy and either attempt to reconnect or re-throw the exception
Canonical usage:RetryLoop retryLoop = client.newRetryLoop(); while ( retryLoop.shouldContinue() ) { try { // do your work ZooKeeper zk = client.getZooKeeper(); // it's important to re-get the ZK instance in case there was an error and the instance was re-created retryLoop.markComplete(); } catch ( Exception e ) { retryLoop.takeException(e); } }
Note: this an abstract class
instead of an interface
for historical reasons. It was originally a class
and if it becomes an interface we risk IncompatibleClassChangeError
s with clients.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> T
callWithRetry
(CuratorZookeeperClient client, Callable<T> proc) Convenience utility: creates a retry loop calling the given proc and retrying if neededstatic RetrySleeper
Returns the default retry sleeperabstract void
Call this when your operation has successfully completedabstract boolean
If true is returned, make an attempt at the operationabstract void
takeException
(Exception exception) Pass any caught exceptions here
-
Constructor Details
-
RetryLoop
public RetryLoop()
-
-
Method Details
-
getDefaultRetrySleeper
Returns the default retry sleeper- Returns:
- sleeper
-
callWithRetry
Convenience utility: creates a retry loop calling the given proc and retrying if needed- Type Parameters:
T
- return type- Parameters:
client
- Zookeeperproc
- procedure to call with retry- Returns:
- procedure result
- Throws:
Exception
- any non-retriable errors
-
shouldContinue
public abstract boolean shouldContinue()If true is returned, make an attempt at the operation- Returns:
- true/false
-
markComplete
public abstract void markComplete()Call this when your operation has successfully completed -
takeException
Pass any caught exceptions here- Parameters:
exception
- the exception- Throws:
Exception
- if not retry-able or the retry policy returned negative
-