|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectewe.sys.TaskObject
A TaskObject is an implementation of a Task that uses an mThread to run asynchronously.
To override a TaskObject you need only override the doRun() method. Within that method you can use the "handle" variable to modify the handle associated with the task. This handle will automatically be set to "Running" before doRun() is called and will be set to "Stopped" when doRun() exits.
| Field Summary | |
protected Handle |
handle
This is the handle used by the TaskObject. |
protected boolean |
interruptThreadToStop
If this is true, then a call to stopTask() will request the running thread to be interrupted. |
protected mThread |
myThread
This is the thread in which the task is running. |
int |
napIterations
Everytime the nap() method is called it calls Coroutine.nap(napIterations,napTime). |
int |
napTime
Everytime the nap() method is called it calls Coroutine.nap(napIterations,napTime). |
boolean |
shouldStop
This will be set true if the stop() method is called. |
| Constructor Summary | |
protected |
TaskObject()
Create a new TaskObject and assign a new Handle to the handle member. |
protected |
TaskObject(Handle h)
Create a new TaskObject using a particular Handle. |
| Method Summary | |
boolean |
checkAbortFail(Handle wasWaitingOn,
boolean stopWaitingOn)
This can be used after a call to waitOn() or waitOnAny() has failed. |
boolean |
checkFailure(boolean resultOfWait,
Handle wasWaitingOn,
boolean stopWaitingOn)
Call this to check on the result of a waitOn() or waitOnAny() and automatically set the Failure or Abort flag of the handle of this task, based on the failure/success of waitOn. |
protected void |
doRun()
Override this method if you want to use an mThread to run your Task. |
protected void |
doStart()
This is called to start the TaskObject running. |
protected void |
doStop(int reason)
This method, by default, sets the shouldStop variable to true. |
Handle |
exec(String title,
Frame parent)
This starts the task and displays a progress bar. |
Handle |
getHandle()
Get the Handle for the TaskObject. |
protected void |
nap()
Nap for the nap time of this task object. |
void |
run()
This calls the doRun() method and then sets the handle flags such that Running is off and Stopped is on after doRun() returns. |
TaskObject |
setNapTime(int napIterations,
int napTime)
Set the napIterations and napTime variables. |
Handle |
show(String title,
Frame parent)
This starts the task and displays a progress bar. |
protected static void |
sleep(int time)
This puts the current mThread thread to sleep. |
ProgressBarForm |
start(String title)
|
Handle |
startTask()
This sets the handle member to the Running state and then calls doStart(). |
Handle |
stopTask(int reason)
Request that the TaskObject stop running. |
boolean |
waitOn(Handle otherHandle,
int flags,
boolean copyProgress)
Wait indefinitely for flags to be set on another handle. |
boolean |
waitOnAny(Handle otherHandle,
int flags,
boolean copyProgress)
Wait indefinitely for any of a set of flags to be set on another handle. |
boolean |
waitOnSuccess(Handle waitFor,
boolean copyProgress)
This calls waitOn(waitFor,Handle.Success,copyProgress) and then calls checkFailure() on it. |
void |
yield()
Yield to another thread or task. |
void |
yield(int everyMilliseconds)
Yield to another thread or task every certain number of milliseconds. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, toString |
| Field Detail |
protected Handle handle
public boolean shouldStop
protected boolean interruptThreadToStop
protected mThread myThread
public int napIterations
public int napTime
| Constructor Detail |
protected TaskObject()
protected TaskObject(Handle h)
| Method Detail |
public Handle startTask()
startTask in interface Taskpublic Handle stopTask(int reason)
stopTask in interface Taskreason - some task specific reason for stopping. There are no pre-defined reasons.
public Handle getHandle()
getHandle in interface Taskprotected void doStart()
If you want to use a different method for Task execution (e.g. Timer ticks or Callbacks) then override this method to start the task running.
protected void doStop(int reason)
You can override this to provide a different method of stopping the task.
reason - some task specific reason for stopping. There are no pre-defined reasons.public final void run()
run in interface Runnableprotected void doRun()
protected static final void sleep(int time)
public TaskObject setNapTime(int napIterations,
int napTime)
napIterations - napTime -
protected void nap()
public ProgressBarForm start(String title)
public Handle exec(String title,
Frame parent)
public Handle show(String title,
Frame parent)
public boolean waitOn(Handle otherHandle,
int flags,
boolean copyProgress)
Only call this from within the TaskObject's thread.
otherHandle - The other handle to wait for.flags - The flags to wait to be set.copyProgress - set this true if you want the progress of the otherHandle to be
reflected in this handle.
public boolean waitOnAny(Handle otherHandle,
int flags,
boolean copyProgress)
Only call this from within the TaskObject's thread.
otherHandle - The other handle to wait for.flags - The flags to wait to be set.copyProgress - set this true if you want the progress of the otherHandle to be
reflected in this handle.
public boolean checkAbortFail(Handle wasWaitingOn,
boolean stopWaitingOn)
Only call this from within the TaskObject's thread.
wasWaitingOn - The Handle that this task was waiting on.stopWaitingOn - If this is true then wasWaitingOn will have its stop() method called.
public boolean checkFailure(boolean resultOfWait,
Handle wasWaitingOn,
boolean stopWaitingOn)
Only call this from within the TaskObject's thread.
resultOfWait - The result of the waitOn() or waitOnAny() call.wasWaitingOn - The hande the task was waiting on.stopWaitingOn - If this is true then the task will be stopped on failure.
public boolean waitOnSuccess(Handle waitFor,
boolean copyProgress)
Only call this from within the TaskObject's thread.
waitFor - The handle to wait for.copyProgress - True if you want this task's handle to reflect the progress of the waitFor handle.
public void yield()
public void yield(int everyMilliseconds)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||