org.oddjob.state
Interface StateLock

All Known Implementing Classes:
JobStateHandler, ParentStateHandler, ServiceStateHandler, StateHandler

public interface StateLock

A mechanism for allowing actions to be performed synchronously with respect to state change.

Author:
rob

Method Summary
 boolean tryToWhen(StateCondition when, Runnable runnable)
          Try to acquire the lock, and then do something when the condition is true.
 boolean waitToWhen(StateCondition when, Runnable runnable)
          Wait to do something when the condition is true.
 

Method Detail

tryToWhen

boolean tryToWhen(StateCondition when,
                  Runnable runnable)
                  throws OddjobLockedException
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 an OddjobLockedException is 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

boolean waitToWhen(StateCondition when,
                   Runnable runnable)
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.