Compose a batch operation from a sequence of dependent steps. Define and implement the operation only once, and allow restart after failure without having to change configuration, and without having to repeat steps that were successful.
A sub-goal is to allow the progress of a batch through the steps to be traced accurately for reporting and auditing purposes. This requires the steps to be uniquely identified.
The vanilla successful case proceeds as follows:
If a step fails internally, e.g. because of resource becoming temporarily unavailable, the sequence can be restarted without repeating the previous steps.
The process above could be carried out by the framework entirely (no need for operator intervention) if a retry policy is in effect.
If a step fails because it receives bad data from an earlier step, the Framework cannot recover without intervention.
If the original problem can be located and fixed (e.g. input data for earlier step is revised):
Unfortunately, the need for parallel processing and automatic restart also makes it practically impossible for steps to handle the context at the level of a single thread of execution, where the client needs to implement business logic. If a step is executing in parallel, then each node needs to be able to restart independently, but the context needs to be a single object that can be passed on to the next step (unless all the steps are parallelised with the same multiplicity, which might not be efficient in general).
Thus batch context must be defined and managed by the template or execution handler.
batchTemplate.iterate(new RepeatCallback[] { new RepeatCallback() { public boolean doInIteration(RepeatContext context) { // do stuff for step one }; }, new RepeatCallback() { public boolean doInIteration(RepeatContext context) { // do stuff for step two - the context // is the same... }; } });
Notice that there is no need for the context to be set explicitly before executing the callback. The context is handled internally to the batch template using an analogue of the TransactionSynchronizationManager.