Package org.keycloak.common.util
Class Retry
- java.lang.Object
- 
- org.keycloak.common.util.Retry
 
- 
 public class Retry extends Object - Author:
- Stian Thorgersen
 
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static interfaceRetry.AdvancedRunnableRunnable, which provides some additional info (iteration for now)static interfaceRetry.Supplier<T>Needed here because: - java.util.function.Supplier defined from Java 8 - Adds some additional info (current iteration)static interfaceRetry.ThrowableCallbackNeeded here because: - java.util.function.BiConsumer defined from Java 8 - Adds some additional info (current iteration and called throwable
 - 
Constructor SummaryConstructors Constructor Description Retry()
 - 
Method SummaryAll Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> Tcall(Retry.Supplier<T> supplier, int attemptsCount, long intervalMillis)Runs the givenrunnableat mostattemptsCounttimes until it passes, leavingintervalMillismilliseconds between the invocations.static intexecute(Runnable runnable, int attemptsCount, long intervalMillis)Runs the givenrunnableat mostattemptsCounttimes until it passes, leavingintervalMillismilliseconds between the invocations.static intexecuteWithBackoff(Retry.AdvancedRunnable runnable, int attemptsCount, int intervalBaseMillis)Runs the givenrunnableat mostattemptsCounttimes until it passes, leaving some increasing random delay milliseconds between the invocations.static intexecuteWithBackoff(Retry.AdvancedRunnable runnable, Duration timeout, int intervalBaseMillis)static intexecuteWithBackoff(Retry.AdvancedRunnable runnable, Retry.ThrowableCallback throwableCallback, int attemptsCount, int intervalBaseMillis)static intexecuteWithBackoff(Retry.AdvancedRunnable runnable, Retry.ThrowableCallback throwableCallback, Duration timeout, int intervalBaseMillis)
 
- 
- 
- 
Method Detail- 
executepublic static int execute(Runnable runnable, int attemptsCount, long intervalMillis) Runs the givenrunnableat mostattemptsCounttimes until it passes, leavingintervalMillismilliseconds between the invocations. The runnable is reexecuted if it throws aRuntimeExceptionorAssertionError.- Parameters:
- runnable-
- attemptsCount- Total number of attempts to execute the- runnable
- intervalMillis-
- Returns:
- Index of the first successful invocation, starting from 0.
 
 - 
executeWithBackoffpublic static int executeWithBackoff(Retry.AdvancedRunnable runnable, int attemptsCount, int intervalBaseMillis) Runs the givenrunnableat mostattemptsCounttimes until it passes, leaving some increasing random delay milliseconds between the invocations. It uses Exponential backoff + jitter algorithm to compute the delay. More details https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/ The base for delay is specified byintervalBaseMillisnumber. The runnable is reexecuted if it throws aRuntimeExceptionorAssertionError.- Parameters:
- runnable-
- attemptsCount- Total number of attempts to execute the- runnable
- intervalBaseMillis- base for the exponential backoff + jitter
- Returns:
- Index of the first successful invocation, starting from 0.
 
 - 
executeWithBackoffpublic static int executeWithBackoff(Retry.AdvancedRunnable runnable, Retry.ThrowableCallback throwableCallback, int attemptsCount, int intervalBaseMillis) 
 - 
executeWithBackoffpublic static int executeWithBackoff(Retry.AdvancedRunnable runnable, Duration timeout, int intervalBaseMillis) 
 - 
executeWithBackoffpublic static int executeWithBackoff(Retry.AdvancedRunnable runnable, Retry.ThrowableCallback throwableCallback, Duration timeout, int intervalBaseMillis) 
 - 
callpublic static <T> T call(Retry.Supplier<T> supplier, int attemptsCount, long intervalMillis) Runs the givenrunnableat mostattemptsCounttimes until it passes, leavingintervalMillismilliseconds between the invocations. The runnable is reexecuted if it throws aRuntimeExceptionorAssertionError.- Parameters:
- supplier-
- attemptsCount- Total number of attempts to execute the- runnable
- intervalMillis-
- Returns:
- Value generated by the supplier.
 
 
- 
 
-