From 652ca038f901e0425935d298ce565a0efa0bcaaa Mon Sep 17 00:00:00 2001 From: Michael Minella Date: Thu, 5 Feb 2015 12:08:46 -0600 Subject: [PATCH] Fixed SplitBuilder to behave as documentation perscribes. This commit includes the parent builder's current state from a SplitBuilder in the actual split. The documentation is also updated to note that a user should either create a flow with transitions or a flow that splits, not both and use composition to create more complex flows. BATCH-2346 --- .../batch/core/job/builder/FlowBuilder.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/job/builder/FlowBuilder.java b/spring-batch-core/src/main/java/org/springframework/batch/core/job/builder/FlowBuilder.java index de878d421..672047d2c 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/job/builder/FlowBuilder.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/job/builder/FlowBuilder.java @@ -582,7 +582,34 @@ public class FlowBuilder { * * In this example, a flow consisting of step1 will be executed in parallel with flow. * + * Note: Adding a split to a chain of states is not supported. For example, the following configuration + * is not supported. Instead, the configuration would need to create a flow3 that was the split flow and assemble + * them separately. + * + *
+	 * // instead of this
+	 * Flow complexFlow = new FlowBuilder<SimpleFlow>("ComplexParallelFlow")
+	 *                       .start(flow1)
+	 *                       .next(flow2)
+	 *                       .split(new SimpleAsyncTaskExecutor())
+	 *                       .add(flow3, flow4)
+	 *                       .build();
+	 *
+	 * // do this
+	 * Flow splitFlow = new FlowBuilder<SimpleFlow>("parallelFlow")
+	 *                       .start(flow3)
+	 *                       .split(new SimpleAsyncTaskExecutor())
+	 *                       .add(flow4).build();
+	 *
+	 * Flow complexFlow = new FlowBuilder<SimpleFlow>("ComplexParallelFlow")
+	 *                       .start(flow1)
+	 *                       .next(flow2)
+	 *                       .next(splitFlow)
+	 *                       .build();
+	 * 
+ * * @author Dave Syer + * @author Michael Minella * * @param the result of the parent builder's build() */ @@ -617,7 +644,10 @@ public class FlowBuilder { FlowBuilder stateBuilder = new FlowBuilder(name + "_" + (counter++)); stateBuilder.currentState = one; flow = stateBuilder.build(); + } else if (one instanceof FlowState && parent.states.size() == 1) { + list.add(((FlowState) one).getFlows().iterator().next()); } + if (flow != null) { list.add(flow); }