Interface DelayStrategy

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 DelayStrategy
Encapsulates the logic of determining a delay when some criteria is met.
Author:
Randall Hauch
  • Method Summary

    Modifier and Type
    Method
    Description
    Create a delay strategy that applies a constant delay as long as the criteria is met.
    exponential(Duration initialDelay, Duration maxDelay)
    Create a delay strategy that applies an exponentially-increasing delay as long as the criteria is met.
    exponential(Duration initialDelay, Duration maxDelay, double backOffMultiplier)
    Create a delay strategy that applies an exponentially-increasing delay as long as the criteria is met.
    Create a delay strategy that applies an linearly-increasing delay as long as the criteria is met.
    Create a delay strategy that never delays.
    boolean
    sleepWhen(boolean criteria)
    Attempt to sleep when the specified criteria is met.
    default boolean
    Attempt to sleep when the specified criteria is met.
  • Method Details

    • sleepWhen

      default boolean sleepWhen(BooleanSupplier criteria)
      Attempt to sleep when the specified criteria is met.
      Parameters:
      criteria - true if this method should sleep, or false if there is no need to sleep
      Returns:
      true if this invocation caused the thread to sleep, or false if this method did not sleep
    • sleepWhen

      boolean sleepWhen(boolean criteria)
      Attempt to sleep when the specified criteria is met.
      Parameters:
      criteria - true if this method should sleep, or false if there is no need to sleep
      Returns:
      true if this invocation caused the thread to sleep, or false if this method did not sleep
    • none

      static DelayStrategy none()
      Create a delay strategy that never delays.
      Returns:
      the strategy; never null
    • constant

      static DelayStrategy constant(Duration delay)
      Create a delay strategy that applies a constant delay as long as the criteria is met. As soon as the criteria is not met, the delay resets to zero.
      Parameters:
      delay - the initial delay; must be positive
      Returns:
      the strategy; never null
    • linear

      static DelayStrategy linear(Duration delay)
      Create a delay strategy that applies an linearly-increasing delay as long as the criteria is met. As soon as the criteria is not met, the delay resets to zero.
      Parameters:
      delay - the initial delay; must be positive
      Returns:
      the strategy; never null
    • exponential

      static DelayStrategy exponential(Duration initialDelay, Duration maxDelay)
      Create a delay strategy that applies an exponentially-increasing delay as long as the criteria is met. As soon as the criteria is not met, the delay resets to zero.
      Parameters:
      initialDelay - the initial delay; must be positive
      maxDelay - the maximum delay; must be greater than the initial delay
      Returns:
      the strategy; never null
    • exponential

      static DelayStrategy exponential(Duration initialDelay, Duration maxDelay, double backOffMultiplier)
      Create a delay strategy that applies an exponentially-increasing delay as long as the criteria is met. As soon as the criteria is not met, the delay resets to zero.
      Parameters:
      initialDelay - the initial delay; must be positive
      maxDelay - the maximum delay; must be greater than the initial delay
      backOffMultiplier - the factor by which the delay increases each pass
      Returns:
      the strategy