Class MergeExecutor

java.lang.Object
ai.nervemind.app.executor.MergeExecutor
All Implemented Interfaces:
NodeExecutor

@Component public class MergeExecutor extends Object implements NodeExecutor
Executor for the "merge" node type - combines data from multiple input branches.

Handles synchronization of parallel workflow branches by collecting and combining data from multiple incoming edges. Essential for rejoining parallel execution paths created by ParallelExecutor or graph structure.

Node Parameters

Merge node configuration parameters
Parameter Type Default Description
mode String "waitAll" How to merge inputs (see modes below)
inputCount Integer 2 Expected number of inputs (for waitAll mode)
timeout Integer 300 Timeout in seconds for waiting
outputKey String "merged" Key under which to store merged data
waitForAll Boolean true If false, proceed with first input (for exclusive/conditional branches)

Merge Modes

  • waitAll - Wait for all expected inputs before proceeding (uses CountDownLatch for synchronization)
  • waitAny - Proceed as soon as any input arrives
  • append - Append all inputs to a list
  • merge - Deep merge all input objects (later inputs override earlier)
  • passthrough - Pass through input directly without nesting. When waitForAll=false, proceeds with first input (ideal for IF/conditional branches)

Output Data

Output keys added by this executor
Key Type Description
[outputKey] Map/List Combined data based on mode
_inputCount Integer Number of inputs that were merged
_mergeMode String The mode used for merging

Thread Safety

Uses ConcurrentHashMap and CountDownLatch to handle concurrent input from multiple threads in parallel execution scenarios.

See Also:
  • Constructor Details

    • MergeExecutor

      public MergeExecutor()
      Default constructor.
  • Method Details

    • execute

      public Map<String,Object> execute(ai.nervemind.common.domain.Node node, Map<String,Object> input, ExecutionService.ExecutionContext context)
      Description copied from interface: NodeExecutor
      Executes the business logic for this node type.
      Specified by:
      execute in interface NodeExecutor
      Parameters:
      node - The node definition containing parameters and configuration. Use Node.parameters() to access user settings.
      input - Combined output from all upstream nodes that connected to this node. For simple flows, this contains the direct predecessor's output. For merge nodes, it contains combined data.
      context - Verification context providing access to workflow-scoped services, logger, and execution metadata.
      Returns:
      A Map containing the results of this node's execution. Keys in this map become available variables for downstream nodes.
      Note: Returning null is treated as an empty map.
    • getNodeType

      public String getNodeType()
      Description copied from interface: NodeExecutor
      Unique identifier for the node type this executor handles. This must match the 'type' field in the JSON definition of the node.
      Specified by:
      getNodeType in interface NodeExecutor
      Returns:
      The unique type string (e.g., "httpRequest", "llmChat").