类 AbstractJob
- java.lang.Object
- org.springframework.batch.core.job.AbstractJob
- 所有已实现的接口:
Job
,StepLocator
,org.springframework.beans.factory.Aware
,org.springframework.beans.factory.BeanNameAware
,org.springframework.beans.factory.InitializingBean
public abstract class AbstractJob extends java.lang.Object implements Job, StepLocator, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.InitializingBean
Abstract implementation of theJob
interface. Common dependencies such as aJobRepository
,JobExecutionListener
s, and various configuration parameters are set here. Therefore, common error handling and listener calling activities are abstracted away from implementations.- 作者:
- Lucas Ward, Dave Syer, Mahmoud Ben Hassine
字段概要
字段 修饰符和类型 字段 说明 protected static org.apache.commons.logging.Log
logger
构造器概要
构造器 构造器 说明 AbstractJob()
Default constructor.AbstractJob(java.lang.String name)
Convenience constructor to immediately add name (which is mandatory but not final).
方法概要
所有方法 实例方法 抽象方法 具体方法 修饰符和类型 方法 说明 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 todoExecute(JobExecution)
.protected ExitStatus
getDefaultExitStatusForFailure(java.lang.Throwable ex, JobExecution execution)
Default mapping from throwable toExitStatus
.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 aJobExecution
.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 currentJobExecution
.boolean
isRestartable()
Flag to indicate if this job can be restarted, at least in principle.void
registerJobExecutionListener(JobExecutionListener listener)
Register a single listener for theJobExecutionListener
callbacks.void
setBeanName(java.lang.String name)
Set the name property if it is not already set.void
setJobExecutionListeners(JobExecutionListener[] listeners)
Public setter for injectingJobExecutionListener
s.void
setJobParametersIncrementer(JobParametersIncrementer jobParametersIncrementer)
Public setter for theJobParametersIncrementer
.void
setJobParametersValidator(JobParametersValidator jobParametersValidator)
A validator for job parameters.void
setJobRepository(JobRepository jobRepository)
Public setter for theJobRepository
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()
字段详细资料
logger
protected static final org.apache.commons.logging.Log logger
构造器详细资料
AbstractJob
public AbstractJob()
Default constructor.
AbstractJob
public AbstractJob(java.lang.String name)
Convenience constructor to immediately add name (which is mandatory but not final).- 参数:
name
- name of the job
方法详细资料
setJobParametersValidator
public void setJobParametersValidator(JobParametersValidator jobParametersValidator)
A validator for job parameters. Defaults to a vanillaDefaultJobParametersValidator
.- 参数:
jobParametersValidator
- a validator instance
afterPropertiesSet
public void afterPropertiesSet() throws java.lang.Exception
Assert mandatory properties:JobRepository
.- 指定者:
afterPropertiesSet
在接口中org.springframework.beans.factory.InitializingBean
- 抛出:
java.lang.Exception
- 另请参阅:
InitializingBean.afterPropertiesSet()
setBeanName
public void setBeanName(java.lang.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.- 指定者:
setBeanName
在接口中org.springframework.beans.factory.BeanNameAware
- 另请参阅:
BeanNameAware.setBeanName(java.lang.String)
setName
public void setName(java.lang.String name)
Set the name property. Always overrides the default value if this object is a Spring bean.- 参数:
name
- the name to be associated with the job.- 另请参阅:
setBeanName(java.lang.String)
getStep
public abstract Step getStep(java.lang.String stepName)
Retrieve the step with the given name. If there is no Step with the given name, then return null.- 指定者:
getStep
在接口中StepLocator
- 参数:
stepName
- name of the step- 返回:
- the Step
getStepNames
public abstract java.util.Collection<java.lang.String> getStepNames()
Retrieve the step names.- 指定者:
getStepNames
在接口中StepLocator
- 返回:
- the step names
getJobParametersValidator
public JobParametersValidator getJobParametersValidator()
从接口复制的说明:Job
A validator for the job parameters of aJobExecution
. Clients of a Job may need to validate the parameters for a launch, before or during the execution.- 指定者:
getJobParametersValidator
在接口中Job
- 返回:
- a validator that can be used to check parameter values (never
null
)
setRestartable
public void setRestartable(boolean restartable)
Boolean flag to prevent categorically a job from restarting, even if it has failed previously.- 参数:
restartable
- the value of the flag to set (default true)
isRestartable
public boolean isRestartable()
从接口复制的说明:Job
Flag to indicate if this job can be restarted, at least in principle.- 指定者:
isRestartable
在接口中Job
- 返回:
- true if this job can be restarted after a failure
- 另请参阅:
Job.isRestartable()
setJobParametersIncrementer
public void setJobParametersIncrementer(JobParametersIncrementer jobParametersIncrementer)
Public setter for theJobParametersIncrementer
.- 参数:
jobParametersIncrementer
- theJobParametersIncrementer
to set
getJobParametersIncrementer
@Nullable public JobParametersIncrementer getJobParametersIncrementer()
从接口复制的说明:Job
If clients need to generate new parameters for the next execution in a sequence they can use this incrementer. The return value may benull
, in the case that this job does not have a natural sequence.- 指定者:
getJobParametersIncrementer
在接口中Job
- 返回:
- in incrementer to be used for creating new parameters
setJobExecutionListeners
public void setJobExecutionListeners(JobExecutionListener[] listeners)
Public setter for injectingJobExecutionListener
s. They will all be given the listener callbacks at the appropriate point in the job.- 参数:
listeners
- the listeners to set.
registerJobExecutionListener
public void registerJobExecutionListener(JobExecutionListener listener)
Register a single listener for theJobExecutionListener
callbacks.- 参数:
listener
- aJobExecutionListener
setJobRepository
public void setJobRepository(JobRepository jobRepository)
Public setter for theJobRepository
that is needed to manage the state of the batch meta domain (jobs, steps, executions) during the life of a job.- 参数:
jobRepository
- repository to use during the job execution
getJobRepository
protected JobRepository getJobRepository()
Convenience method for subclasses to access the job repository.- 返回:
- the 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 tohandleStep(Step, JobExecution)
.- 参数:
execution
- the currentJobExecution
- 抛出:
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 todoExecute(JobExecution)
.- 指定者:
execute
在接口中Job
- 参数:
execution
- aJobExecution
- 抛出:
StartLimitExceededException
- if start limit of one of the steps was exceeded- 另请参阅:
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 currentJobExecution
. Clients of this method do not need access to theJobRepository
, 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
- theStep
to executeexecution
- the currentJobExecution
- 返回:
- the
StepExecution
corresponding to this step - 抛出:
JobInterruptedException
- if theJobExecution
has been interrupted, and in particular ifBatchStatus.ABANDONED
orBatchStatus.STOPPING
is detectedStartLimitExceededException
- if the start limit has been exceeded for this stepJobRestartException
- if the job is in an inconsistent state from an earlier failure
getDefaultExitStatusForFailure
protected ExitStatus getDefaultExitStatusForFailure(java.lang.Throwable ex, JobExecution execution)
Default mapping from throwable toExitStatus
.- 参数:
ex
- the cause of the failureexecution
- theJobExecution
instance.- 返回:
- an
ExitStatus
toString
public java.lang.String toString()
- 覆盖:
toString
在类中java.lang.Object