Class CancellableSleep

java.lang.Object
step.artefacts.handlers.CancellableSleep

public class CancellableSleep extends Object
  • Field Details

    • DEFAULT_CHECK_INTERVAL_MS

      public static final long DEFAULT_CHECK_INTERVAL_MS
      See Also:
  • Method Details

    • sleep

      public static boolean sleep(long duration, Supplier<Boolean> cancelCondition, Class<?> invokingClass)
    • sleep

      public static boolean sleep(long duration, Supplier<Boolean> cancelCondition, long checkIntervalMs, String invocationContext)
      Sleeps for a maximum of duration milliseconds, checking every checkIntervalMs milliseconds whether the cancelCondition is met, and cancelling the sleeping if so.
      Parameters:
      duration - number of milliseconds to sleep
      cancelCondition - method which is invoked to verify if execution is to be cancelled. This method is invoked often, and in time-sensitive code, so it should return quickly.
      checkIntervalMs - number of milliseconds between cancellation checks. A lower limit of 10 ms is enforced, but higher values (say, >= 100 ms) are strongly recommended.
      invocationContext - indication of the context where the method invocation originated. Only used for logging, and may be null.
      Returns:
      true if the entire sleep went through without being cancelled, false if it was cancelled.