Class StagedTaskRunner<C>

java.lang.Object
privbot.task.StagedTaskRunner<C>
Type Parameters:
C - context type

public final class StagedTaskRunner<C> extends Object
Runs TaskNodes in AutomationStage order. Each tick, the first stage (in enum declaration order) that has at least one valid node executes exactly one node — the highest-priority valid node within that stage.

Later stages are skipped once a node runs. If no node runs in any stage, the tick is idle (same as TaskNodeRunner when nothing validates).

See Also:
  • Constructor Details

    • StagedTaskRunner

      public StagedTaskRunner(Supplier<C> contextSupplier)
      Parameters:
      contextSupplier - supplies the shared context each tick
    • StagedTaskRunner

      public StagedTaskRunner(Supplier<C> contextSupplier, BooleanSupplier runnableCheck)
      Parameters:
      contextSupplier - supplies the shared context each tick
      runnableCheck - when it returns false, tick() does nothing
  • Method Details

    • addNode

      public void addNode(AutomationStage stage, TaskNode<C> node)
      Registers a node for a stage. Nodes in the same stage compete by TaskNode.getPriority() (higher wins).
    • removeNode

      public void removeNode(String name)
      Removes every node with this name, from every stage.
    • getNodes

      public List<TaskNode<C>> getNodes()
      An unmodifiable snapshot of all nodes, in stage order then registration order.
    • getActiveNode

      public TaskNode<C> getActiveNode()
      The node that ran on the last tick, or null when that tick was idle.
    • getLastActiveStage

      public AutomationStage getLastActiveStage()
      The stage of getActiveNode(), or null when the last tick was idle.
    • getNodeCount

      public int getNodeCount()
      The number of registered nodes across all stages.
    • initialize

      public void initialize()
      Clears active state and execution statistics. Does not reset nodes.
    • shutdown

      public void shutdown()
      Calls TaskNode.cleanup() on every node. Unlike TaskNodeRunner.shutdown() there is no worker to stop, and a node whose cleanup throws stops the loop.
    • tick

      public boolean tick()
      Runs one tick: the highest-priority valid node of the first stage that has one executes.

      Threading: selection and execution both run on the calling thread, with no ReadScope and no forced-move hold check. Call it from a script worker if nodes sleep, and make sure their predicates may read from that thread.

      Returns:
      true if the selected node performed a blocking action
    • getActiveTaskName

      public String getActiveTaskName()
      The name of the node that ran on the last tick, or null when idle.
    • getActiveTaskStatus

      public String getActiveTaskStatus()
      That node's status after it ran, or "Idle".
    • didLastTickBlock

      public boolean didLastTickBlock()
      The last executed node's return value; false on an idle tick.
    • getExecutionTimes

      public Map<String,Long> getExecutionTimes()
      Node name to its last execution time in milliseconds (unmodifiable view).
    • getExecutionCounts

      public Map<String,Long> getExecutionCounts()
      Node name to how many times it executed (unmodifiable view).
    • getTotalTicks

      public long getTotalTicks()
      Ticks processed since initialize(), idle ticks included.
    • getNodeStats

      public String getNodeStats()
      A multi-line report of every node with its stage, priority and execution statistics.
    • reset

      public void reset()
      Resets every node and clears active state; statistics are kept.
    • clearNodes

      public void clearNodes()
      Removes every registered node.