-
Notifications
You must be signed in to change notification settings - Fork 39
Workflow Hierarchies
More complex workflows can contain subsets of tasks that can be abstracted as workflows themselves. Workflow hierarchies enables you to divide a complex workflow into a parent workflow that creates child workflows. For example, a credit application workflow can contain a credit decision workflow as a child workflow. See glossary for workflow hierarchy related terms.
Creation of child workflows and signaling between parent and child workflows is done through StateExecution
-interface. State handler methods may construct new child workflows by using builder returned by StateExecution.workflowInstanceBuilder()
and add them through StateExecution.addChildWorkflows()
. The child workflows are workflow instances that are executed independently of the parent workflow, allowing asynchronous and concurrent processing of tasks related to the workflow.
Even though the execution of the child workflows is independent, nFlow provides methods to coordinate the execution of the parent and child workflows. For example, the child workflows may notify the parent workflow when they reach a final state by calling StateExecution.wakeUpParentWorkflow()
, and the parent workflow can get the child workflows by calling StateExecution.getAllChildWorkflows()
or StateExecution.queryChildWorkflows()
.
nFlow guarantees that the child workflows are created if and only if the state method that added them is processed successfully. nFlow also guarantees that calling StateExecution.wakeUpParentWorkflow()
multiple times will wake up the parent only once, unless the parent workflow execution was started before the last wake up call. In other words, the parent is always woken up if and only if needed.
However, nFlow does not enforce calling the StateExecution.wakeUpParentWorkflow()
- it is up to the child workflow to call it if needed. In some cases the parent workflow may proceed to final state before the child workflows are completed, in which case there is no need to wake up the parent from the child workflows. The parent workflow may also be scheduled to check the child workflow statuses after some time to handle the case where the child workflows fail to finish.
The child workflows can also create their own child workflows. nFlow does not limit the number of the child workflows nor the depth of the workflow hierarchy.
nFlow Explorer supports child workflows by providing links from parent workflow to child workflows and vice versa. Archiving workflows support child workflows by only archiving workflow hierarchies that are completely in final state.
For an example on how to use child workflows, see FibonacciWorkflow.java.