Class TimedOperationVerifier

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

public class TimedOperationVerifier extends Object
Enforce time-outs on operations and throw OperationTimedOutException. Same as Watchdog.
  • Field Details

    • DEFAULT

      public static final TimedOperationVerifier DEFAULT
      Default verifier checking only the current thread's interruption status.
  • Constructor Details

    • TimedOperationVerifier

      public TimedOperationVerifier(long t0, long maxExecTime)
      Create a verifier.
      Parameters:
      t0 - epoch-relative timestamp in ms
      maxExecTime - max allowed execution time in ms; 0 means no limit
    • TimedOperationVerifier

      public TimedOperationVerifier(long maxExecTime)
      Create a verifier whose start time is the current time.
      Parameters:
      maxExecTime - max allowed execution time in ms; 0 means no limit
    • TimedOperationVerifier

      public TimedOperationVerifier()
      Create a verifier with no time limit.
  • Method Details

    • getInitTime

      public long getInitTime()
      Get the verifier'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(TimedOperationVerifier o)
      Verify an operation using the provided verifier or DEFAULT.
      Parameters:
      o - verifier to use, or null to use DEFAULT
      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