|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectus.ihmc.utilities.thread.InterruptableWorker
public abstract class InterruptableWorker
Title:
InterruptableThreadDescription:
This class is designed to be a pattern for threads that need to be interruptable (usually time limited). It also manages the tracking the state during operations.
Nested Class Summary | |
---|---|
static class |
InterruptableWorker.STATE
|
Constructor Summary | |
---|---|
InterruptableWorker()
|
Method Summary | |
---|---|
abstract InterruptableWorker.STATE |
doWork()
This method needs to be overridden and should perform the actual work It should periodically chech the isInterrupted method to know if it should stop. |
abstract java.lang.Object |
getCurrentResult()
This method needs to be overridden and should be used by the application to get the current result while waiting as well as get the final result once finished |
InterruptableWorker.STATE |
getCurrentState()
This method returns the current state |
boolean |
isInterrupted()
This method should be used by the InterruptableWorker to check if it has been interrupted It returns true when stop has been called and stays true until reset |
boolean |
isWorkingOrPendingInterruption()
|
void |
reset()
This method should be overridden, but should call this method as the first step. |
void |
run()
|
void |
setCurrentState(InterruptableWorker.STATE state)
|
void |
startWorkOnANewThread()
This is the normal thread run method called on start It tells the worker to start and tracks the resulting state The worker should return the appropriate finish state: SUCCESSFULLY_COMPLETED UNSUCCESSFULLY_COMPLETED INTERRUPTED |
void |
startWorkOnThisThread()
|
void |
stopWork()
This method is used to signal the worker to stop and then wait until worker finishes to return |
void |
waitForResult(long timeout)
This method should be used by the application to block until work is finished It will block until the timeout and interrupt the worker if not finished in time It does not guarentee the timeout period because it will depend on how long it takes the worker to finish after being told to stop. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public InterruptableWorker()
Method Detail |
---|
public abstract InterruptableWorker.STATE doWork()
public abstract java.lang.Object getCurrentResult()
public void reset()
public InterruptableWorker.STATE getCurrentState()
public void startWorkOnANewThread()
public void startWorkOnThisThread()
public void run()
run
in interface java.lang.Runnable
public void setCurrentState(InterruptableWorker.STATE state)
public void stopWork()
public void waitForResult(long timeout)
timeout
- long in millisecondspublic boolean isInterrupted()
public boolean isWorkingOrPendingInterruption()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |