Class ExponentialBackoffRetryPolicy

  • All Implemented Interfaces:
    io.namastack.outbox.retry.OutboxRetryPolicy

    
    public final class ExponentialBackoffRetryPolicy
     implements OutboxRetryPolicy
                        

    Retry policy that implements exponential backoff with configurable parameters.

    This policy increases the delay between retries exponentially, starting with an initial delay and multiplying by a backoff multiplier for each retry, up to a maximum delay.

    Since:

    0.1.0

    Author:

    Roland Beisel

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      Boolean shouldRetry(Throwable exception) Always returns true, indicating that retries should be attempted.
      Duration nextDelay(Integer retryCount) Calculates the next delay using exponential backoff.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ExponentialBackoffRetryPolicy

        ExponentialBackoffRetryPolicy(Duration initialDelay, Duration maxDelay, Double backoffMultiplier)
        Parameters:
        initialDelay - Initial delay for the first retry
        maxDelay - Maximum delay between retries
        backoffMultiplier - Multiplier for exponential backoff calculation
    • Method Detail

      • shouldRetry

         Boolean shouldRetry(Throwable exception)

        Always returns true, indicating that retries should be attempted.

        Parameters:
        exception - The exception that occurred
        Returns:

        Always true

      • nextDelay

         Duration nextDelay(Integer retryCount)

        Calculates the next delay using exponential backoff.

        The delay is calculated as: initialDelay * (backoffMultiplier ^ retryCount) The result is capped at the maximum delay.

        Parameters:
        retryCount - The current retry count
        Returns:

        Calculated delay duration, capped at maxDelay