Class SimpleStepHandler
java.lang.Object
org.springframework.batch.core.job.SimpleStepHandler
- All Implemented Interfaces:
StepHandler
,org.springframework.beans.factory.InitializingBean
public class SimpleStepHandler
extends Object
implements StepHandler, org.springframework.beans.factory.InitializingBean
Implementation of
StepHandler
that manages repository and restart concerns.- Author:
- Dave Syer
-
Constructor Summary
ConstructorDescriptionConvenient default constructor for configuration usage.SimpleStepHandler
(JobRepository jobRepository) SimpleStepHandler
(JobRepository jobRepository, ExecutionContext executionContext) -
Method Summary
Modifier and TypeMethodDescriptionvoid
Check mandatory properties (jobRepository).protected JobRepository
handleStep
(Step step, JobExecution execution) Handle a step and return the execution for it.void
setExecutionContext
(ExecutionContext executionContext) A context containing values to be added to the step execution before it is handled.void
setJobRepository
(JobRepository jobRepository) protected boolean
shouldStart
(StepExecution lastStepExecution, JobExecution jobExecution, Step step) Given a step and configuration, return true if the step should start, false if it should not, and throw an exception if the job should finish.
-
Constructor Details
-
SimpleStepHandler
public SimpleStepHandler()Convenient default constructor for configuration usage. -
SimpleStepHandler
- Parameters:
jobRepository
- aJobRepository
-
SimpleStepHandler
- Parameters:
jobRepository
- aJobRepository
executionContext
- theExecutionContext
for the current Step
-
-
Method Details
-
afterPropertiesSet
Check mandatory properties (jobRepository).- Specified by:
afterPropertiesSet
in interfaceorg.springframework.beans.factory.InitializingBean
- Throws:
Exception
- See Also:
-
InitializingBean.afterPropertiesSet()
-
getJobRepository
- Returns:
- the used jobRepository
-
setJobRepository
- Parameters:
jobRepository
- the jobRepository to set
-
setExecutionContext
A context containing values to be added to the step execution before it is handled.- Parameters:
executionContext
- the execution context to set
-
handleStep
public StepExecution handleStep(Step step, JobExecution execution) throws JobInterruptedException, JobRestartException, StartLimitExceededException Description copied from interface:StepHandler
Handle a step and return the execution for it. Does not save theJobExecution
, but should manage the persistence of theStepExecution
if required (e.g. at least it needs to be added to a repository before the step can be executed).- Specified by:
handleStep
in interfaceStepHandler
- Parameters:
step
- aStep
execution
- aJobExecution
- Returns:
- an execution of the step
- Throws:
JobInterruptedException
- if there is an interruptionJobRestartException
- if there is a problem restarting a failed stepStartLimitExceededException
- if the step exceeds its start limit- See Also:
-
shouldStart
protected boolean shouldStart(StepExecution lastStepExecution, JobExecution jobExecution, Step step) throws JobRestartException, StartLimitExceededException Given a step and configuration, return true if the step should start, false if it should not, and throw an exception if the job should finish.- Parameters:
lastStepExecution
- the last step executionjobExecution
- theJobExecution
instance to be evaluated.step
- theStep
instance to be evaluated.- Returns:
- true if step should start, false if it should not.
- Throws:
StartLimitExceededException
- if the start limit has been exceeded for this stepJobRestartException
- if the job is in an inconsistent state from an earlier failure
-