Class SimpleStepExecutionSplitter
java.lang.Object
org.springframework.batch.core.partition.support.SimpleStepExecutionSplitter
- All Implemented Interfaces:
StepExecutionSplitter,org.springframework.beans.factory.InitializingBean
public class SimpleStepExecutionSplitter
extends Object
implements StepExecutionSplitter, org.springframework.beans.factory.InitializingBean
Generic implementation of
StepExecutionSplitter that delegates to a
Partitioner to generate ExecutionContext instances. Takes care of
restartability and identifying the step executions from previous runs of the same job.
The generated StepExecution instances have names that identify them uniquely in
the partition. The name is constructed from a base (name of the target step) plus a
suffix taken from the Partitioner identifiers, separated by a colon, e.g.
{step1:partition0, step1:partition1, ...}.- Since:
- 2.0
- Author:
- Dave Syer, Mahmoud Ben Hassine
-
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor for convenience in configuration.SimpleStepExecutionSplitter(JobRepository jobRepository, boolean allowStartIfComplete, String stepName, Partitioner partitioner) Construct aSimpleStepExecutionSplitterfrom its mandatory properties. -
Method Summary
Modifier and TypeMethodDescriptionvoidCheck mandatory properties (step name, job repository and partitioner).The name of the step configuration that will be executed remotely.protected booleanisStartable(StepExecution stepExecution, ExecutionContext context) Check if a step execution is startable.voidsetAllowStartIfComplete(boolean allowStartIfComplete) Flag to indicate that the partition target step is allowed to start if an execution is complete.voidsetJobRepository(JobRepository jobRepository) The job repository that will be used to manage the persistence of the delegate step executions.voidsetPartitioner(Partitioner partitioner) ThePartitionerthat will be used to generate step execution meta data for the target step.voidsetStepName(String stepName) The name of the target step that will be executed across the partitions.split(StepExecution stepExecution, int gridSize) Partition the providedStepExecutioninto a set of parallel executable instances with the same parentJobExecution.
-
Constructor Details
-
SimpleStepExecutionSplitter
public SimpleStepExecutionSplitter()Default constructor for convenience in configuration. -
SimpleStepExecutionSplitter
public SimpleStepExecutionSplitter(JobRepository jobRepository, boolean allowStartIfComplete, String stepName, Partitioner partitioner) Construct aSimpleStepExecutionSplitterfrom its mandatory properties.- Parameters:
jobRepository- theJobRepositoryallowStartIfComplete- flag specifying preferences on restartstepName- the target step namepartitioner- aPartitionerto use for generating input parameters
-
-
Method Details
-
afterPropertiesSet
Check mandatory properties (step name, job repository and partitioner).- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean- Throws:
Exception- See Also:
-
InitializingBean.afterPropertiesSet()
-
setAllowStartIfComplete
public void setAllowStartIfComplete(boolean allowStartIfComplete) Flag to indicate that the partition target step is allowed to start if an execution is complete. Defaults to the same value as the underlying step. Set this manually to override the underlying step properties.- Parameters:
allowStartIfComplete- the value to set- See Also:
-
setJobRepository
The job repository that will be used to manage the persistence of the delegate step executions.- Parameters:
jobRepository- the JobRepository to set
-
setPartitioner
ThePartitionerthat will be used to generate step execution meta data for the target step.- Parameters:
partitioner- the partitioner to set
-
setStepName
The name of the target step that will be executed across the partitions. Mandatory with no default.- Parameters:
stepName- the step name to set
-
getStepName
Description copied from interface:StepExecutionSplitterThe name of the step configuration that will be executed remotely. Remote workers are going to execute a the same step for each execution context in the partition.- Specified by:
getStepNamein interfaceStepExecutionSplitter- Returns:
- the name of the step that will execute the business logic
- See Also:
-
split
public Set<StepExecution> split(StepExecution stepExecution, int gridSize) throws JobExecutionException Description copied from interface:StepExecutionSplitterPartition the providedStepExecutioninto a set of parallel executable instances with the same parentJobExecution. The grid size will be treated as a hint for the size of the collection to be returned. It may or may not correspond to the physical size of an execution grid.
On a restart clients of theStepExecutionSplittershould expect it to reconstitute the state of the last failed execution and only return those executions that need to be restarted. Thus the grid size hint will be ignored on a restart.- Specified by:
splitin interfaceStepExecutionSplitter- Parameters:
stepExecution- theStepExecutionto be partitioned.gridSize- a hint for the splitter if the size of the grid is known- Returns:
- a set of
StepExecutioninstances for remote processing - Throws:
JobExecutionException- if the split cannot be made- See Also:
-
isStartable
protected boolean isStartable(StepExecution stepExecution, ExecutionContext context) throws JobExecutionException Check if a step execution is startable.- Parameters:
stepExecution- the step execution to checkcontext- the execution context of the step- Returns:
- true if the step execution is startable, false otherwise
- Throws:
JobExecutionException- if unable to check if the step execution is startable
-