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

      All Methods Static Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      static DelayStrategy constant​(long delayInMilliseconds)
      Create a delay strategy that applies a constant delay as long as the criteria is met.
      static DelayStrategy exponential​(long initialDelayInMilliseconds, long maxDelayInMilliseconds)
      Create a delay strategy that applies an exponentially-increasing delay as long as the criteria is met.
      static DelayStrategy exponential​(long initialDelayInMilliseconds, long maxDelayInMilliseconds, double backOffMultiplier)
      Create a delay strategy that applies an exponentially-increasing delay as long as the criteria is met.
      static DelayStrategy linear​(long delayInMilliseconds)
      Create a delay strategy that applies an linearly-increasing delay as long as the criteria is met.
      static DelayStrategy none()
      Create a delay strategy that never delays.
      boolean sleepWhen​(boolean criteria)
      Attempt to sleep when the specified criteria is met.
      default boolean sleepWhen​(BooleanSupplier criteria)
      Attempt to sleep when the specified criteria is met.
    • Method Detail

      • 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​(long delayInMilliseconds)
        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:
        delayInMilliseconds - the initial delay; must be positive
        Returns:
        the strategy; never null
      • linear

        static DelayStrategy linear​(long delayInMilliseconds)
        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:
        delayInMilliseconds - the initial delay; must be positive
        Returns:
        the strategy; never null
      • exponential

        static DelayStrategy exponential​(long initialDelayInMilliseconds,
                                         long maxDelayInMilliseconds)
        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:
        initialDelayInMilliseconds - the initial delay; must be positive
        maxDelayInMilliseconds - the maximum delay; must be greater than the initial delay
        Returns:
        the strategy; never null
      • exponential

        static DelayStrategy exponential​(long initialDelayInMilliseconds,
                                         long maxDelayInMilliseconds,
                                         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:
        initialDelayInMilliseconds - the initial delay; must be positive
        maxDelayInMilliseconds - the maximum delay; must be greater than the initial delay
        backOffMultiplier - the factor by which the delay increases each pass
        Returns:
        the strategy