|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.curator.RetryLoop
public class 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); } }
Method Summary | ||
---|---|---|
static
|
callWithRetry(CuratorZookeeperClient client,
Callable<T> proc)
Convenience utility: creates a retry loop calling the given proc and retrying if needed |
|
static RetrySleeper |
getDefaultRetrySleeper()
Returns the default retry sleeper |
|
static boolean |
isRetryException(Throwable exception)
Utility - return true if the given exception is retry-able |
|
void |
markComplete()
Call this when your operation has successfully completed |
|
boolean |
shouldContinue()
If true is returned, make an attempt at the operation |
|
static boolean |
shouldRetry(int rc)
Utility - return true if the given Zookeeper result code is retry-able |
|
void |
takeException(Exception exception)
Pass any caught exceptions here |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static RetrySleeper getDefaultRetrySleeper()
public static <T> T callWithRetry(CuratorZookeeperClient client, Callable<T> proc) throws Exception
T
- return typeclient
- Zookeeperproc
- procedure to call with retry
Exception
- any non-retriable errorspublic boolean shouldContinue()
public void markComplete()
public static boolean shouldRetry(int rc)
rc
- result code
public static boolean isRetryException(Throwable exception)
exception
- exception to check
public void takeException(Exception exception) throws Exception
exception
- the exception
Exception
- if not retry-able or the retry policy returned negative
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |