Class LinearBlockHoppingScanner

All Implemented Interfaces:
Iterable<FlowNode>, Iterator<FlowNode>, Filterator<FlowNode>

@NotThreadSafe public class LinearBlockHoppingScanner extends LinearScanner
Extension of LinearScanner that skips nested blocks at the current level, useful for finding enclosing blocks. ONLY use this with nodes inside the flow graph, never the last node of a completed flow (it will jump over the whole flow).

This is useful where you only care about FlowNodes that precede this one or are part of an enclosing scope (within a Block).

Specifically:

  • Where a BlockEndNode is encountered, the scanner will jump to the BlockStartNode and go to its first parent.
  • The only case where you visit branches of a parallel block is if you begin inside it.

Specific use cases:

  • Finding out the executor workspace used to run a FlowNode
  • Finding the start of the parallel block enclosing the current node
  • Locating the label applying to a given FlowNode (if any) if using labelled blocks
Author:
Sam Van Oort
  • Constructor Details

    • LinearBlockHoppingScanner

      public LinearBlockHoppingScanner()
  • Method Details

    • setup

      public boolean setup(@CheckForNull Collection<FlowNode> heads, @CheckForNull Collection<FlowNode> blackList)
      Description copied from class: LinearScanner
      Set up for iteration/analysis on a graph of nodes, initializing the internal state Includes null-checking on arguments to allow directly calling with unchecked inputs (simplifies use).
      Overrides:
      setup in class LinearScanner
      Parameters:
      heads - The head nodes we start walking from (the most recently executed nodes, i.e. FlowExecution.getCurrentHeads()
      blackList - Nodes that we cannot visit or walk past (useful to limit scanning to only nodes after a specific point)
      Returns:
      True if we can have nodes to work with, otherwise false
    • setHeads

      protected void setHeads(@NonNull Collection<FlowNode> heads)
      Description copied from class: LinearScanner
      Set up to begin flow scanning using the filteredHeads as starting points This method makes several assumptions: - AbstractFlowScanner.reset() has already been invoked to reset state - filteredHeads has already had any points in AbstractFlowScanner.myBlackList removed - none of the filteredHeads are null
      Overrides:
      setHeads in class LinearScanner
      Parameters:
      heads - Head nodes that have been filtered against denyList. Do not pass multiple heads.
    • jumpBlockScan

      @CheckForNull protected FlowNode jumpBlockScan(@CheckForNull FlowNode node, @NonNull Collection<FlowNode> blacklistNodes)
      Keeps jumping over blocks until we hit the first node preceding a block
    • next

      protected FlowNode next(@CheckForNull FlowNode current, @NonNull Collection<FlowNode> blackList)
      Description copied from class: AbstractFlowScanner
      Actual meat of the iteration, get the next node to visit, using and updating state as needed
      Overrides:
      next in class LinearScanner
      Parameters:
      current - Current node to use in generating next value
      blackList - Nodes that are not eligible for visiting
      Returns:
      Next node to visit, or null if we've exhausted the node list