Class AbstractJob

All Implemented Interfaces:
Job, StepLocator, org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.InitializingBean
Direct Known Subclasses:
FlowJob, SimpleJob

public abstract class AbstractJob extends Object implements Job, StepLocator, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.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.
Lucas Ward, Dave Syer, Mahmoud Ben Hassine
  • Field Details

    • logger

      protected static final org.apache.commons.logging.Log logger
  • Constructor Details

    • AbstractJob

      public AbstractJob()
      Default constructor.
    • AbstractJob

      public AbstractJob(String name)
      Convenience constructor to immediately add name (which is mandatory but not final).
      name - name of the job
  • Method Details

    • setJobParametersValidator

      public void setJobParametersValidator(JobParametersValidator jobParametersValidator)
      A validator for job parameters. Defaults to a vanilla DefaultJobParametersValidator.
      jobParametersValidator - a validator instance
    • afterPropertiesSet

      public void afterPropertiesSet() throws Exception
      Assert mandatory properties: JobRepository.
      Specified by:
      afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
      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 org.springframework.beans.factory.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.
      name - the name to be associated with the job.
      See Also:
    • 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
      stepName - name of the step
      the Step
    • getStepNames

      public abstract Collection<String> getStepNames()
      Retrieve the step names.
      Specified by:
      getStepNames in interface StepLocator
      the step names
    • getJobParametersValidator

      public JobParametersValidator getJobParametersValidator()
      Description copied from interface: Job
      A validator for the job parameters of a JobExecution. Clients of a Job may need to validate the parameters for a launch or before or during the execution.
      Specified by:
      getJobParametersValidator in interface Job
      a validator that can be used to check parameter values (never null). Defaults to DefaultJobParametersValidator.
    • 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()
      Description copied from interface: Job
      Flag to indicate if this job can be restarted, at least in principle.
      Specified by:
      isRestartable in interface Job
      true if this job can be restarted after a failure. Defaults to true.
      See Also:
    • setJobParametersIncrementer

      public void setJobParametersIncrementer(JobParametersIncrementer jobParametersIncrementer)
      Public setter for the JobParametersIncrementer.
      jobParametersIncrementer - the JobParametersIncrementer to set
    • getJobParametersIncrementer

      @Nullable 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, when this job does not have a natural sequence.
      Specified by:
      getJobParametersIncrementer in interface Job
      an incrementer to be used for creating new parameters. Defaults to null.
    • 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.
      listeners - the listeners to set.
    • registerJobExecutionListener

      public void registerJobExecutionListener(JobExecutionListener listener)
      Register a single listener for the JobExecutionListener callbacks.
      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.
      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 to handleStep(Step, JobExecution).
      execution - the current JobExecution
      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
      execution - a JobExecution
      StartLimitExceededException - if start limit of one of the steps was exceeded
      See Also:
    • handleStep

      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).
      step - the Step to execute
      execution - the current JobExecution
      the StepExecution corresponding to this step
      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
    • getDefaultExitStatusForFailure

      protected ExitStatus getDefaultExitStatusForFailure(Throwable ex, JobExecution execution)
      Default mapping from throwable to ExitStatus.
      ex - the cause of the failure
      execution - the JobExecution instance.
      an ExitStatus
    • setObservationConvention

      public void setObservationConvention(BatchJobObservationConvention observationConvention)
    • setObservationRegistry

      public void setObservationRegistry(io.micrometer.observation.ObservationRegistry observationRegistry)
    • setMeterRegistry

      public void setMeterRegistry(io.micrometer.core.instrument.MeterRegistry meterRegistry)
    • toString

      public String toString()
      toString in class Object