Class ParallelExecutor
java.lang.Object
ai.nervemind.app.executor.ParallelExecutor
- All Implemented Interfaces:
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
| 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
| 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 Summary
ConstructorsConstructorDescriptionParallelExecutor(NodeExecutorRegistry nodeExecutorRegistry) Creates a new parallel executor. -
Method Summary
Modifier and TypeMethodDescriptionexecute(ai.nervemind.common.domain.Node node, Map<String, Object> input, ExecutionService.ExecutionContext context) Executes the business logic for this node type.Unique identifier for the node type this executor handles.
-
Constructor Details
-
ParallelExecutor
Creates a new parallel executor.- Parameters:
nodeExecutorRegistry- the registry for accessing other node executors
-
-
Method Details
-
getNodeType
Description copied from interface:NodeExecutorUnique identifier for the node type this executor handles. This must match the 'type' field in the JSON definition of the node.- Specified by:
getNodeTypein interfaceNodeExecutor- 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:NodeExecutorExecutes the business logic for this node type.- Specified by:
executein interfaceNodeExecutor- Parameters:
node- The node definition containing parameters and configuration. UseNode.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: Returningnullis treated as an empty map.
-