|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectorg.oddjob.state.StateHandler<S>
public class StateHandler<S extends State>
Helps Jobs handle state change.
Attempted to make waitToWhen(StateCondition, Runnable) and
{@link #tryToWhen(StateCondition, Runnable) both use timeouts. This
now required interrupt handling and the tryLock was intermittently
interrupted. The cause of this could not be found so attempting to
implement timeouts was abandoned for the time being.
| Constructor Summary | |
|---|---|
StateHandler(Stateful source,
S readyState)
Constructor. |
|
| Method Summary | ||
|---|---|---|
void |
addStateListener(StateListener listener)
Add a job state listener. |
|
void |
assertAlive()
Convenience method to check the job hasn't been destroyed. |
|
void |
assertLockHeld()
|
|
|
callLocked(Callable<T> callable)
Runs the Callable locked. |
|
void |
fireEvent()
Fire the event, update last event. |
|
State |
getState()
Return the current state of the job. |
|
StateEvent |
lastStateEvent()
Get the last event. |
|
int |
listenerCount()
The number of listeners. |
|
void |
removeStateListener(StateListener listener)
Remove a job state listener. |
|
void |
restoreLastJobStateEvent(StateEvent savedEvent)
Typically only called after restoring a jobstate handler after deserialisation. |
|
void |
setState(S state)
|
|
void |
setState(S state,
Date date)
|
|
void |
setStateException(State state,
Throwable ex)
|
|
void |
setStateException(S state,
Throwable t,
Date date)
|
|
void |
sleep(long time)
Sleep. |
|
String |
toString()
Override toString. |
|
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. |
|
void |
wake()
Wake any threads that are sleeping via sleep(long). |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public StateHandler(Stateful source,
S readyState)
source - The source for events.readyState - The ready state.| Method Detail |
|---|
public StateEvent lastStateEvent()
lastStateEvent in interface Statefulpublic void restoreLastJobStateEvent(StateEvent savedEvent)
source -
public void setState(S state,
Date date)
throws JobDestroyedException
JobDestroyedException
public void setState(S state)
throws JobDestroyedException
JobDestroyedException
public void setStateException(S state,
Throwable t,
Date date)
throws JobDestroyedException
JobDestroyedException
public void setStateException(State state,
Throwable ex)
throws JobDestroyedException
JobDestroyedExceptionpublic State getState()
public void assertAlive()
throws JobDestroyedException
JobDestroyedException - If it has.public void assertLockHeld()
public boolean tryToWhen(StateCondition when,
Runnable runnable)
throws OddjobLockedException
StateLockOddjobLockedException
is thrown.
tryToWhen in interface StateLockwhen - The condition.runnable - The action.
OddjobLockedException - If the lock can not be acquired.
public boolean waitToWhen(StateCondition when,
Runnable runnable)
StateLock
waitToWhen in interface StateLockwhen - The condition.runnable - The action.
public <T> T callLocked(Callable<T> callable)
callable - The callable.
public void sleep(long time)
throws InterruptedException
time -
InterruptedExceptionpublic void wake()
sleep(long).
public void addStateListener(StateListener listener)
throws JobDestroyedException
addStateListener in interface Statefullistener - The listener.
JobDestroyedExceptionpublic void removeStateListener(StateListener listener)
removeStateListener in interface Statefullistener - The listener.public int listenerCount()
public String toString()
toString in class Objectpublic void fireEvent()
event - The event.
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||