Class Retrier

java.lang.Object
google.registry.util.Retrier
All Implemented Interfaces:
Serializable

public class Retrier extends Object implements Serializable
Wrapper that does retry with exponential backoff.
See Also:
  • Constructor Details

    • Retrier

      @Inject public Retrier(Sleeper sleeper, @Named("transientFailureRetries") int transientFailureRetries)
  • Method Details

    • callWithRetry

      public <V> V callWithRetry(Callable<V> callable, Predicate<Throwable> isRetryable)
      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: