public abstract class AbstractJob extends java.lang.Object implements Job, StepLocator, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.InitializingBean
Job
interface. Common dependencies
such as a JobRepository
, JobExecutionListener
s, and various
configuration parameters are set here. Therefore, common error handling and
listener calling activities are abstracted away from implementations.Modifier and Type | Field and Description |
---|---|
protected static org.apache.commons.logging.Log |
logger |
Constructor and Description |
---|
AbstractJob()
Default constructor.
|
AbstractJob(java.lang.String name)
Convenience constructor to immediately add name (which is mandatory but
not final).
|
Modifier and Type | Method and Description |
---|---|
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) . |
protected ExitStatus |
getDefaultExitStatusForFailure(java.lang.Throwable ex,
JobExecution execution)
Default mapping from throwable to
ExitStatus . |
JobParametersIncrementer |
getJobParametersIncrementer()
If clients need to generate new parameters for the next execution in a
sequence they can use this incrementer.
|
JobParametersValidator |
getJobParametersValidator()
A validator for the job parameters of a
JobExecution . |
protected JobRepository |
getJobRepository()
Convenience method for subclasses to access the job repository.
|
java.lang.String |
getName() |
abstract Step |
getStep(java.lang.String stepName)
Retrieve the step with the given name.
|
abstract java.util.Collection<java.lang.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(java.lang.String name)
Set the name property if it is not already set.
|
void |
setJobExecutionListeners(JobExecutionListener[] listeners)
Public setter for injecting
JobExecutionListener s. |
void |
setJobParametersIncrementer(JobParametersIncrementer jobParametersIncrementer)
Public setter for the
JobParametersIncrementer . |
void |
setJobParametersValidator(JobParametersValidator jobParametersValidator)
A validator for job parameters.
|
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(java.lang.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.
|
java.lang.String |
toString() |
public AbstractJob()
public AbstractJob(java.lang.String name)
name
- public void setJobParametersValidator(JobParametersValidator jobParametersValidator)
DefaultJobParametersValidator
.jobParametersValidator
- a validator instancepublic void afterPropertiesSet() throws java.lang.Exception
JobRepository
.afterPropertiesSet
in interface org.springframework.beans.factory.InitializingBean
java.lang.Exception
InitializingBean.afterPropertiesSet()
public void setBeanName(java.lang.String name)
setBeanName
in interface org.springframework.beans.factory.BeanNameAware
BeanNameAware.setBeanName(java.lang.String)
public void setName(java.lang.String name)
setBeanName(java.lang.String)
public abstract Step getStep(java.lang.String stepName)
getStep
in interface StepLocator
stepName
- public abstract java.util.Collection<java.lang.String> getStepNames()
getStepNames
in interface StepLocator
public JobParametersValidator getJobParametersValidator()
Job
JobExecution
. Clients of
a Job may need to validate the parameters for a launch, before or during
the execution.getJobParametersValidator
in interface Job
public void setRestartable(boolean restartable)
restartable
- the value of the flag to set (default true)public boolean isRestartable()
Job
isRestartable
in interface Job
Job.isRestartable()
public void setJobParametersIncrementer(JobParametersIncrementer jobParametersIncrementer)
JobParametersIncrementer
.jobParametersIncrementer
- the JobParametersIncrementer
to setpublic JobParametersIncrementer getJobParametersIncrementer()
Job
getJobParametersIncrementer
in interface Job
public void setJobExecutionListeners(JobExecutionListener[] listeners)
JobExecutionListener
s. They will all
be given the listener callbacks at the appropriate point in the job.listeners
- the listeners to set.public void registerJobExecutionListener(JobExecutionListener listener)
JobExecutionListener
callbacks.listener
- a JobExecutionListener
public void setJobRepository(JobRepository jobRepository)
JobRepository
that is needed to manage the
state of the batch meta domain (jobs, steps, executions) during the life
of a job.jobRepository
- protected JobRepository getJobRepository()
protected abstract void doExecute(JobExecution execution) throws JobExecutionException
handleStep(Step, JobExecution)
.execution
- the current JobExecution
JobExecutionException
- to signal a fatal batch framework error (not a business or
validation exception)public final void execute(JobExecution execution)
doExecute(JobExecution)
.execute
in interface Job
execution
- a JobExecution
StartLimitExceededException
- if start limit of one of the steps was exceededJob.execute(JobExecution)
protected final StepExecution handleStep(Step step, JobExecution execution) throws JobInterruptedException, JobRestartException, StartLimitExceededException
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).step
- the Step
to executeexecution
- the current JobExecution
StepExecution
corresponding to this stepJobInterruptedException
- if the JobExecution
has been interrupted, and in
particular if BatchStatus.ABANDONED
or
BatchStatus.STOPPING
is detectedStartLimitExceededException
- if the start limit has been exceeded for this stepJobRestartException
- if the job is in an inconsistent state from an earlier
failureprotected ExitStatus getDefaultExitStatusForFailure(java.lang.Throwable ex, JobExecution execution)
ExitStatus
.ex
- the cause of the failureExitStatus
public java.lang.String toString()
toString
in class java.lang.Object