Class Watchdog
java.lang.Object
com.pnfsoftware.jeb.util.concurrent.Watchdog
Enforce time-outs on operations and throw
OperationTimedOutException. Same as
TimedOperationVerifier.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionlongGet the watchdog's start time.longGet the maximum allowed execution time.static voidReport an interruption as an operation timeout.voidverify()Verify that the current thread has not been interrupted and the timeout has not elapsed.static voidVerify an operation using the provided watchdog or the default watchdog.static voidVerify that the current thread has not been interrupted.
-
Constructor Details
-
Watchdog
public Watchdog(long t0, long maxExecTime) Create a watchdog.- Parameters:
t0- epoch-relative timestamp in millisecondsmaxExecTime- 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
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
Report an interruption as an operation timeout.- Parameters:
e- interruption to wrap- Throws:
OperationTimedOutException- always thrown
-