public class DefaultTask extends Object implements Task
Task. It launches code via the linked
ThreadService, and reports status updates via the linked
EventService.| Constructor and Description |
|---|
DefaultTask(ThreadService threadService,
EventService eventService)
Creates a new task.
|
| Modifier and Type | Method and Description |
|---|---|
void |
cancel(String reason)
Cancels the operation execution, with the given reason for doing so.
|
String |
getCancelReason()
Gets a message describing why the operation was canceled.
|
String |
getName()
Gets the name of the object.
|
long |
getProgressMaximum()
Gets the number of steps the task performs in total.
|
long |
getProgressValue()
Gets the step the task is currently performing.
|
String |
getStatusMessage()
Gets a status message describing what the task is currently doing.
|
boolean |
isCanceled()
Gets whether the operation has been canceled.
|
boolean |
isDone()
Checks whether the task has completed.
|
void |
run(Runnable r)
Starts running the task.
|
void |
setName(String name)
Sets the name of the object.
|
void |
setProgressMaximum(long max)
Sets the total number of steps.
|
void |
setProgressValue(long step)
Sets the current step.
|
void |
setStatusMessage(String status)
Sets the status message.
|
void |
waitFor()
Waits for the task to complete.
|
public DefaultTask(ThreadService threadService, EventService eventService)
threadService - Service to use for launching the task in its own
thread. Required.eventService - Service to use for reporting status updates as
TaskEvents. May be null, in which case no events are
reported.public void waitFor()
throws InterruptedException,
ExecutionException
TaskwaitFor in interface TaskInterruptedException - if the task is interrupted.ExecutionException - if the task throws an exception while running.public boolean isDone()
Taskpublic String getStatusMessage()
TaskgetStatusMessage in interface Taskpublic long getProgressValue()
TaskgetProgressValue in interface TaskTask.getProgressMaximum() inclusive.Task.getProgressMaximum()public long getProgressMaximum()
TaskgetProgressMaximum in interface TaskTask.getProgressValue()public void setStatusMessage(String status)
TasksetStatusMessage in interface Taskstatus - The message to set.Task.getStatusMessage()public void setProgressValue(long step)
TasksetProgressValue in interface Taskstep - The step vaule to set.Task.getProgressValue()public void setProgressMaximum(long max)
TasksetProgressMaximum in interface Taskmax - The step count to set.Task.getProgressMaximum()public boolean isCanceled()
CancelableisCanceled in interface Cancelablepublic void cancel(String reason)
Cancelable
This method merely sets the operation status to canceled; it cannot
necessarily stop the operation itself. That is, it is the responsibility of
each individual operation to check Cancelable.isCanceled() in a timely manner
during execution, and stop doing whatever it is doing if the flag has been
tripped.
cancel in interface Cancelablereason - A message describing why the operation is being canceled.public String getCancelReason()
CancelablegetCancelReason in interface Cancelablepublic String getName()
NamedCopyright © 2009–2018 SciJava. All rights reserved.