org.springframework.batch.core.step
Class AbstractStep

java.lang.Object
  extended by org.springframework.batch.core.step.AbstractStep
All Implemented Interfaces:
Step, BeanNameAware, InitializingBean
Direct Known Subclasses:
ItemOrientedStep, MessageOrientedStep, TaskletStep

public abstract class AbstractStep
extends Object
implements Step, InitializingBean, BeanNameAware

A Step implementation that provides common behavior to subclasses, including registering and calling listeners.

Author:
Dave Syer, Ben Hale, Robert Kasanicky

Nested Class Summary
protected static class AbstractStep.FatalException
          Signals a fatal exception - e.g.
 
Field Summary
static String JOB_INTERRUPTED
          Exit code for interrupted status.
 
Constructor Summary
AbstractStep()
          Default constructor.
AbstractStep(String name)
          Convenient constructor for setting only the name property.
 
Method Summary
 void afterPropertiesSet()
           
protected abstract  void close(ExecutionContext ctx)
           
protected abstract  ExitStatus doExecute(StepExecution stepExecution)
           
 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 getCompositeListener()
           
protected  JobRepository getJobRepository()
           
 String getName()
           
 int getStartLimit()
           
 boolean isAllowStartIfComplete()
           
protected abstract  void open(ExecutionContext ctx)
           
 void registerStepExecutionListener(StepExecutionListener listener)
          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 for JobRepository.
 void setName(String name)
          Set the name property.
 void setStartLimit(int startLimit)
          Public setter for the startLimit.
 void setStepExecutionListeners(StepExecutionListener[] listeners)
          Register each of the objects as listeners.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

JOB_INTERRUPTED

public static final String JOB_INTERRUPTED
Exit code for interrupted status.

See Also:
Constant Field Values
Constructor Detail

AbstractStep

public AbstractStep()
Default constructor.


AbstractStep

public AbstractStep(String name)
Convenient constructor for setting only the name property.

Parameters:
name -
Method Detail

afterPropertiesSet

public void afterPropertiesSet()
                        throws Exception
Specified by:
afterPropertiesSet in interface InitializingBean
Throws:
Exception

getName

public String getName()
Specified by:
getName in interface Step
Returns:
the name of this step.

setName

public void setName(String name)
Set the name property. Always overrides the default value if this object is a Spring bean.

See Also:
setBeanName(java.lang.String)

setBeanName

public void setBeanName(String name)
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 interface BeanNameAware
See Also:
BeanNameAware.setBeanName(java.lang.String)

getStartLimit

public int getStartLimit()
Specified by:
getStartLimit in interface Step
Returns:
the number of times a job can be started with the same identifier.

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 interface Step
Returns:
true if a step that is already marked as complete can be started again.

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

protected abstract ExitStatus doExecute(StepExecution stepExecution)
                                 throws Exception
Throws:
Exception

open

protected abstract void open(ExecutionContext ctx)
                      throws Exception
Throws:
Exception

close

protected abstract void close(ExecutionContext ctx)
                       throws Exception
Throws:
Exception

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 interface Step
Parameters:
stepExecution - an entity representing the step to be executed
Throws:
JobInterruptedException - if the step is interrupted externally
UnexpectedJobExecutionException

registerStepExecutionListener

public void registerStepExecutionListener(StepExecutionListener listener)
Register a step listener for callbacks at the appropriate stages in a step execution.

Parameters:
listener - a StepExecutionListener

setStepExecutionListeners

public void setStepExecutionListeners(StepExecutionListener[] listeners)
Register each of the objects as listeners.

Parameters:
listeners - an array of listener objects of known types.

getCompositeListener

protected StepExecutionListener getCompositeListener()
Returns:
composite listener that delegates to all registered listeners.

setJobRepository

public void setJobRepository(JobRepository jobRepository)
Public setter for JobRepository.

Parameters:
jobRepository - is a mandatory dependence (no default).

getJobRepository

protected JobRepository getJobRepository()


Copyright © 2009 SpringSource. All Rights Reserved.