java.lang.Object
swim.concurrent.AbstractTask
- All Implemented Interfaces:
Task
,TaskFunction
Skeletal implementation of a stateful
Task
.-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
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()
Returns the executionStage
to which this task is bound.final TaskContext
Returns the context used to managed thisTask
.void
Lifecycle callback invoked after thisTask
is explicitly cancelled.boolean
Returnstrue
if thisTask
might block its thread of execution when running; returnsfalse
if thisTask
will never block.void
Lifecycle callback invoked before thisTask
is scheduled for execution.
-
Field Details
-
taskContext
-
-
Constructor Details
-
AbstractTask
public AbstractTask()
-
-
Method Details
-
taskContext
Description copied from interface:Task
- Specified by:
taskContext
in interfaceTask
-
setTaskContext
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
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
.
-