Class CancellableSleep


  • public class CancellableSleep
    extends java.lang.Object
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean sleep​(long duration, java.util.function.Supplier<java.lang.Boolean> cancelCondition, long checkIntervalMs, java.lang.String invocationContext)
      Sleeps for a maximum of duration milliseconds, checking every checkIntervalMs milliseconds whether the cancelCondition is met, and cancelling the sleeping if so.
      static boolean sleep​(long duration, java.util.function.Supplier<java.lang.Boolean> cancelCondition, java.lang.Class<?> invokingClass)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • DEFAULT_CHECK_INTERVAL_MS

        public static final long DEFAULT_CHECK_INTERVAL_MS
        See Also:
        Constant Field Values
    • Method Detail

      • sleep

        public static boolean sleep​(long duration,
                                    java.util.function.Supplier<java.lang.Boolean> cancelCondition,
                                    java.lang.Class<?> invokingClass)
      • sleep

        public static boolean sleep​(long duration,
                                    java.util.function.Supplier<java.lang.Boolean> cancelCondition,
                                    long checkIntervalMs,
                                    java.lang.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.