Class SimpleStepHandler
- java.lang.Object
- org.springframework.batch.core.job.SimpleStepHandler
- All Implemented Interfaces:
StepHandler
,org.springframework.beans.factory.InitializingBean
- Direct Known Subclasses:
JsrStepHandler
public class SimpleStepHandler extends java.lang.Object implements StepHandler, org.springframework.beans.factory.InitializingBean
Implementation ofStepHandler
that manages repository and restart concerns.- Author:
- Dave Syer
Constructor Summary
Constructors Constructor Description SimpleStepHandler()
Convenient default constructor for configuration usage.SimpleStepHandler(JobRepository jobRepository)
SimpleStepHandler(JobRepository jobRepository, ExecutionContext executionContext)
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
afterPropertiesSet()
Check mandatory properties (jobRepository).protected JobRepository
getJobRepository()
StepExecution
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 Detail
SimpleStepHandler
public SimpleStepHandler()
Convenient default constructor for configuration usage.
SimpleStepHandler
public SimpleStepHandler(JobRepository jobRepository)
- Parameters:
jobRepository
- aJobRepository
SimpleStepHandler
public SimpleStepHandler(JobRepository jobRepository, ExecutionContext executionContext)
- Parameters:
jobRepository
- aJobRepository
executionContext
- theExecutionContext
for the current Step
Method Detail
afterPropertiesSet
public void afterPropertiesSet() throws java.lang.Exception
Check mandatory properties (jobRepository).- Specified by:
afterPropertiesSet
in interfaceorg.springframework.beans.factory.InitializingBean
- Throws:
java.lang.Exception
- See Also:
InitializingBean.afterPropertiesSet()
getJobRepository
protected JobRepository getJobRepository()
- Returns:
- the used jobRepository
setJobRepository
public void setJobRepository(JobRepository jobRepository)
- Parameters:
jobRepository
- the jobRepository to set
setExecutionContext
public void setExecutionContext(ExecutionContext executionContext)
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:
Job.execute(JobExecution)
,Step.execute(StepExecution)
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