Class Retrier
- All Implemented Interfaces:
Serializable
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Holds functions to call whenever the code being retried fails. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfinal void
callWithRetry
(VoidCallable callable, Retrier.FailureReporter failureReporter, Class<? extends Throwable> retryableError, Class<? extends Throwable>... moreRetryableErrors) Retries a unit of work in the face of transient errors, without returning a value.final void
callWithRetry
(VoidCallable callable, Class<? extends Throwable> retryableError, Class<? extends Throwable>... moreRetryableErrors) Retries a unit of work in the face of transient errors, without returning a value.final <V> V
callWithRetry
(Callable<V> callable, Retrier.FailureReporter failureReporter, Class<? extends Throwable> retryableError, Class<? extends Throwable>... moreRetryableErrors) Retries a unit of work in the face of transient errors and returns the result.final <V> V
callWithRetry
(Callable<V> callable, Class<? extends Throwable> retryableError, Class<? extends Throwable>... moreRetryableErrors) Retries a unit of work in the face of transient errors and returns the result.<V> V
callWithRetry
(Callable<V> callable, Predicate<Throwable> isRetryable) Retries a unit of work in the face of transient errors.
-
Constructor Details
-
Retrier
@Inject public Retrier(Sleeper sleeper, @Named("transientFailureRetries") int transientFailureRetries)
-
-
Method Details
-
callWithRetry
Retries a unit of work in the face of transient errors.Retrying is done a fixed number of times, with exponential backoff, if the exception that is thrown is deemed retryable by the predicate. If the error is not considered retryable, or if the thread is interrupted, or if the allowable number of attempts has been exhausted, the original exception is propagated through to the caller. Checked exceptions are wrapped in a RuntimeException, while unchecked exceptions are propagated as-is.
- Returns:
- the value returned by the
Callable
.
-
callWithRetry
@SafeVarargs public final <V> V callWithRetry(Callable<V> callable, Class<? extends Throwable> retryableError, Class<? extends Throwable>... moreRetryableErrors) Retries a unit of work in the face of transient errors and returns the result.Retrying is done a fixed number of times, with exponential backoff, if the exception that is thrown is on an allow list of retryable errors. If the error is not on the allow list, or if the thread is interrupted, or if the allowable number of attempts has been exhausted, the original exception is propagated through to the caller. Checked exceptions are wrapped in a RuntimeException, while unchecked exceptions are propagated as-is.
Uses a default FailureReporter that logs before each retry.
- Returns:
- the value returned by the
Callable
.
-
callWithRetry
@SafeVarargs public final void callWithRetry(VoidCallable callable, Class<? extends Throwable> retryableError, Class<? extends Throwable>... moreRetryableErrors) Retries a unit of work in the face of transient errors, without returning a value.- See Also:
-
callWithRetry
@SafeVarargs public final <V> V callWithRetry(Callable<V> callable, Retrier.FailureReporter failureReporter, Class<? extends Throwable> retryableError, Class<? extends Throwable>... moreRetryableErrors) Retries a unit of work in the face of transient errors and returns the result.Retrying is done a fixed number of times, with exponential backoff, if the exception that is thrown is on an allow list of retryable errors. If the error is not on the allow list, or if the thread is interrupted, or if the allowable number of attempts has been exhausted, the original exception is propagated through to the caller. Checked exceptions are wrapped in a RuntimeException, while unchecked exceptions are propagated as-is.
- Returns:
- the value returned by the
Callable
.
-
callWithRetry
@SafeVarargs public final void callWithRetry(VoidCallable callable, Retrier.FailureReporter failureReporter, Class<? extends Throwable> retryableError, Class<? extends Throwable>... moreRetryableErrors) Retries a unit of work in the face of transient errors, without returning a value.- See Also:
-