Class RetryStrategies
java.lang.Object
software.amazon.lambda.durable.retry.RetryStrategies
Factory class for creating common retry strategies.
This class provides preset retry strategies for common use cases, as well as factory methods for creating custom retry strategies with exponential or linear backoff and jitter.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classPreset retry strategies for common use cases. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic RetryStrategyexponentialBackoff(int maxAttempts, Duration initialDelay, Duration maxDelay, double backoffRate, JitterStrategy jitter) Creates an exponential backoff retry strategy.static RetryStrategyexponentialBackoff(int maxAttempts, Duration initialDelay, Duration maxDelay, double backoffRate, JitterStrategy jitter, int pauseEvery) Creates an exponential backoff retry strategy that pauses everypauseEvery-th failed attempt.static RetryStrategyfixedDelay(int maxAttempts, Duration fixedDelay) Creates a simple retry strategy that retries a fixed number of times with a fixed delay.static RetryStrategyfixedDelay(int maxAttempts, Duration fixedDelay, int pauseEvery) Creates a fixed-delay retry strategy that pauses everypauseEvery-th failed attempt.static RetryStrategylinearBackoff(int maxAttempts, Duration initialDelay, Duration increment) Creates a linear backoff retry strategy.static RetryStrategylinearBackoff(int maxAttempts, Duration initialDelay, Duration increment, int pauseEvery) Creates a linear backoff retry strategy that pauses everypauseEvery-th failed attempt.static RetryStrategylinearBackoff(int maxAttempts, Duration initialDelay, Duration maxDelay, Duration increment, JitterStrategy jitter) Creates a linear backoff retry strategy.static RetryStrategylinearBackoff(int maxAttempts, Duration initialDelay, Duration maxDelay, Duration increment, JitterStrategy jitter, int pauseEvery) Creates a linear backoff retry strategy with jitter that pauses everypauseEvery-th failed attempt.
-
Constructor Details
-
RetryStrategies
public RetryStrategies()
-
-
Method Details
-
exponentialBackoff
public static RetryStrategy exponentialBackoff(int maxAttempts, Duration initialDelay, Duration maxDelay, double backoffRate, JitterStrategy jitter) Creates an exponential backoff retry strategy.The delay calculation follows the formula: baseDelay = min(initialDelay × backoffRate^(attempt-1), maxDelay)
- Parameters:
maxAttempts- Maximum number of attempts (including initial attempt)initialDelay- Initial delay before first retrymaxDelay- Maximum delay between retriesbackoffRate- Multiplier for exponential backoffjitter- Jitter strategy to apply to delays- Returns:
- RetryStrategy implementing exponential backoff with jitter
-
exponentialBackoff
@Experimental public static RetryStrategy exponentialBackoff(int maxAttempts, Duration initialDelay, Duration maxDelay, double backoffRate, JitterStrategy jitter, int pauseEvery) Creates an exponential backoff retry strategy that pauses everypauseEvery-th failed attempt.The pause uses the delay and jitter of this strategy. Attempts that do not pause keep the same delay.
- Parameters:
maxAttempts- Maximum number of attempts (including initial attempt)initialDelay- Initial delay before first retrymaxDelay- Maximum delay between retriesbackoffRate- Multiplier for exponential backoffjitter- Jitter strategy to apply to delayspauseEvery- pause on attempts divisible by this value; 0 or negative never pauses- Returns:
- RetryStrategy implementing exponential backoff with jitter and pause
-
linearBackoff
public static RetryStrategy linearBackoff(int maxAttempts, Duration initialDelay, Duration increment) Creates a linear backoff retry strategy.The delay calculation follows the formula: delay = initialDelay + increment × (attempt-1)
- Parameters:
maxAttempts- Maximum number of attempts (including initial attempt)initialDelay- Initial delay before first retryincrement- Amount to add to the delay after each retry attempt- Returns:
- RetryStrategy implementing linear backoff
-
linearBackoff
@Experimental public static RetryStrategy linearBackoff(int maxAttempts, Duration initialDelay, Duration increment, int pauseEvery) Creates a linear backoff retry strategy that pauses everypauseEvery-th failed attempt.- Parameters:
maxAttempts- Maximum number of attempts (including initial attempt)initialDelay- Initial delay before first retryincrement- Amount to add to the delay after each retry attemptpauseEvery- pause on attempts divisible by this value; 0 or negative never pauses- Returns:
- RetryStrategy implementing linear backoff with pause
-
linearBackoff
public static RetryStrategy linearBackoff(int maxAttempts, Duration initialDelay, Duration maxDelay, Duration increment, JitterStrategy jitter) Creates a linear backoff retry strategy.The delay calculation follows the formula: baseDelay = min(initialDelay + increment × (attempt-1), maxDelay)
- Parameters:
maxAttempts- Maximum number of attempts (including initial attempt)initialDelay- Initial delay before first retrymaxDelay- Maximum delay between retriesincrement- Amount to add to the delay after each retry attemptjitter- Jitter strategy to apply to delays- Returns:
- RetryStrategy implementing linear backoff with jitter
-
linearBackoff
@Experimental public static RetryStrategy linearBackoff(int maxAttempts, Duration initialDelay, Duration maxDelay, Duration increment, JitterStrategy jitter, int pauseEvery) Creates a linear backoff retry strategy with jitter that pauses everypauseEvery-th failed attempt.- Parameters:
maxAttempts- Maximum number of attempts (including initial attempt)initialDelay- Initial delay before first retrymaxDelay- Maximum delay between retriesincrement- Amount to add to the delay after each retry attemptjitter- Jitter strategy to apply to delayspauseEvery- pause on attempts divisible by this value; 0 or negative never pauses- Returns:
- RetryStrategy implementing linear backoff with jitter and pause
-
fixedDelay
Creates a simple retry strategy that retries a fixed number of times with a fixed delay.- Parameters:
maxAttempts- Maximum number of attempts (including initial attempt)fixedDelay- Fixed delay between retries- Returns:
- RetryStrategy with fixed delay
-
fixedDelay
@Experimental public static RetryStrategy fixedDelay(int maxAttempts, Duration fixedDelay, int pauseEvery) Creates a fixed-delay retry strategy that pauses everypauseEvery-th failed attempt.- Parameters:
maxAttempts- Maximum number of attempts (including initial attempt)fixedDelay- Fixed delay between retriespauseEvery- pause on attempts divisible by this value; 0 or negative never pauses- Returns:
- RetryStrategy with fixed delay and pause
-