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 attempt.
Implementations should be thread-safe if the RetryPolicy is shared across threads.
- Since:
- 4.4.0
- Author:
- Mark Allen
-
Method Summary
Modifier and TypeMethodDescriptiondelayAfterFailedAttempt(@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.static @NonNull RetryPolicy.BackofffullJitter(@NonNull RetryPolicy.Backoff delegate) Randomizes a delegate's delay uniformly at nanosecond resolution from zero (inclusive) to its cap (exclusive).
-
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 attempt to fail- Returns:
- delay before the next retry
-
fixed
Creates a fixed backoff.- Parameters:
delay- delay before every retry- Returns:
- a fixed backoff
-
fullJitter
Randomizes a delegate's delay uniformly at nanosecond resolution from zero (inclusive) to its cap (exclusive). A zero cap remains zero. This is useful for spreading simultaneous retries across clients. The delegate must return a non-null, nonnegative duration and be thread-safe when shared.- Parameters:
delegate- backoff supplying the delay cap- Returns:
- a backoff with full jitter
- Since:
- 4.8.0
-
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
-