Interface Task

All Superinterfaces:
TaskFunction
All Known Implementing Classes:
AbstractTask, AgentModel, AgentNode, MetaEdgeAgent, MetaHostAgent, MetaLaneAgent, MetaMeshAgent, MetaPartAgent

public interface Task extends TaskFunction
Stateful TaskFunction to invoke as a sequential process on a concurrent execution Stage, with lifecycle callbacks, and a TaskContext for self-management. Use Stage.task(TaskFunction) to bind a new Task to a Stage, and invoke TaskRef.cue() to schedule the concurrent execution of the sequential task.

Blocking

Task implementations should not perform long running or blocking operations, if possible. If a Task does need to block, it should return true from taskWillBlock() to avoid thread starvation of the execution Stage.
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Executes this sequential process.
    void
    Sets the context used to managed this Task.
    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.
  • Method Details

    • taskContext

      TaskContext taskContext()
      Returns the context used to managed this Task. Returns null if this Task is not bound to a Stage.
    • setTaskContext

      void setTaskContext(TaskContext taskContext)
      Sets the context used to managed this Task. A TaskContext is assigned when binding this Task to a Stage.
    • runTask

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

      boolean taskWillBlock()
      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.
    • taskWillCue

      void taskWillCue()
      Lifecycle callback invoked before this Task is scheduled for execution.
    • taskDidCancel

      void taskDidCancel()
      Lifecycle callback invoked after this Task is explicitly cancelled.