Interface RetryPolicy.Backoff

Enclosing class:
RetryPolicy
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

Determines how long to wait before retrying after a failed transaction attempt.

Implementations should be thread-safe if the RetryPolicy is shared across threads.

Since:
4.4.0
Author:
Mark Allen
  • Method Details

    • delayAfterFailedAttempt

      @NonNull Duration delayAfterFailedAttempt(@NonNull Integer failedAttemptNumber, @NonNull DatabaseException failure)
      Determines how long to wait after a failed attempt before the next retry.
      Parameters:
      failedAttemptNumber - one-based number of the attempt that just failed
      failure - the database failure that caused the transaction attempt to fail
      Returns:
      delay before the next retry
    • fixed

      static @NonNull RetryPolicy.Backoff fixed(@NonNull Duration delay)
      Creates a fixed backoff.
      Parameters:
      delay - delay before every retry
      Returns:
      a fixed backoff
    • exponential

      static @NonNull RetryPolicy.Backoff exponential(@NonNull Duration initialDelay, @NonNull Duration maxDelay)
      Creates an exponential backoff.

      Failed attempt 1 returns initialDelay, failed attempt 2 returns initialDelay * 2, failed attempt 3 returns initialDelay * 4, and so on until the delay reaches maxDelay. Arithmetic overflow saturates at maxDelay.

      Parameters:
      initialDelay - initial delay
      maxDelay - maximum delay
      Returns:
      an exponential backoff