Class AbstractStep
java.lang.Object
org.springframework.batch.core.step.AbstractStep
- All Implemented Interfaces:
Step
,org.springframework.beans.factory.Aware
,org.springframework.beans.factory.BeanNameAware
,org.springframework.beans.factory.InitializingBean
- Direct Known Subclasses:
DelegateStep
,FlowStep
,JobStep
,PartitionStep
,TaskletStep
public abstract class AbstractStep
extends Object
implements Step, org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.BeanNameAware
A
Step
implementation that provides common behavior to subclasses, including
registering and calling listeners.- Author:
- Dave Syer, Ben Hale, Robert Kasanicky, Michael Minella, Chris Schaefer, Mahmoud Ben Hassine
-
Field Summary
Fields inherited from interface org.springframework.batch.core.Step
STEP_TYPE_KEY
-
Constructor Summary
ConstructorDescriptionDefault constructor.AbstractStep
(String name) Convenient constructor for setting only the name property. -
Method Summary
Modifier and TypeMethodDescriptionvoid
protected void
close
(ExecutionContext ctx) Extension point for subclasses to provide callbacks to their collaborators at the end of a step (right at the end of the finally block), to close or release resources.protected abstract void
doExecute
(StepExecution stepExecution) Extension point for subclasses to execute business logic.protected void
doExecutionRegistration
(StepExecution stepExecution) Registers theStepExecution
for property resolution viaStepScope
protected void
Releases the most recentStepExecution
final void
execute
(StepExecution stepExecution) Template method for step execution logic - calls abstract methods for resource initialization (open(ExecutionContext)
), execution logic (doExecute(StepExecution)
) and resource closing (close(ExecutionContext)
).protected StepExecutionListener
protected JobRepository
getName()
int
boolean
protected void
open
(ExecutionContext ctx) Extension point for subclasses to provide callbacks to their collaborators at the beginning of a step, to open or acquire resources.void
Register a step listener for callbacks at the appropriate stages in a step execution.void
setAllowStartIfComplete
(boolean allowStartIfComplete) Public setter for flag that determines whether the step should start again if it is already complete.void
setBeanName
(String name) Set the name property if it is not already set.void
setJobRepository
(JobRepository jobRepository) Public setter forJobRepository
.void
setMeterRegistry
(io.micrometer.core.instrument.MeterRegistry meterRegistry) void
Set the name property.void
setObservationConvention
(BatchStepObservationConvention observationConvention) void
setObservationRegistry
(io.micrometer.observation.ObservationRegistry observationRegistry) void
setStartLimit
(int startLimit) Public setter for the startLimit.void
setStepExecutionListeners
(StepExecutionListener[] listeners) Register each of the objects as listeners.toString()
-
Constructor Details
-
AbstractStep
public AbstractStep()Default constructor. -
AbstractStep
Convenient constructor for setting only the name property.- Parameters:
name
- Name of the step
-
-
Method Details
-
afterPropertiesSet
- Specified by:
afterPropertiesSet
in interfaceorg.springframework.beans.factory.InitializingBean
- Throws:
Exception
-
getName
-
setName
Set the name property. Always overrides the default value if this object is a Spring bean.- Parameters:
name
- the name of theStep
.- See Also:
-
setBeanName
Set the name property if it is not already set. Because of the order of the callbacks in a Spring container the name property will be set first if it is present. Care is needed with bean definition inheritance - if a parent bean has a name, then its children need an explicit name as well, otherwise they will not be unique.- Specified by:
setBeanName
in interfaceorg.springframework.beans.factory.BeanNameAware
- See Also:
-
BeanNameAware.setBeanName(java.lang.String)
-
getStartLimit
public int getStartLimit()- Specified by:
getStartLimit
in interfaceStep
- Returns:
- the number of times a step can be (re)started for the same job instance.
Defaults to
Integer.MAX_VALUE
-
setStartLimit
public void setStartLimit(int startLimit) Public setter for the startLimit.- Parameters:
startLimit
- the startLimit to set
-
isAllowStartIfComplete
public boolean isAllowStartIfComplete()- Specified by:
isAllowStartIfComplete
in interfaceStep
- Returns:
true
if a step that is already marked as complete can be started again. Defaults tofalse
.
-
setAllowStartIfComplete
public void setAllowStartIfComplete(boolean allowStartIfComplete) Public setter for flag that determines whether the step should start again if it is already complete. Defaults to false.- Parameters:
allowStartIfComplete
- the value of the flag to set
-
doExecute
Extension point for subclasses to execute business logic. Subclasses should set theExitStatus
on theStepExecution
before returning.- Parameters:
stepExecution
- the current step context- Throws:
Exception
- checked exception thrown by implementation
-
open
Extension point for subclasses to provide callbacks to their collaborators at the beginning of a step, to open or acquire resources. Does nothing by default.- Parameters:
ctx
- theExecutionContext
to use- Throws:
Exception
- checked exception thrown by implementation
-
close
Extension point for subclasses to provide callbacks to their collaborators at the end of a step (right at the end of the finally block), to close or release resources. Does nothing by default.- Parameters:
ctx
- theExecutionContext
to use- Throws:
Exception
- checked exception thrown by implementation
-
execute
public final void execute(StepExecution stepExecution) throws JobInterruptedException, UnexpectedJobExecutionException Template method for step execution logic - calls abstract methods for resource initialization (open(ExecutionContext)
), execution logic (doExecute(StepExecution)
) and resource closing (close(ExecutionContext)
).- Specified by:
execute
in interfaceStep
- Parameters:
stepExecution
- an entity representing the step to be executed.- Throws:
JobInterruptedException
- if the step is interrupted externally.UnexpectedJobExecutionException
-
doExecutionRelease
protected void doExecutionRelease()Releases the most recentStepExecution
-
doExecutionRegistration
Registers theStepExecution
for property resolution viaStepScope
- Parameters:
stepExecution
- StepExecution to use when hydrating the StepScoped beans
-
registerStepExecutionListener
Register a step listener for callbacks at the appropriate stages in a step execution.- Parameters:
listener
- aStepExecutionListener
-
setStepExecutionListeners
Register each of the objects as listeners.- Parameters:
listeners
- an array of listener objects of known types.
-
getCompositeListener
- Returns:
- composite listener that delegates to all registered listeners.
-
setJobRepository
Public setter forJobRepository
.- Parameters:
jobRepository
- is a mandatory dependence (no default).
-
getJobRepository
-
toString
-
setObservationConvention
-
setObservationRegistry
public void setObservationRegistry(io.micrometer.observation.ObservationRegistry observationRegistry) -
setMeterRegistry
public void setMeterRegistry(io.micrometer.core.instrument.MeterRegistry meterRegistry)
-