Class AbstractTask

java.lang.Object
swim.concurrent.AbstractTask
All Implemented Interfaces:
Task, TaskFunction

public abstract class AbstractTask extends Object implements Task
Skeletal implementation of a stateful Task.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected TaskContext
    Context used to manage this Task; null if this Task is not bound to an execution Stage.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Cancels this task to prevent it from executing.
    boolean
    cue()
    Schedules this task to execute as a sequential process.
    boolean
    Returns true if the task is currently scheduled for execution.
    abstract void
    Executes this sequential process.
    void
    Sets the context used to managed this Task.
    Returns the execution Stage to which this task is bound.
    Returns the context used to managed this Task.
    void
    Lifecycle callback invoked after this Task is explicitly cancelled.
    boolean
    Returns true if this Task might block its thread of execution when running; returns false if this Task will never block.
    void
    Lifecycle callback invoked before this Task is scheduled for execution.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • taskContext

      protected TaskContext taskContext
      Context used to manage this Task; null if this Task is not bound to an execution Stage.
  • Constructor Details

    • AbstractTask

      public AbstractTask()
  • Method Details

    • taskContext

      public final TaskContext taskContext()
      Description copied from interface: Task
      Returns the context used to managed this Task. Returns null if this Task is not bound to a Stage.
      Specified by:
      taskContext in interface Task
    • setTaskContext

      public void setTaskContext(TaskContext taskContext)
      Description copied from interface: Task
      Sets the context used to managed this Task. A TaskContext is assigned when binding this Task to a Stage.
      Specified by:
      setTaskContext in interface Task
    • runTask

      public abstract void runTask()
      Description copied from interface: Task
      Executes this sequential process. Only one thread at a time will execute runTask for this Task.
      Specified by:
      runTask in interface Task
      Specified by:
      runTask in interface TaskFunction
    • taskWillBlock

      public boolean taskWillBlock()
      Description copied from interface: Task
      Returns true if this Task might block its thread of execution when running; returns false if this Task will never block. Used by the execution Stage to prevent thread starvation when concurrently running many blocking tasks.
      Specified by:
      taskWillBlock in interface Task
    • taskWillCue

      public void taskWillCue()
      Description copied from interface: Task
      Lifecycle callback invoked before this Task is scheduled for execution.
      Specified by:
      taskWillCue in interface Task
    • taskDidCancel

      public void taskDidCancel()
      Description copied from interface: Task
      Lifecycle callback invoked after this Task is explicitly cancelled.
      Specified by:
      taskDidCancel in interface Task
    • stage

      public Stage stage()
      Returns the execution Stage to which this task is bound. Delegates to the assigned taskContext.
      Throws:
      TaskException - if taskContext is null.
    • isCued

      public boolean isCued()
      Returns true if the task is currently scheduled for execution. Delegates to the assigned taskContext, if set; otherwise returns false.
    • cue

      public boolean cue()
      Schedules this task to execute as a sequential process. Returns true if this operation caused the scheduling of this task; returns false if this task was already scheduled to execute. This task becomes uncued prior to the the invocation of runTask(), enabling this task to re-cue itself while running. Delegates to the assigned taskContext.
      Throws:
      TaskException - if taskContext is null.
    • cancel

      public boolean cancel()
      Cancels this task to prevent it from executing. Returns true if this operation caused the cancellation of this task; returns false if this task was not scheduled to execute. Delegates to the assigned taskContext.