Class ParallelExecutor

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

@Component public class ParallelExecutor extends Object implements NodeExecutor
Executor for the "parallel" node type - executes multiple branches concurrently.

Enables parallel execution of independent operations using Java virtual threads (Project Loom). Branches execute simultaneously and results are combined based on the configured strategy. Ideal for independent API calls or data processing tasks.

Node Parameters

Parallel node configuration parameters
Parameter Type Default Description
branches List [] List of branch configurations
combineResults String "merge" How to combine results (see strategies)
timeout Long 60000 Max execution time in milliseconds
failFast Boolean false Cancel all on first failure

Branch Structure

Each branch in the branches list contains:

  • name - Branch identifier for result tracking
  • operations - List of operations to execute sequentially in this branch

Operation Structure

Each operation within a branch:

  • type - Node type to execute
  • name - Display name (optional)
  • config - Configuration for that node type

Combine Strategies

  • merge - Deep merge all branch results into single object
  • array - Collect results in an array
  • first - Return only the first completed result

Output Data

Output keys added by this executor
Key Type Description
result Map/List Combined output based on strategy
completedBranches List Names of successfully completed branches
branchCount Integer Total number of branches
successCount Integer Number of successful branches
hasErrors Boolean True if any branch failed
errors Map Branch name → error message (if errors)

Implementation Notes

Uses Executors.newVirtualThreadPerTaskExecutor() for lightweight concurrent execution. Each branch runs in its own virtual thread.

See Also:
  • Constructor Details

    • ParallelExecutor

      public ParallelExecutor(@Lazy NodeExecutorRegistry nodeExecutorRegistry)
      Creates a new parallel executor.
      Parameters:
      nodeExecutorRegistry - the registry for accessing other node executors
  • Method Details

    • 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").
    • 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.