Interface SimpleChunkVisitor
- All Known Implementing Classes:
StandardChunkVisitor
A ForkScanner.visitSimpleChunks(SimpleChunkVisitor, ChunkFinder) creates these FlowChunks using a ChunkFinder to define the chunk boundaries.
We walk through the FlowNodes in reverse order from end to start, so end callbacks are invoked before
their corresponding start callbacks.
Callback types
There are two kinds of callbacks - chunk callbacks, and parallel structure callbacks.
Chunk Callbacks:
chunkStart(FlowNode, FlowNode, ForkScanner)- detected the start of a chunk beginning with a nodechunkEnd(FlowNode, FlowNode, ForkScanner)- detected the end of a chunk, terminating with a nodeatomNode(FlowNode, FlowNode, FlowNode, ForkScanner)- most nodes, which aren't boundaries of chunks
Chunk callback rules:
- For a single node, it may have EITHER OR BOTH chunkStart and chunkEnd events
- Every node that doesn't get a startChunk/endChunk callback gets an atomNode callback.
- For
ChunkFinderimplementations that match theBlockStartNodeandBlockEndNodeshould never have both for a single node. - You cannot have multiple of any of the same specific type of callbacks for the same flownode
- You cannot have a atomNode callback AND a start/end for the same flownode (application of the above).
Parallel Structure Callbacks: Zero, One, or (in niche cases) several different ones may be invoked for any given FlowNode.
These are used to provide awareness of parallel/branching structures if they need special handling.
parallelStart(FlowNode, FlowNode, ForkScanner)parallelEnd(FlowNode, FlowNode, ForkScanner)parallelBranchStart(FlowNode, FlowNode, ForkScanner)parallelBranchEnd(FlowNode, FlowNode, ForkScanner)
The cases where a node triggers multiple callbacks are where it is one of several forked branches of an incomplete parallel block. In this case it can be a parallelBranchEnd, also potentially a parallelEnd, plus whatever role that node might normally have (such as the start of another parallel).
Implementations get to decide how to use and handle chunks, and should be stateful.
At a minimum they should handle:
- Cases where there is no enclosing chunk (no start/end found, or outside a chunk)
- Cases where there is no chunk end to match the start, because we haven't finished running a block
- Nesting of chunks
- Author:
- Sam Van Oort
-
Method Summary
Modifier and TypeMethodDescriptionvoidatomNode(FlowNode before, FlowNode atomNode, FlowNode after, ForkScanner scan) Called for a flownode neither start nor end.voidchunkEnd(FlowNode endNode, FlowNode afterChunk, ForkScanner scanner) Called when hitting the end of a chunk.voidchunkStart(FlowNode startNode, FlowNode beforeBlock, ForkScanner scanner) Called when hitting the start of a chunk.voidparallelBranchEnd(FlowNode parallelStartNode, FlowNode branchEndNode, ForkScanner scanner) Hit the end start of a parallel branchvoidparallelBranchStart(FlowNode parallelStartNode, FlowNode branchStartNode, ForkScanner scanner) Hit the start of a parallel branchvoidparallelEnd(FlowNode parallelStartNode, FlowNode parallelEndNode, ForkScanner scanner) Notifies that we've seen the end of a parallel blockvoidparallelStart(FlowNode parallelStartNode, FlowNode branchNode, ForkScanner scanner) Notifies that we've hit the start of a parallel block (the point where it branches out).
-
Method Details
-
chunkStart
void chunkStart(@NonNull FlowNode startNode, @CheckForNull FlowNode beforeBlock, @NonNull ForkScanner scanner) Called when hitting the start of a chunk.- Parameters:
startNode- First node in chunk (marker), included in nodebeforeBlock- First node before chunk (null if none exist)scanner- Forkscanner used (for state tracking)
-
chunkEnd
void chunkEnd(@NonNull FlowNode endNode, @CheckForNull FlowNode afterChunk, @NonNull ForkScanner scanner) Called when hitting the end of a chunk.- Parameters:
endNode- Last node in chunkafterChunk- Node after chunk (null if we are on the last node)scanner- Forkscanner used (for state tracking)
-
parallelStart
void parallelStart(@NonNull FlowNode parallelStartNode, @NonNull FlowNode branchNode, @NonNull ForkScanner scanner) Notifies that we've hit the start of a parallel block (the point where it branches out).- Parameters:
parallelStartNode- TheBlockStartNodebeginning it, next will be branchesbranchNode-BlockStartNodefor one of the branches (it will be labelled)scanner- ForkScanner used
-
parallelEnd
void parallelEnd(@NonNull FlowNode parallelStartNode, @NonNull FlowNode parallelEndNode, @NonNull ForkScanner scanner) Notifies that we've seen the end of a parallel block- Parameters:
parallelStartNode- First node of parallel (BlockStartNodebefore the branches)parallelEndNode- Last node of parallel (BlockEndNode)scanner- ForkScanner used
-
parallelBranchStart
void parallelBranchStart(@NonNull FlowNode parallelStartNode, @NonNull FlowNode branchStartNode, @NonNull ForkScanner scanner) Hit the start of a parallel branch- Parameters:
parallelStartNode- First node of parallel (BlockStartNode before the branches)branchStartNode- BlockStartNode beginning the branch (this will have the ThreadNameAction giving its name)scanner- ForkScanner used
-
parallelBranchEnd
void parallelBranchEnd(@NonNull FlowNode parallelStartNode, @NonNull FlowNode branchEndNode, @NonNull ForkScanner scanner) Hit the end start of a parallel branchMay not be invoked if we're inside an in-progress parallel
- Parameters:
parallelStartNode- First node of parallel (BlockStartNode before the branches)branchEndNode- Final node of the branch (may be BlockEndNode if done, otherwise just the last one executed)scanner- ForkScanner used
-
atomNode
void atomNode(@CheckForNull FlowNode before, @NonNull FlowNode atomNode, @CheckForNull FlowNode after, @NonNull ForkScanner scan) Called for a flownode neither start nor end. Ways you may want to use this: accumulate pause time, collect errors, etc. Note: invocations don't guarantee whether or not you're within a marked chunk.- Parameters:
before- Node before the currentatomNode- The node itselfafter- Node after the currentscan- Reference to our forkscanner, if we want to poke at the state within
-