Package org.oddjob.state
Interface StateLock
- All Known Implementing Classes:
EventStateHandler,JobStateHandler,ParentStateHandler,ServiceStateHandler,StateHandler,TimerStateHandler
public interface StateLock
A mechanism for allowing actions to be performed synchronously
with respect to state change.
- Author:
- rob
-
Method Summary
Modifier and TypeMethodDescription<T> TcallLocked(Callable<T> callable) Wait to acquire the lock and execute the Callable while holding the lock.voidWait to acquire the lock and execute the Runnable while holding the lock.<T> TsupplyLocked(Supplier<T> supplier) Wait to acquire the lock and execute the Supplier while holding the lock.booleantryToWhen(StateCondition when, Runnable runnable) Try to acquire the lock, and then do something when the condition is true.booleanwaitToWhen(StateCondition when, Runnable runnable) Wait to do something when the condition is true.
-
Method Details
-
tryToWhen
Try to acquire the lock, and then do something when the condition is true. Both the condition evaluation and the performing of the action are done in the context of the same state lock. If the lock can not be acquired anOddjobLockedExceptionis thrown.- Parameters:
when- The condition.runnable- The action.- Returns:
- true if the condition was true and the action executed. False otherwise.
- Throws:
OddjobLockedException- If the lock can not be acquired.
-
waitToWhen
Wait to do something when the condition is true. Both the condition evaluation and the performing of the action are done in the context of the same state lock. If the lock can not be acquired then the lock is waited for.- Parameters:
when- The condition.runnable- The action.- Returns:
- true if the condition was true and the action executed.
-
runLocked
Wait to acquire the lock and execute the Runnable while holding the lock.- Parameters:
runnable- The Runnable.
-
callLocked
Wait to acquire the lock and execute the Callable while holding the lock.- Parameters:
callable- The callable.- Returns:
- The result of the callable.
- Throws:
Exception- from the callable.
-
supplyLocked
Wait to acquire the lock and execute the Supplier while holding the lock.- Parameters:
supplier- The Supplier.- Returns:
- The result from the Supplier.
-