Class TimedOperationVerifier
java.lang.Object
com.pnfsoftware.jeb.util.concurrent.TimedOperationVerifier
Enforce time-outs on operations and throw
OperationTimedOutException. Same as
Watchdog.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final TimedOperationVerifierDefault verifier checking only the current thread's interruption status. -
Constructor Summary
ConstructorsConstructorDescriptionCreate a verifier with no time limit.TimedOperationVerifier(long maxExecTime) Create a verifier whose start time is the current time.TimedOperationVerifier(long t0, long maxExecTime) Create a verifier. -
Method Summary
Modifier and TypeMethodDescriptionlongGet the verifier'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 verifier orDEFAULT.static voidVerify that the current thread has not been interrupted.
-
Field Details
-
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 msmaxExecTime- 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
Verify an operation using the provided verifier orDEFAULT.- Parameters:
o- verifier to use, or null to useDEFAULT- 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
-