Class RetryPolicy

java.lang.Object
net.jodah.lyra.internal.RecurringPolicy<RetryPolicy>
net.jodah.lyra.config.RetryPolicy

public class RetryPolicy
extends net.jodah.lyra.internal.RecurringPolicy<RetryPolicy>
Policy that defines how retries should be performed.
  • Constructor Summary

    Constructors 
    Constructor Description
    RetryPolicy()
    Creates a retry policy that retries forever.
  • Method Summary

    Modifier and Type Method Description
    boolean allowsAttempts()
    Returns whether the policy allows any attempts based on the configured maxAttempts and maxDuration.
    Duration getInterval()
    Returns the interval between attempts.
    int getIntervalMultiplier()
    Returns the interval multiplier for backoff attempts.
    int getMaxAttempts()
    Returns the max attempts.
    Duration getMaxDuration()
    Returns the max duration to perform attempts for.
    Duration getMaxInterval()
    Returns the max interval between backoff attempts.
    RetryPolicy withBackoff​(Duration interval, Duration maxInterval)
    Sets the interval to pause for between attempts, exponentially backing of to the maxInterval multiplying successive intervals by a factor of 2.
    RetryPolicy withBackoff​(Duration interval, Duration maxInterval, int intervalMultiplier)
    Sets the interval to pause for between attempts, exponentially backing of to the maxInterval multiplying successive intervals by the intervalMultiplier.
    RetryPolicy withInterval​(Duration interval)
    Sets the interval to pause for between attempts.
    RetryPolicy withMaxAttempts​(int maxAttempts)
    Sets the max number of attempts to perform.
    RetryPolicy withMaxDuration​(Duration maxDuration)
    Sets the max duration to perform attempts for.

    Methods inherited from class java.lang.Object

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

    • RetryPolicy

      public RetryPolicy()
      Creates a retry policy that retries forever.
  • Method Details

    • allowsAttempts

      public boolean allowsAttempts()
      Returns whether the policy allows any attempts based on the configured maxAttempts and maxDuration.
      Overrides:
      allowsAttempts in class net.jodah.lyra.internal.RecurringPolicy<RetryPolicy>
    • getInterval

      public Duration getInterval()
      Returns the interval between attempts.
      Overrides:
      getInterval in class net.jodah.lyra.internal.RecurringPolicy<RetryPolicy>
      See Also:
      withInterval(Duration), withBackoff(Duration, Duration), withBackoff(Duration, Duration, int)
    • getIntervalMultiplier

      public int getIntervalMultiplier()
      Returns the interval multiplier for backoff attempts.
      Overrides:
      getIntervalMultiplier in class net.jodah.lyra.internal.RecurringPolicy<RetryPolicy>
      See Also:
      withBackoff(Duration, Duration, int)
    • getMaxAttempts

      public int getMaxAttempts()
      Returns the max attempts.
      Overrides:
      getMaxAttempts in class net.jodah.lyra.internal.RecurringPolicy<RetryPolicy>
      See Also:
      withMaxAttempts(int)
    • getMaxDuration

      public Duration getMaxDuration()
      Returns the max duration to perform attempts for.
      Overrides:
      getMaxDuration in class net.jodah.lyra.internal.RecurringPolicy<RetryPolicy>
      See Also:
      withMaxDuration(Duration)
    • getMaxInterval

      public Duration getMaxInterval()
      Returns the max interval between backoff attempts.
      Overrides:
      getMaxInterval in class net.jodah.lyra.internal.RecurringPolicy<RetryPolicy>
      See Also:
      withBackoff(Duration, Duration)
    • withBackoff

      public RetryPolicy withBackoff​(Duration interval, Duration maxInterval)
      Sets the interval to pause for between attempts, exponentially backing of to the maxInterval multiplying successive intervals by a factor of 2.
      Overrides:
      withBackoff in class net.jodah.lyra.internal.RecurringPolicy<RetryPolicy>
      Throws:
      java.lang.NullPointerException - if interval or maxInterval are null
      java.lang.IllegalArgumentException - if interval is <= 0 or interval is >= maxInterval
    • withBackoff

      public RetryPolicy withBackoff​(Duration interval, Duration maxInterval, int intervalMultiplier)
      Sets the interval to pause for between attempts, exponentially backing of to the maxInterval multiplying successive intervals by the intervalMultiplier.
      Overrides:
      withBackoff in class net.jodah.lyra.internal.RecurringPolicy<RetryPolicy>
      Throws:
      java.lang.NullPointerException - if interval or maxInterval are null
      java.lang.IllegalArgumentException - if interval is <= 0, interval is >= maxInterval or the intervalMultiplier is <= 1
    • withInterval

      public RetryPolicy withInterval​(Duration interval)
      Sets the interval to pause for between attempts.
      Overrides:
      withInterval in class net.jodah.lyra.internal.RecurringPolicy<RetryPolicy>
      Throws:
      java.lang.NullPointerException - if interval is null
      java.lang.IllegalStateException - if backoff intervals have already been set via withBackoff(Duration, Duration) or withBackoff(Duration, Duration, int)
    • withMaxAttempts

      public RetryPolicy withMaxAttempts​(int maxAttempts)
      Sets the max number of attempts to perform. -1 indicates to always attempt.
      Overrides:
      withMaxAttempts in class net.jodah.lyra.internal.RecurringPolicy<RetryPolicy>
    • withMaxDuration

      public RetryPolicy withMaxDuration​(Duration maxDuration)
      Sets the max duration to perform attempts for.
      Overrides:
      withMaxDuration in class net.jodah.lyra.internal.RecurringPolicy<RetryPolicy>
      Throws:
      java.lang.NullPointerException - if maxDuration is null