Class Watchdog

java.lang.Object
com.pnfsoftware.jeb.util.concurrent.Watchdog

@Ser public class Watchdog extends Object
Enforce time-outs on operations and throw OperationTimedOutException. Same as TimedOperationVerifier.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create a watchdog with no time limit.
    Watchdog(long maxExecTime)
    Create a watchdog whose start time is the current time.
    Watchdog(long t0, long maxExecTime)
    Create a watchdog.
  • Method Summary

    Modifier and Type
    Method
    Description
    long
    Get the watchdog's start time.
    long
    Get the maximum allowed execution time.
    static void
    Report an interruption as an operation timeout.
    void
    Verify that the current thread has not been interrupted and the timeout has not elapsed.
    static void
    Verify an operation using the provided watchdog or the default watchdog.
    static void
    Verify that the current thread has not been interrupted.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Watchdog

      public Watchdog(long t0, long maxExecTime)
      Create a watchdog.
      Parameters:
      t0 - epoch-relative timestamp in milliseconds
      maxExecTime - maximum allowed execution time in milliseconds; 0 means no limit
    • Watchdog

      public Watchdog(long maxExecTime)
      Create a watchdog whose start time is the current time.
      Parameters:
      maxExecTime - maximum allowed execution time in milliseconds; 0 means no limit
    • Watchdog

      public Watchdog()
      Create a watchdog with no time limit.
  • Method Details

    • getInitTime

      public long getInitTime()
      Get the watchdog's start time.
      Returns:
      epoch-relative start timestamp, in milliseconds
    • getMaxExecTime

      public long getMaxExecTime()
      Get the maximum allowed execution time.
      Returns:
      maximum execution time in milliseconds; 0 means no limit
    • verify

      public void verify()
      Verify that the current thread has not been interrupted and the timeout has not elapsed.
      Throws:
      OperationTimedOutException - if the current thread is interrupted or the timeout elapsed
    • verify

      public static void verify(Watchdog o)
      Verify an operation using the provided watchdog or the default watchdog.
      Parameters:
      o - watchdog to use, or null to use the default watchdog
      Throws:
      OperationTimedOutException - if the current thread is interrupted or the timeout elapsed
    • verifyInterruptions

      public static void verifyInterruptions()
      Verify that the current thread has not been interrupted.
      Throws:
      OperationTimedOutException - if the current thread is interrupted
    • reportInterruption

      public static void reportInterruption(InterruptedException e)
      Report an interruption as an operation timeout.
      Parameters:
      e - interruption to wrap
      Throws:
      OperationTimedOutException - always thrown