public interface Task extends Cancelable, Named
run(Runnable), and
can report its progression from within the Runnable.
- A Task object can simply be used to report in a synchronous manner
the progression of a piece of code. In the case of synchronous reporting,
the job is considered started when start() is called and
finished when finish() is called. A finished job can be finished
either because it is done or because it has been cancelled.
A cancel callback can be set with setCancelCallBack(Runnable).
The runnable argument will be executed in the case of an external event
requesting a cancellation of the task - typically, if a user clicks
a cancel button on the GUI, task.cancel("User cancellation requested") will
be called. As a result, the task implementors should run the callback.
This callback can be used to make the task aware that a cancellation
has been requested, and should proceed to stop its execution.
See also TaskService, DefaultTask| Modifier and Type | Method and Description |
|---|---|
default void |
finish()
reports that the task is finished - synchronous job
|
default Runnable |
getCancelCallBack()
Returns the current cancel callback runnable, This can be used to
concatenate callbacks in order, for instance, to ask for a user
confirmation before cancelling the task
|
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 |
isDone()
Checks whether the task has completed.
|
void |
run(Runnable r)
Starts running the task - asynchronous job
|
default void |
setCancelCallBack(Runnable runnable)
If the task is cancelled (external call to
Cancelable.cancel(String)),
the input runnable argument should be executed by task implementors. |
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.
|
default void |
start()
reports that the task is started - synchronous job
|
void |
waitFor()
Waits for the task to complete - asynchronous job
|
cancel, getCancelReason, isCanceledvoid run(Runnable r)
IllegalStateException - if the task was already started.void waitFor()
throws InterruptedException,
ExecutionException
IllegalStateException - if run(java.lang.Runnable) has not been called yet.InterruptedException - if the task is interrupted.ExecutionException - if the task throws an exception while running.default void start()
default void finish()
boolean isDone()
String getStatusMessage()
long getProgressValue()
getProgressMaximum() inclusive.getProgressMaximum()long getProgressMaximum()
getProgressValue()void setStatusMessage(String status)
status - The message to set.getStatusMessage()void setProgressValue(long step)
step - The step vaule to set.getProgressValue()void setProgressMaximum(long max)
max - The step count to set.getProgressMaximum()default void setCancelCallBack(Runnable runnable)
Cancelable.cancel(String)),
the input runnable argument should be executed by task implementors.runnable - : should be executed if this task is cancelled through
Cancelable.cancel(String)default Runnable getCancelCallBack()
Copyright © 2009–2023 SciJava. All rights reserved.