- 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 TaskContexttaskContext
-
Constructor Summary
Constructors Constructor Description AbstractTask()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description booleancancel()Cancels this task to prevent it from executing.booleancue()Schedules this task to execute as a sequential process.booleanisCued()Returnstrueif the task is currently scheduled for execution.abstract voidrunTask()Executes this sequential process.voidsetTaskContext(TaskContext taskContext)Sets the context used to managed thisTask.Stagestage()Returns the executionStageto which this task is bound.TaskContexttaskContext()Returns the context used to managed thisTask.voidtaskDidCancel()Lifecycle callback invoked after thisTaskis explicitly cancelled.booleantaskWillBlock()Returnstrueif thisTaskmight block its thread of execution when running; returnsfalseif thisTaskwill never block.voidtaskWillCue()Lifecycle callback invoked before thisTaskis scheduled for execution.
-
-
-
Field Detail
-
taskContext
protected TaskContext taskContext
-
-
Method Detail
-
taskContext
public final TaskContext taskContext()
Description copied from interface:Task- Specified by:
taskContextin interfaceTask
-
setTaskContext
public void setTaskContext(TaskContext taskContext)
Description copied from interface:TaskSets the context used to managed thisTask. ATaskContextis assigned when binding thisTaskto aStage.- Specified by:
setTaskContextin interfaceTask
-
runTask
public abstract void runTask()
Description copied from interface:TaskExecutes this sequential process. Only one thread at a time will executerunTaskfor thisTask.- Specified by:
runTaskin interfaceTask- Specified by:
runTaskin interfaceTaskFunction
-
taskWillBlock
public boolean taskWillBlock()
Description copied from interface:TaskReturnstrueif thisTaskmight block its thread of execution when running; returnsfalseif thisTaskwill never block. Used by the executionStageto prevent thread starvation when concurrently running many blocking tasks.- Specified by:
taskWillBlockin interfaceTask
-
taskWillCue
public void taskWillCue()
Description copied from interface:TaskLifecycle callback invoked before thisTaskis scheduled for execution.- Specified by:
taskWillCuein interfaceTask
-
taskDidCancel
public void taskDidCancel()
Description copied from interface:TaskLifecycle callback invoked after thisTaskis explicitly cancelled.- Specified by:
taskDidCancelin interfaceTask
-
stage
public Stage stage()
Returns the executionStageto which this task is bound. Delegates to the assignedtaskContext.- Throws:
TaskException- iftaskContextisnull.
-
isCued
public boolean isCued()
Returnstrueif 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. Returnstrueif this operation caused the scheduling of this task; returnsfalseif 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- iftaskContextisnull.
-
cancel
public boolean cancel()
Cancels this task to prevent it from executing. Returnstrueif this operation caused the cancellation of this task; returnsfalseif this task was not scheduled to execute. Delegates to the assignedtaskContext.
-
-