|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface Task
This is the interface for a Schmant task. It defines task run control methods and methods to query the task about its state. A task may have the following states:
TaskFactory
or is waiting for its turn to run in a TaskExecutor
.
The task's internal state (is running? has run? canceled?) is
protected by the satisfied state lock defined in TaskDependency
.
(Tasks that inherit AbstractTask
get that for free.)
Some run control methods are inspired by the methods in java.util.concurrent.Future
. This class does not extend Future
,
though, since tasks do not necessarily produce a result.
A Task
object is always created by a task-specific
TaskFactory
. The task factory has setter methods that build scripts
can use to configure the task. The setter methods configure a task-specific
TaskSpecification
object. When the task is configured, the build
script calls TaskFactory.create()
to create a Task
object
based on the configured TaskSpecification
. (In practice, the Task
and the TaskSpecification
objects are the same.)
Task objects are always read only.
Some tasks implement the Producer
interface. When
running one of those tasks, an object is produced that can be retrieved from
the Producer.get()
method.
All methods in this interface are implemented by AbstractTask
. Task
implementations are encouraged to inherit that class (or any of its
subclasses).
A task implementation is responsible for logging all errors (even Error
:s) to its thread's Report
.
Tasks are encouraged to implement a good toString
method since that
is used for error reporting.
Method Summary | |
---|---|
boolean |
cancel(boolean mayInterruptIfRunning)
Cancel a task that has not been run or is running. |
TaskDependency |
getDependencyForTasksScheduledByThisTask()
If this task schedules other tasks in a TaskExecutor ,
this method returns a dependency object that is satisfied when all those
tasks have been run. |
Throwable |
getFailureCause()
If the task failed, this method can be used to retrieve the failure cause. |
boolean |
isCancelled()
Is the task canceled? |
boolean |
isDone()
Has this task been run? |
boolean |
isInterrupted()
Was the task interrupted? |
boolean |
isRunning()
Is the task currently running? |
boolean |
isSuccessful()
Was the task successful? (I.e: did it not throw an exception?) |
Methods inherited from interface org.schmant.run.TaskDependency |
---|
getDependencyObservable, getSatisfiedStateLock, isSatisfied |
Methods inherited from interface org.schmant.task.TaskRunnable |
---|
run |
Method Detail |
---|
boolean isDone()
true
if this task has been run.boolean cancel(boolean mayInterruptIfRunning)
mayInterruptIfRunning
- Should the task be interrupted if it is
running?boolean isCancelled()
true
if the task was canceled.boolean isSuccessful()
true
if the task has been successfully run.boolean isInterrupted()
true
if the task was interrupted.boolean isRunning()
true
if the task has been successfully run.Throwable getFailureCause()
TaskDependency getDependencyForTasksScheduledByThisTask()
TaskExecutor
,
this method returns a dependency object that is satisfied when all those
tasks have been run. If not, the returned dependency object is satisfied
when this task has been run.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |