Class WaitStrategies

java.lang.Object
software.amazon.lambda.durable.retry.WaitStrategies

public final class WaitStrategies extends Object
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.

  • Constructor Details

    • WaitStrategies

      public WaitStrategies()
  • Method Details

    • defaultStrategy

      public static <T> WaitForConditionWaitStrategy<T> 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 throwing WaitForConditionFailedException
      initialDelay - initial delay before first retry
      maxDelay - maximum delay between retries
      backoffRate - multiplier for exponential backoff (must be >= 1.0)
      jitter - jitter strategy to apply to delays
      Returns:
      a WaitForConditionWaitStrategy implementing exponential backoff with jitter
    • fixedDelay

      public 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.
      Type Parameters:
      T - the type of state being polled
      Parameters:
      maxAttempts - maximum number of attempts before throwing WaitForConditionFailedException
      fixedDelay - the constant delay between polling attempts
      Returns:
      a WaitForConditionWaitStrategy with fixed delay