Class RetryStrategies

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

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

  • 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 retry
      maxDelay - Maximum delay between retries
      backoffRate - Multiplier for exponential backoff
      jitter - 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 every pauseEvery-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 retry
      maxDelay - Maximum delay between retries
      backoffRate - Multiplier for exponential backoff
      jitter - Jitter strategy to apply to delays
      pauseEvery - 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 retry
      increment - 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 every pauseEvery-th failed attempt.
      Parameters:
      maxAttempts - Maximum number of attempts (including initial attempt)
      initialDelay - Initial delay before first retry
      increment - Amount to add to the delay after each retry attempt
      pauseEvery - 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 retry
      maxDelay - Maximum delay between retries
      increment - Amount to add to the delay after each retry attempt
      jitter - 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 every pauseEvery-th failed attempt.
      Parameters:
      maxAttempts - Maximum number of attempts (including initial attempt)
      initialDelay - Initial delay before first retry
      maxDelay - Maximum delay between retries
      increment - Amount to add to the delay after each retry attempt
      jitter - Jitter strategy to apply to delays
      pauseEvery - pause on attempts divisible by this value; 0 or negative never pauses
      Returns:
      RetryStrategy implementing linear backoff with jitter and pause
    • fixedDelay

      public static RetryStrategy fixedDelay(int maxAttempts, Duration 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 every pauseEvery-th failed attempt.
      Parameters:
      maxAttempts - Maximum number of attempts (including initial attempt)
      fixedDelay - Fixed delay between retries
      pauseEvery - pause on attempts divisible by this value; 0 or negative never pauses
      Returns:
      RetryStrategy with fixed delay and pause