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 TypeMethodDescriptionbooleancancel()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.stage()Returns the executionStageto which this task is bound.final TaskContextReturns the context used to managed thisTask.voidLifecycle callback invoked after thisTaskis explicitly cancelled.booleanReturnstrueif thisTaskmight block its thread of execution when running; returnsfalseif thisTaskwill never block.voidLifecycle callback invoked before thisTaskis scheduled for execution.
-
Field Details
-
taskContext
-
-
Constructor Details
-
AbstractTask
public AbstractTask()
-
-
Method Details
-
taskContext
Description copied from interface:Task- Specified by:
taskContextin interfaceTask
-
setTaskContext
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
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.
-