Interface IntervalFunction

All Superinterfaces:
Serializable
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface
public interface IntervalFunction
extends Serializable
Function that computes the wait time necessary for each subsequent retry attempt. The input is the sequence number of the attempt (1 = first failed attempt, 2 = second failed attempt and so on), the output is the wait time in milliseconds.
Since:
4.3
  • Method Summary

    Modifier and Type Method Description
    static IntervalFunction constant​(long intervalMs)
    Creates an IntervalFunction which returns a fixed interval in milliseconds.
    static IntervalFunction exponentialBackoff​(long intervalMillis, double multiplier)
    Creates an IntervalFunction which starts from the specified wait interval, on the first attempt, and for each subsequent attempt uses a longer interval, equal to the previous wait duration multiplied by the provided scaling factor (so for example: 1, 2, 4, 8, ...).
    static IntervalFunction exponentialBackoffWithCap​(long intervalMillis, double multiplier, long capMillis)
    Creates an IntervalFunction which starts from the specified wait interval, on the first attempt, and for each subsequent attempt uses a longer interval, equal to the previous wait duration multiplied by the provided scaling factor (so for example: 1, 2, 4, 8, ...).
    long waitAfterAttempt​(int attempt)
    Returns the wait time required before the specified attempt.
  • Method Details

    • constant

      static IntervalFunction constant​(long intervalMs)
      Creates an IntervalFunction which returns a fixed interval in milliseconds.
    • exponentialBackoff

      static IntervalFunction exponentialBackoff​(long intervalMillis, double multiplier)
      Creates an IntervalFunction which starts from the specified wait interval, on the first attempt, and for each subsequent attempt uses a longer interval, equal to the previous wait duration multiplied by the provided scaling factor (so for example: 1, 2, 4, 8, ...).
    • exponentialBackoffWithCap

      static IntervalFunction exponentialBackoffWithCap​(long intervalMillis, double multiplier, long capMillis)
      Creates an IntervalFunction which starts from the specified wait interval, on the first attempt, and for each subsequent attempt uses a longer interval, equal to the previous wait duration multiplied by the provided scaling factor (so for example: 1, 2, 4, 8, ...). The wait interval increases only until a certain maximum value, ie. is capped. All subsequent wait intervals returned will be equal to the cap.
    • waitAfterAttempt

      long waitAfterAttempt​(int attempt)
      Returns the wait time required before the specified attempt. In this context attempt no. 1 means the first attempt, so it's not an index and zero is not an allowed input.