- java.lang.Object
-
- swim.concurrent.AbstractTask
-
- All Implemented Interfaces:
Task
,TaskFunction
public abstract class AbstractTask extends Object implements Task
Skeletal implementation of a statefulTask
.
-
-
Field Summary
Fields Modifier and Type Field Description protected TaskContext
taskContext
-
Constructor Summary
Constructors Constructor Description AbstractTask()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description boolean
cancel()
Cancels this task to prevent it from executing.boolean
cue()
Schedules this task to execute as a sequential process.boolean
isCued()
Returnstrue
if the task is currently scheduled for execution.abstract void
runTask()
Executes this sequential process.void
setTaskContext(TaskContext taskContext)
Sets the context used to managed thisTask
.Stage
stage()
Returns the executionStage
to which this task is bound.TaskContext
taskContext()
Returns the context used to managed thisTask
.void
taskDidCancel()
Lifecycle callback invoked after thisTask
is explicitly cancelled.boolean
taskWillBlock()
Returnstrue
if thisTask
might block its thread of execution when running; returnsfalse
if thisTask
will never block.void
taskWillCue()
Lifecycle callback invoked before thisTask
is scheduled for execution.
-
-
-
Field Detail
-
taskContext
protected TaskContext taskContext
-
-
Method Detail
-
taskContext
public final TaskContext taskContext()
Description copied from interface:Task
- Specified by:
taskContext
in interfaceTask
-
setTaskContext
public void setTaskContext(TaskContext taskContext)
Description copied from interface:Task
Sets the context used to managed thisTask
. ATaskContext
is assigned when binding thisTask
to aStage
.- Specified by:
setTaskContext
in interfaceTask
-
runTask
public abstract void runTask()
Description copied from interface:Task
Executes this sequential process. Only one thread at a time will executerunTask
for thisTask
.- Specified by:
runTask
in interfaceTask
- Specified by:
runTask
in interfaceTaskFunction
-
taskWillBlock
public boolean taskWillBlock()
Description copied from interface:Task
Returnstrue
if thisTask
might block its thread of execution when running; returnsfalse
if thisTask
will never block. Used by the executionStage
to prevent thread starvation when concurrently running many blocking tasks.- Specified by:
taskWillBlock
in interfaceTask
-
taskWillCue
public void taskWillCue()
Description copied from interface:Task
Lifecycle callback invoked before thisTask
is scheduled for execution.- Specified by:
taskWillCue
in interfaceTask
-
taskDidCancel
public void taskDidCancel()
Description copied from interface:Task
Lifecycle callback invoked after thisTask
is explicitly cancelled.- Specified by:
taskDidCancel
in interfaceTask
-
stage
public Stage stage()
Returns the executionStage
to which this task is bound. Delegates to the assignedtaskContext
.- Throws:
TaskException
- iftaskContext
isnull
.
-
isCued
public boolean isCued()
Returnstrue
if the task is currently scheduled for execution. Delegates to the assignedtaskContext
, if set; otherwise returnsfalse
.
-
cue
public boolean cue()
Schedules this task to execute as a sequential process. Returnstrue
if this operation caused the scheduling of this task; returnsfalse
if this task was already scheduled to execute. This task becomes uncued prior to the the invocation ofrunTask()
, enabling this task to re-cue itself while running. Delegates to the assignedtaskContext
.- Throws:
TaskException
- iftaskContext
isnull
.
-
cancel
public boolean cancel()
Cancels this task to prevent it from executing. Returnstrue
if this operation caused the cancellation of this task; returnsfalse
if this task was not scheduled to execute. Delegates to the assignedtaskContext
.
-
-