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
TaskEvent
s. May be null, in which case no events are
reported.public void waitFor() throws InterruptedException, ExecutionException
Task
waitFor
in interface Task
InterruptedException
- if the task is interrupted.ExecutionException
- if the task throws an exception while running.public boolean isDone()
Task
public String getStatusMessage()
Task
getStatusMessage
in interface Task
public long getProgressValue()
Task
getProgressValue
in interface Task
Task.getProgressMaximum()
inclusive.Task.getProgressMaximum()
public long getProgressMaximum()
Task
getProgressMaximum
in interface Task
Task.getProgressValue()
public void setStatusMessage(String status)
Task
setStatusMessage
in interface Task
status
- The message to set.Task.getStatusMessage()
public void setProgressValue(long step)
Task
setProgressValue
in interface Task
step
- The step vaule to set.Task.getProgressValue()
public void setProgressMaximum(long max)
Task
setProgressMaximum
in interface Task
max
- The step count to set.Task.getProgressMaximum()
public boolean isCanceled()
Cancelable
isCanceled
in interface Cancelable
public 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 Cancelable
reason
- A message describing why the operation is being canceled.public String getCancelReason()
Cancelable
getCancelReason
in interface Cancelable
public String getName()
Named
Copyright © 2015–2022 SciJava. All rights reserved.