Class JitteredRetryPolicy

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

    
    public final class JitteredRetryPolicy
     implements OutboxRetryPolicy
                        

    Retry policy that adds random jitter to a base retry policy.

    This policy wraps another retry policy and adds random jitter to the delay to help avoid thundering herd problems when multiple instances retry at the same time.

    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) Delegates the retry decision to the base policy.
      Duration nextDelay(Integer retryCount) Calculates the next delay by adding random jitter to the base policy's delay.
      • Methods inherited from class java.lang.Object

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

      • JitteredRetryPolicy

        JitteredRetryPolicy(OutboxRetryPolicy basePolicy, Duration jitter)
        Parameters:
        basePolicy - The underlying retry policy to add jitter to
        jitter - Maximum jitter duration to add
    • Method Detail

      • shouldRetry

         Boolean shouldRetry(Throwable exception)

        Delegates the retry decision to the base policy.

        Parameters:
        exception - The exception that occurred
        Returns:

        True if the base policy says to retry

      • nextDelay

         Duration nextDelay(Integer retryCount)

        Calculates the next delay by adding random jitter to the base policy's delay.

        Parameters:
        retryCount - The current retry count
        Returns:

        Base delay plus random jitter