Interface TypedGuard.Builder.RetryBuilder<T>

Enclosing interface:
TypedGuard.Builder<T>

public static interface TypedGuard.Builder.RetryBuilder<T>
Configures a retry.
See Also:
  • @Retry
  • Method Details

    • maxRetries

      TypedGuard.Builder.RetryBuilder<T> maxRetries(int value)
      Sets the maximum number of retries. Defaults to 3.
      Parameters:
      value - the maximum number of retries, must be >= -1.
      Returns:
      this retry builder
      See Also:
      • @Retry.maxRetries
    • delay

      TypedGuard.Builder.RetryBuilder<T> delay(long value, ChronoUnit unit)
      Sets the delay between retries. Defaults to 0.
      Parameters:
      value - the delay length, must be >= 0
      unit - the delay unit, must not be null
      Returns:
      this retry builder
      See Also:
      • @Retry.delay
      • @Retry.delayUnit
    • maxDuration

      TypedGuard.Builder.RetryBuilder<T> maxDuration(long value, ChronoUnit unit)
      Sets the maximum duration of all invocations, including possible retries. Defaults to 3 minutes.
      Parameters:
      value - the maximum duration length, must be >= 0
      unit - the maximum duration unit, must not be null
      Returns:
      this retry builder
      See Also:
      • @Retry.maxDuration
      • @Retry.durationUnit
    • jitter

      TypedGuard.Builder.RetryBuilder<T> jitter(long value, ChronoUnit unit)
      Sets the jitter bound. Random value in the range from -jitter to +jitter will be added to the delay between retry attempts. Defaults to 200 millis.
      Parameters:
      value - the jitter bound length, must be >= 0
      unit - the jitter bound unit, must not be null
      Returns:
      this retry builder
      See Also:
      • @Retry.jitter
      • @Retry.jitterDelayUnit
    • retryOn

      Sets the set of exception types considered failure. Defaults to all exceptions (Exception).
      Parameters:
      value - collection of exception types, must not be null
      Returns:
      this retry builder
      See Also:
      • @Retry.retryOn
    • retryOn

      TypedGuard.Builder.RetryBuilder<T> retryOn(Class<? extends Throwable> value)
      Equivalent to retryOn(Set.of(value)).
      Parameters:
      value - an exception class, must not be null
      Returns:
      this retry builder
    • abortOn

      Sets the set of exception types considered success. Defaults to no exception (empty set).
      Parameters:
      value - collection of exception types, must not be null
      Returns:
      this retry builder
      See Also:
      • @Retry.abortOn
    • abortOn

      TypedGuard.Builder.RetryBuilder<T> abortOn(Class<? extends Throwable> value)
      Equivalent to abortOn(Set.of(value)).
      Parameters:
      value - an exception class, must not be null
      Returns:
      this retry builder
    • whenResult

      Sets a predicate to determine when a result should be considered failure and retry should be attempted. All results that do not match this predicate are implicitly considered success.
      Parameters:
      value - the predicate, must not be null
      Returns:
      this retry builder
    • whenException

      Sets a predicate to determine when an exception should be considered failure and retry should be attempted. This is a more general variant of retryOn. Note that there is no generalized abortOn, because all exceptions that do not match this predicate are implicitly considered success.

      If this method is called, retryOn and abortOn may not be called.

      Parameters:
      value - the predicate, must not be null
      Returns:
      this retry builder
      See Also:
    • beforeRetry

      Sets a before retry handler, which is called before each retry, but not before the original attempt.
      Parameters:
      value - the before retry handler, must not be null
      Returns:
      this retry builder
      See Also:
    • beforeRetry

      Sets a before retry handler, which is called before each retry, but not before the original attempt.
      Parameters:
      value - the before retry handler, must not be null
      Returns:
      this retry builder
    • withExponentialBackoff

      Configures retry to use an exponential backoff instead of the default constant backoff.

      Only one backoff strategy may be configured, so calling withFibonacciBackoff() or withCustomBackoff() in addition to this method leads to an exception during done().

      Returns:
      the exponential backoff builder
      See Also:
    • withFibonacciBackoff

      Configures retry to use a Fibonacci backoff instead of the default constant backoff.

      Only one backoff strategy may be configured, so calling withExponentialBackoff() or withCustomBackoff() in addition to this method leads to an exception during done().

      Returns:
      the Fibonacci backoff builder
      See Also:
    • withCustomBackoff

      Configures retry to use a custom backoff instead of the default constant backoff.

      Only one backoff strategy may be configured, so calling withExponentialBackoff() or withFibonacciBackoff() in addition to this method leads to an exception during done().

      Returns:
      the custom backoff builder
      See Also:
    • onRetry

      Sets a callback that will be invoked when a retry is attempted.

      The callback must be fast and non-blocking and must not throw an exception.

      Parameters:
      callback - the retried callback, must not be null
      Returns:
      this retry builder
    • onSuccess

      Sets a callback that will be invoked when this retry strategy treats a finished invocation as success, regardless of whether a retry was attempted or not.

      The callback must be fast and non-blocking and must not throw an exception.

      Parameters:
      callback - the retried callback, must not be null
      Returns:
      this retry builder
    • onFailure

      Sets a callback that will be invoked when this retry strategy treats a finished invocation as failure, and no more retries will be attempted. The failure may be caused by depleting the maximum number of retries or the maximum duration, or by an exception that is not retryable.

      The callback must be fast and non-blocking and must not throw an exception.

      Parameters:
      callback - the retried callback, must not be null
      Returns:
      this retry builder
    • done

      Returns the original fault tolerance builder.
      Returns:
      the original fault tolerance builder
    • with