Interface BackoffStrategy
-
- All Known Implementing Classes:
ExponentialDelayWithHalfJitter,ExponentialDelayWithJitter,ExponentialDelayWithoutJitter,FixedDelayWithJitter,FixedDelayWithoutJitter,Immediately
@SdkPublicApi @ThreadSafe public interface BackoffStrategy
Determines how long to wait before each execution attempt.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description DurationcomputeDelay(int attempt)Compute the amount of time to wait before the provided attempt number is executed.static BackoffStrategyexponentialDelay(Duration baseDelay, Duration maxDelay)Wait for a random period of time between 0ms and an exponentially increasing amount of time between each subsequent attempt of the same call.static BackoffStrategyexponentialDelayHalfJitter(Duration baseDelay, Duration maxDelay)Wait for a random period of time with an upper bound of exponentially increasing amount of time between each subsequent attempt of the same call and a lower bound of half the amount of the computed exponential delay.static BackoffStrategyexponentialDelayWithoutJitter(Duration baseDelay, Duration maxDelay)Wait for an exponentially increasing amount of time between each subsequent attempt of the same call.static BackoffStrategyfixedDelay(Duration delay)Wait for a random period of time between 0ms and the provided delay.static BackoffStrategyfixedDelayWithoutJitter(Duration delay)Wait for a period of time equal to the provided delay.static BackoffStrategyretryImmediately()Do not back off: retry immediately.
-
-
-
Method Detail
-
computeDelay
Duration computeDelay(int attempt)
Compute the amount of time to wait before the provided attempt number is executed.- Parameters:
attempt- The attempt to compute the delay for, starting at one.- Throws:
IllegalArgumentException- If the given attempt is less or equal to zero.
-
retryImmediately
static BackoffStrategy retryImmediately()
Do not back off: retry immediately.
-
fixedDelay
static BackoffStrategy fixedDelay(Duration delay)
Wait for a random period of time between 0ms and the provided delay.
-
fixedDelayWithoutJitter
static BackoffStrategy fixedDelayWithoutJitter(Duration delay)
Wait for a period of time equal to the provided delay.
-
exponentialDelay
static BackoffStrategy exponentialDelay(Duration baseDelay, Duration maxDelay)
Wait for a random period of time between 0ms and an exponentially increasing amount of time between each subsequent attempt of the same call.Specifically, the first attempt waits 0ms, and each subsequent attempt waits between 0ms and
min(maxDelay, baseDelay * (1 << (attempt - 2))).
-
exponentialDelayHalfJitter
static BackoffStrategy exponentialDelayHalfJitter(Duration baseDelay, Duration maxDelay)
Wait for a random period of time with an upper bound of exponentially increasing amount of time between each subsequent attempt of the same call and a lower bound of half the amount of the computed exponential delay.Specifically, the first attempt waits 0ms, and each subsequent attempt waits between
min(maxDelay, baseDelay * (1 << (attempt - 2))) / 2andmin(maxDelay, baseDelay * (1 << (attempt - 2))) + 1.
-
exponentialDelayWithoutJitter
static BackoffStrategy exponentialDelayWithoutJitter(Duration baseDelay, Duration maxDelay)
Wait for an exponentially increasing amount of time between each subsequent attempt of the same call.Specifically, the first attempt waits 0ms, and each subsequent attempt waits for
min(maxDelay, baseDelay * (1 << (attempt - 2))).
-
-