Class ThreadLocalRetryLoop
- java.lang.Object
-
- org.apache.curator.connection.ThreadLocalRetryLoop
-
public class ThreadLocalRetryLoop extends java.lang.Object
Retry loops can easily end up getting nested which can cause exponential calls of the retry policy (see https://issues.apache.org/jira/browse/CURATOR-559). This utility works around that by using an internal ThreadLocal to hold a retry loop. E.g. if the retry loop fails anywhere in the chain of nested calls it will fail for the rest of the nested calls instead.
Example usage:
ThreadLocalRetryLoop threadLocalRetryLoop = new ThreadLocalRetryLoop(); RetryLoop retryLoop = threadLocalRetryLoop.getRetryLoop(client::newRetryLoop); try { while ( retryLoop.shouldContinue() ) { try { // do work retryLoop.markComplete(); } catch ( Exception e ) { ThreadUtils.checkInterrupted(e); retryLoop.takeException(e); } } } finally { threadLocalRetryLoop.release(); }
-
-
Constructor Summary
Constructors Constructor Description ThreadLocalRetryLoop()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description RetryLoop
getRetryLoop(java.util.function.Supplier<RetryLoop> newRetryLoopSupplier)
Call to get the current retry loop.void
release()
Must be called to release the retry loop.
-
-
-
Method Detail
-
getRetryLoop
public RetryLoop getRetryLoop(java.util.function.Supplier<RetryLoop> newRetryLoopSupplier)
Call to get the current retry loop. If there isn't one, one is allocated vianewRetryLoopSupplier
.- Parameters:
newRetryLoopSupplier
- supply a new retry loop when needed. Normally you should useCuratorZookeeperClient.newRetryLoop()
- Returns:
- retry loop to use
-
release
public void release()
Must be called to release the retry loop. SeeStandardConnectionHandlingPolicy.callWithRetry(org.apache.curator.CuratorZookeeperClient, java.util.concurrent.Callable)
for an example usage.
-
-