Top Inners Constructors Methods
org.keycloak.common.util

public Class Retry

extends Object
Class Inheritance
Imports
java.time.Duration, java.util.Random

Author
Stian Thorgersen

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
Retry.AdvancedRunnable

Runnable, which provides some additional info (iteration for now)

public static interface
Retry.Supplier<T>

Needed here because: - java.util.function.Supplier defined from Java 8 - Adds some additional info (current iteration)

public static interface
Retry.ThrowableCallback

Needed here because: - java.util.function.BiConsumer defined from Java 8 - Adds some additional info (current iteration and called throwable

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static <T> T

Returns:

Value generated by the supplier.
call
(Retry.Supplier<T> supplier, int
Total number of attempts to execute the runnable
attemptsCount
,
long intervalMillis)

Runs the given runnable at most attemptsCount times until it passes, leaving intervalMillis milliseconds between the invocations.

private static int
computeBackoffInterval(int base, int iteration)

private static int
computeIterationBase(int base, int iteration)

public static int

Returns:

Index of the first successful invocation, starting from 0.
execute
(Runnable runnable, int
Total number of attempts to execute the runnable
attemptsCount
,
long intervalMillis)

Runs the given runnable at most attemptsCount times until it passes, leaving intervalMillis milliseconds between the invocations.

public static int

Returns:

Index of the first successful invocation, starting from 0.
executeWithBackoff
(Retry.AdvancedRunnable runnable, int
Total number of attempts to execute the runnable
attemptsCount
,
int
base for the exponential backoff + jitter
intervalBaseMillis
)

Runs the given runnable at most attemptsCount times until it passes, leaving some increasing random delay milliseconds between the invocations.

public static int
executeWithBackoff(Retry.AdvancedRunnable runnable, Retry.ThrowableCallback throwableCallback, int attemptsCount, int intervalBaseMillis)

public static int
executeWithBackoff(Retry.AdvancedRunnable runnable, Duration timeout, int intervalBaseMillis)

public static int
executeWithBackoff(Retry.AdvancedRunnable runnable, Retry.ThrowableCallback throwableCallback, Duration timeout, int intervalBaseMillis)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

Retryback to summary
public Retry()

Method Detail

callback to summary
public static <T> T call(Retry.Supplier<T> supplier, int attemptsCount, long intervalMillis)

Runs the given runnable at most attemptsCount times until it passes, leaving intervalMillis milliseconds between the invocations. The runnable is reexecuted if it throws a RuntimeException or AssertionError.

Parameters
attemptsCount:int

Total number of attempts to execute the runnable

Returns:T

Value generated by the supplier.

computeBackoffIntervalback to summary
private static int computeBackoffInterval(int base, int iteration)
computeIterationBaseback to summary
private static int computeIterationBase(int base, int iteration)
executeback to summary
public static int execute(Runnable runnable, int attemptsCount, long intervalMillis)

Runs the given runnable at most attemptsCount times until it passes, leaving intervalMillis milliseconds between the invocations. The runnable is reexecuted if it throws a RuntimeException or AssertionError.

Parameters
attemptsCount:int

Total number of attempts to execute the runnable

Returns:int

Index of the first successful invocation, starting from 0.

executeWithBackoffback to summary
public static int executeWithBackoff(Retry.AdvancedRunnable runnable, int attemptsCount, int intervalBaseMillis)

Runs the given runnable at most attemptsCount times 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 by intervalBaseMillis number. The runnable is reexecuted if it throws a RuntimeException or AssertionError.

Parameters
attemptsCount:int

Total number of attempts to execute the runnable

intervalBaseMillis:int

base for the exponential backoff + jitter

Returns:int

Index of the first successful invocation, starting from 0.

executeWithBackoffback to summary
public static int executeWithBackoff(Retry.AdvancedRunnable runnable, Retry.ThrowableCallback throwableCallback, int attemptsCount, int intervalBaseMillis)
executeWithBackoffback to summary
public static int executeWithBackoff(Retry.AdvancedRunnable runnable, Duration timeout, int intervalBaseMillis)
executeWithBackoffback to summary
public static int executeWithBackoff(Retry.AdvancedRunnable runnable, Retry.ThrowableCallback throwableCallback, Duration timeout, int intervalBaseMillis)
org.keycloak.common.util back to summary

public Interface Retry.AdvancedRunnable


Runnable, which provides some additional info (iteration for now)

Method Summary

Modifier and TypeMethod and Description
public void
run(int iteration)

Method Detail

runback to summary
public void run(int iteration)
org.keycloak.common.util back to summary

public Interface Retry.Supplier<T>


Needed here because: - java.util.function.Supplier defined from Java 8 - Adds some additional info (current iteration)

Method Summary

Modifier and TypeMethod and Description
public T

Returns:

a result
get
(int iteration)

Gets a result.

Method Detail

getback to summary
public T get(int iteration)

Gets a result.

Returns:T

a result

org.keycloak.common.util back to summary

public Interface Retry.ThrowableCallback


Needed here because: - java.util.function.BiConsumer defined from Java 8 - Adds some additional info (current iteration and called throwable

Method Summary

Modifier and TypeMethod and Description
public void
handleThrowable(int iteration, Throwable t)

Method Detail

handleThrowableback to summary
public void handleThrowable(int iteration, Throwable t)