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 Summary
Modifier and TypeMethodDescription@NonNull DurationdelayAfterFailedAttempt(@NonNull Integer failedAttemptNumber, @NonNull DatabaseException failure) Determines how long to wait after a failed attempt before the next retry.static @NonNull RetryPolicy.Backoffexponential(@NonNull Duration initialDelay, @NonNull Duration maxDelay) Creates an exponential backoff.static @NonNull RetryPolicy.BackoffCreates a fixed backoff.
-
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 failedfailure- the database failure that caused the transaction attempt to fail- Returns:
- delay before the next retry
-
fixed
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 returnsinitialDelay * 2, failed attempt 3 returnsinitialDelay * 4, and so on until the delay reachesmaxDelay. Arithmetic overflow saturates atmaxDelay.- Parameters:
initialDelay- initial delaymaxDelay- maximum delay- Returns:
- an exponential backoff
-