Package io.bytestreams.exchange.core
Interface BackoffStrategy
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Strategy for computing the delay between retry attempts.
Strategies are composable via decorator methods:
BackoffStrategy strategy = BackoffStrategy.exponential(Duration.ofMillis(100))
.withMax(Duration.ofSeconds(30))
.withJitter(0.5);
-
Method Summary
Modifier and TypeMethodDescriptiondelay(int attempt) Computes the delay before the given attempt.static BackoffStrategyexponential(Duration baseDelay) Returns a strategy that doubles the base delay on each attempt:baseDelay * 2^(attempt - 1).static BackoffStrategyReturns a strategy that always returns the same delay.default BackoffStrategywithJitter(double factor) Wraps this strategy, adding random jitter up tofactor * delay.default BackoffStrategyWraps this strategy, capping the delay at the given maximum.
-
Method Details
-
delay
Computes the delay before the given attempt.- Parameters:
attempt- the 1-based attempt number- Returns:
- the delay (must not be negative)
-
fixed
Returns a strategy that always returns the same delay.- Parameters:
delay- the fixed delay- Returns:
- a fixed-delay backoff strategy
-
exponential
Returns a strategy that doubles the base delay on each attempt:baseDelay * 2^(attempt - 1).- Parameters:
baseDelay- the delay for the first attempt- Returns:
- an exponential backoff strategy
-
withMax
Wraps this strategy, capping the delay at the given maximum.- Parameters:
max- the maximum delay- Returns:
- a capped backoff strategy
-
withJitter
Wraps this strategy, adding random jitter up tofactor * delay.- Parameters:
factor- the jitter factor (0.0 = no jitter, 1.0 = up to 100% of the delay)- Returns:
- a jittered backoff strategy
-