org.springframework.batch.core.job
Class AbstractJob

java.lang.Object
  extended by org.springframework.batch.core.job.AbstractJob
All Implemented Interfaces:
Job, StepLocator, BeanNameAware, InitializingBean
Direct Known Subclasses:
FlowJob, SimpleJob

public abstract class AbstractJob
extends Object
implements Job, StepLocator, BeanNameAware, InitializingBean

Abstract implementation of the Job interface. Common dependencies such as a JobRepository, JobExecutionListeners, and various configuration parameters are set here. Therefore, common error handling and listener calling activities are abstracted away from implementations.

Author:
Lucas Ward, Dave Syer

Field Summary
protected static Log logger
           
 
Constructor Summary
AbstractJob()
          Default constructor.
AbstractJob(String name)
          Convenience constructor to immediately add name (which is mandatory but not final).
 
Method Summary
 void afterPropertiesSet()
          Assert mandatory properties: JobRepository.
protected abstract  void doExecute(JobExecution execution)
          Extension point for subclasses allowing them to concentrate on processing logic and ignore listeners and repository calls.
 void execute(JobExecution execution)
          Run the specified job, handling all listener and repository calls, and delegating the actual processing to doExecute(JobExecution).
 JobParametersIncrementer getJobParametersIncrementer()
          If clients need to generate new parameters for the next execution in a sequence they can use this incrementer.
 String getName()
           
abstract  Step getStep(String stepName)
          Retrieve the step with the given name.
abstract  Collection<String> getStepNames()
          Retrieve the step names.
protected  StepExecution handleStep(Step step, JobExecution execution)
          Convenience method for subclasses to delegate the handling of a specific step in the context of the current JobExecution.
 boolean isRestartable()
          Flag to indicate if this job can be restarted, at least in principle.
 void registerJobExecutionListener(JobExecutionListener listener)
          Register a single listener for the JobExecutionListener callbacks.
 void setBeanName(String name)
          Set the name property if it is not already set.
 void setJobExecutionListeners(JobExecutionListener[] listeners)
          Public setter for injecting JobExecutionListeners.
 void setJobParametersIncrementer(JobParametersIncrementer jobParametersIncrementer)
          Public setter for the JobParametersIncrementer.
 void setJobRepository(JobRepository jobRepository)
          Public setter for the JobRepository that is needed to manage the state of the batch meta domain (jobs, steps, executions) during the life of a job.
 void setName(String name)
          Set the name property.
 void setRestartable(boolean restartable)
          Boolean flag to prevent categorically a job from restarting, even if it has failed previously.
 String toString()
           
protected  void updateStepExecution(StepExecution stepExecution)
          Convenience method for subclasses so they can change the state of a StepExecution if necessary.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

logger

protected static final Log logger
Constructor Detail

AbstractJob

public AbstractJob()
Default constructor.


AbstractJob

public AbstractJob(String name)
Convenience constructor to immediately add name (which is mandatory but not final).

Parameters:
name -
Method Detail

afterPropertiesSet

public void afterPropertiesSet()
                        throws Exception
Assert mandatory properties: JobRepository.

Specified by:
afterPropertiesSet in interface InitializingBean
Throws:
Exception
See Also:
InitializingBean.afterPropertiesSet()

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)

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)

getName

public String getName()
Specified by:
getName in interface Job

getStep

public abstract Step getStep(String stepName)
Retrieve the step with the given name. If there is no Step with the given name, then return null.

Specified by:
getStep in interface StepLocator
Parameters:
stepName -
Returns:
the Step

getStepNames

public abstract Collection<String> getStepNames()
Retrieve the step names.

Specified by:
getStepNames in interface StepLocator
Returns:
the step names

setRestartable

public void setRestartable(boolean restartable)
Boolean flag to prevent categorically a job from restarting, even if it has failed previously.

Parameters:
restartable - the value of the flag to set (default true)

isRestartable

public boolean isRestartable()
Description copied from interface: Job
Flag to indicate if this job can be restarted, at least in principle.

Specified by:
isRestartable in interface Job
Returns:
true if this job can be restarted after a failure
See Also:
Job.isRestartable()

setJobParametersIncrementer

public void setJobParametersIncrementer(JobParametersIncrementer jobParametersIncrementer)
Public setter for the JobParametersIncrementer.

Parameters:
jobParametersIncrementer - the JobParametersIncrementer to set

getJobParametersIncrementer

public JobParametersIncrementer getJobParametersIncrementer()
Description copied from interface: Job
If clients need to generate new parameters for the next execution in a sequence they can use this incrementer. The return value may be null, in the case that this job does not have a natural sequence.

Specified by:
getJobParametersIncrementer in interface Job
Returns:
in incrementer to be used for creating new parameters

setJobExecutionListeners

public void setJobExecutionListeners(JobExecutionListener[] listeners)
Public setter for injecting JobExecutionListeners. They will all be given the listener callbacks at the appropriate point in the job.

Parameters:
listeners - the listeners to set.

registerJobExecutionListener

public void registerJobExecutionListener(JobExecutionListener listener)
Register a single listener for the JobExecutionListener callbacks.

Parameters:
listener - a JobExecutionListener

setJobRepository

public void setJobRepository(JobRepository jobRepository)
Public setter for the JobRepository that is needed to manage the state of the batch meta domain (jobs, steps, executions) during the life of a job.

Parameters:
jobRepository -

doExecute

protected abstract void doExecute(JobExecution execution)
                           throws JobExecutionException
Extension point for subclasses allowing them to concentrate on processing logic and ignore listeners and repository calls. Implementations usually are concerned with the ordering of steps, and delegate actual step processing to handleStep(Step, JobExecution).

Parameters:
execution - the current JobExecution
Throws:
JobExecutionException - to signal a fatal batch framework error (not a business or validation exception)

execute

public final void execute(JobExecution execution)
Run the specified job, handling all listener and repository calls, and delegating the actual processing to doExecute(JobExecution).

Specified by:
execute in interface Job
Parameters:
execution - a JobExecution
Throws:
StartLimitExceededException - if start limit of one of the steps was exceeded
See Also:
Job.execute(JobExecution)

handleStep

protected final StepExecution handleStep(Step step,
                                         JobExecution execution)
                                  throws JobInterruptedException,
                                         JobRestartException,
                                         StartLimitExceededException
Convenience method for subclasses to delegate the handling of a specific step in the context of the current JobExecution. Clients of this method do not need access to the JobRepository, nor do they need to worry about populating the execution context on a restart, nor detecting the interrupted state (in job or step execution).

Parameters:
step - the Step to execute
execution - the current JobExecution
Returns:
the StepExecution corresponding to this step
Throws:
JobInterruptedException - if the JobExecution has been interrupted, and in particular if BatchStatus.ABANDONED or BatchStatus.STOPPING is detected
StartLimitExceededException - if the start limit has been exceeded for this step
JobRestartException - if the job is in an inconsistent state from an earlier failure

updateStepExecution

protected void updateStepExecution(StepExecution stepExecution)
Convenience method for subclasses so they can change the state of a StepExecution if necessary. Use with care (and not at all preferably) and only before or after a step is executed.

Parameters:
stepExecution -

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2009 SpringSource. All Rights Reserved.