Class WaitStrategies
java.lang.Object
software.amazon.lambda.durable.retry.WaitStrategies
Factory class for creating common
WaitForConditionWaitStrategy implementations.
This class provides preset wait strategies (for use with waitForCondition) for common use cases, as well as factory methods for creating custom retry strategies with exponential backoff and jitter.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classPreset wait strategies for common use cases. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> WaitForConditionWaitStrategy<T>Returns the default wait strategy.static <T> WaitForConditionWaitStrategy<T>exponentialBackoff(int maxAttempts, Duration initialDelay, Duration maxDelay, double backoffRate, JitterStrategy jitter) Creates an exponential backoff wait strategy.static <T> WaitForConditionWaitStrategy<T>fixedDelay(int maxAttempts, Duration fixedDelay) Creates a fixed delay wait strategy that returns a constant delay regardless of attempt number or state.
-
Constructor Details
-
WaitStrategies
public WaitStrategies()
-
-
Method Details
-
defaultStrategy
Returns the default wait strategy.- Type Parameters:
T- the type of state being polled- Returns:
- the default wait strategy
-
exponentialBackoff
public static <T> WaitForConditionWaitStrategy<T> exponentialBackoff(int maxAttempts, Duration initialDelay, Duration maxDelay, double backoffRate, JitterStrategy jitter) Creates an exponential backoff wait strategy.The delay calculation follows the formula: baseDelay = min(initialDelay × backoffRate^(attempt-1), maxDelay)
- Type Parameters:
T- the type of state being polled- Parameters:
maxAttempts- maximum number of attempts before throwingWaitForConditionFailedExceptioninitialDelay- initial delay before first retrymaxDelay- maximum delay between retriesbackoffRate- multiplier for exponential backoff (must be >= 1.0)jitter- jitter strategy to apply to delays- Returns:
- a
WaitForConditionWaitStrategyimplementing exponential backoff with jitter
-
fixedDelay
Creates a fixed delay wait strategy that returns a constant delay regardless of attempt number or state.- Type Parameters:
T- the type of state being polled- Parameters:
maxAttempts- maximum number of attempts before throwingWaitForConditionFailedExceptionfixedDelay- the constant delay between polling attempts- Returns:
- a
WaitForConditionWaitStrategywith fixed delay
-