org.springframework.batch.core.launch.support

## Class SimpleJobOperator

- java.lang.Object
- - org.springframework.batch.core.launch.support.SimpleJobOperator

- All Implemented Interfaces:
    JobOperator, org.springframework.beans.factory.InitializingBean

      public class SimpleJobOperator
      extends java.lang.Object
      implements JobOperator, org.springframework.beans.factory.InitializingBean

  Simple implementation of the JobOperator interface. Due to the amount of functionality the implementation is combining, the following dependencies are required:
  - `JobLauncher`
  - `JobExplorer`
  - `JobRepository`
  - `JobRegistry`
  Since:
    2.0
  Author:
    Dave Syer, Lucas Ward, Will Schipp

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `SimpleJobOperator()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `JobExecution` | `abandon(long jobExecutionId)` Mark the `JobExecution` as ABANDONED.
    `void` | `afterPropertiesSet()` Check mandatory properties.
    `java.util.List<java.lang.Long>` | `getExecutions(long instanceId)` List the `JobExecutions` associated with a particular `JobInstance`, in reverse order of creation (and therefore usually of execution).
    `java.util.List<java.lang.Long>` | `getJobInstances(java.lang.String jobName, int start, int count)` List the `JobInstances` for a given job name, in reverse order of creation (and therefore usually of first execution).
    `java.util.Set<java.lang.String>` | `getJobNames()` List the available job names that can be launched with `JobOperator.start(String, String)`.
    `java.lang.String` | `getParameters(long executionId)` Get the `JobParameters` as an easily readable String.
    `java.util.Set<java.lang.Long>` | `getRunningExecutions(java.lang.String jobName)` Get the id values of all the running `JobExecutions` with the given job name.
    `java.util.Map<java.lang.Long,java.lang.String>` | `getStepExecutionSummaries(long executionId)` Summarise the `StepExecution` instances belonging to the `JobExecution` with the supplied id, giving details of status, start and end times etc.
    `java.lang.String` | `getSummary(long executionId)` Summarise the `JobExecution` with the supplied id, giving details of status, start and end times etc.
    `java.lang.Long` | `restart(long executionId)` Restart a failed or stopped `JobExecution`.
    `void` | `setJobExplorer(JobExplorer jobExplorer)` Public setter for the `JobExplorer`.
    `void` | `setJobLauncher(JobLauncher jobLauncher)` Public setter for the `JobLauncher`.
    `void` | `setJobParametersConverter(JobParametersConverter jobParametersConverter)` Public setter for the `JobParametersConverter`.
    `void` | `setJobRegistry(ListableJobLocator jobRegistry)` Public setter for the `ListableJobLocator`.
    `void` | `setJobRepository(JobRepository jobRepository)`
    `java.lang.Long` | `start(java.lang.String jobName, java.lang.String parameters)` Start a new instance of a job with the parameters specified.
    `java.lang.Long` | `startNextInstance(java.lang.String jobName)` Launch the next in a sequence of `JobInstance` determined by the `JobParametersIncrementer` attached to the specified job.
    `boolean` | `stop(long executionId)` Send a stop signal to the `JobExecution` with the supplied id.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### SimpleJobOperator

          public SimpleJobOperator()

  - ### Method Detail

    - #### afterPropertiesSet

          public void afterPropertiesSet()
                                  throws java.lang.Exception

      Check mandatory properties.
      Specified by:
        `afterPropertiesSet` in interface `org.springframework.beans.factory.InitializingBean`
      Throws:
        `java.lang.Exception`
      See Also:
        `InitializingBean.afterPropertiesSet()`

    - #### setJobParametersConverter

          public void setJobParametersConverter(JobParametersConverter jobParametersConverter)

      Public setter for the `JobParametersConverter`.
      Parameters:
        `jobParametersConverter` - the `JobParametersConverter` to set

    - #### setJobRegistry

          public void setJobRegistry(ListableJobLocator jobRegistry)

      Public setter for the `ListableJobLocator`.
      Parameters:
        `jobRegistry` - the `ListableJobLocator` to set

    - #### setJobExplorer

          public void setJobExplorer(JobExplorer jobExplorer)

      Public setter for the `JobExplorer`.
      Parameters:
        `jobExplorer` - the `JobExplorer` to set

    - #### setJobRepository

          public void setJobRepository(JobRepository jobRepository)

    - #### setJobLauncher

          public void setJobLauncher(JobLauncher jobLauncher)

      Public setter for the `JobLauncher`.
      Parameters:
        `jobLauncher` - the `JobLauncher` to set

    - #### getExecutions

          public java.util.List<java.lang.Long> getExecutions(long instanceId)
                                                       throws NoSuchJobInstanceException

      Description copied from interface: `JobOperator`
      List the `JobExecutions` associated with a particular `JobInstance`, in reverse order of creation (and therefore usually of execution).
      Specified by:
        `getExecutions` in interface `JobOperator`
      Parameters:
        `instanceId` - the id of a `JobInstance`
      Returns:
        the id values of all the `JobExecutions` associated with this instance
      Throws:
        `NoSuchJobInstanceException`

    - #### getJobNames

          public java.util.Set<java.lang.String> getJobNames()

      Description copied from interface: `JobOperator`
      List the available job names that can be launched with `JobOperator.start(String, String)`.
      Specified by:
        `getJobNames` in interface `JobOperator`
      Returns:
        a set of job names

    - #### getJobInstances

          public java.util.List<java.lang.Long> getJobInstances(java.lang.String jobName,
                                                                int start,
                                                                int count)
                                                         throws NoSuchJobException

      Description copied from interface: `JobOperator`
      List the `JobInstances` for a given job name, in reverse order of creation (and therefore usually of first execution).
      Specified by:
        `getJobInstances` in interface `JobOperator`
      Parameters:
        `jobName` - the job name that all the instances have
        `start` - the start index of the instances
        `count` - the maximum number of values to return
      Returns:
        the id values of the `JobInstances`
      Throws:
        `NoSuchJobException`

    - #### getParameters

          public java.lang.String getParameters(long executionId)
                                         throws NoSuchJobExecutionException

      Description copied from interface: `JobOperator`
      Get the `JobParameters` as an easily readable String.
      Specified by:
        `getParameters` in interface `JobOperator`
      Parameters:
        `executionId` - the id of an existing `JobExecution`
      Returns:
        the job parameters that were used to launch the associated instance
      Throws:
        `NoSuchJobExecutionException` - if the id was not associated with any `JobExecution`

    - #### getRunningExecutions

          public java.util.Set<java.lang.Long> getRunningExecutions(java.lang.String jobName)
                                                             throws NoSuchJobException

      Description copied from interface: `JobOperator`
      Get the id values of all the running `JobExecutions` with the given job name.
      Specified by:
        `getRunningExecutions` in interface `JobOperator`
      Parameters:
        `jobName` - the name of the job to search under
      Returns:
        the id values of the running `JobExecution` instances
      Throws:
        `NoSuchJobException` - if there are no `JobExecutions` with that job name

    - #### getStepExecutionSummaries

          public java.util.Map<java.lang.Long,java.lang.String> getStepExecutionSummaries(long executionId)
                                                                                   throws NoSuchJobExecutionException

      Description copied from interface: `JobOperator`
      Summarise the `StepExecution` instances belonging to the `JobExecution` with the supplied id, giving details of status, start and end times etc.
      Specified by:
        `getStepExecutionSummaries` in interface `JobOperator`
      Parameters:
        `executionId` - the id of an existing `JobExecution`
      Returns:
        a map of step execution id to String summarising the state of the execution
      Throws:
        `NoSuchJobExecutionException` - if there is no `JobExecution` with the supplied id

    - #### getSummary

          public java.lang.String getSummary(long executionId)
                                      throws NoSuchJobExecutionException

      Description copied from interface: `JobOperator`
      Summarise the `JobExecution` with the supplied id, giving details of status, start and end times etc.
      Specified by:
        `getSummary` in interface `JobOperator`
      Parameters:
        `executionId` - the id of an existing `JobExecution`
      Returns:
        a String summarising the state of the job execution
      Throws:
        `NoSuchJobExecutionException` - if there is no `JobExecution` with the supplied id

    - #### restart

          public java.lang.Long restart(long executionId)
                                 throws JobInstanceAlreadyCompleteException,
                                        NoSuchJobExecutionException,
                                        NoSuchJobException,
                                        JobRestartException,
                                        JobParametersInvalidException

      Description copied from interface: `JobOperator`
      Restart a failed or stopped `JobExecution`. Fails with an exception if the id provided does not exist or corresponds to a `JobInstance` that in normal circumstances already completed successfully.
      Specified by:
        `restart` in interface `JobOperator`
      Parameters:
        `executionId` - the id of a failed or stopped `JobExecution`
      Returns:
        the id of the `JobExecution` that was started
      Throws:
        `JobInstanceAlreadyCompleteException` - if the job was already successfully completed
        `NoSuchJobExecutionException` - if the id was not associated with any `JobExecution`
        `NoSuchJobException` - if the `JobExecution` was found, but its corresponding `Job` is no longer available for launching
        `JobRestartException` - if there is a non-specific error with the restart (e.g. corrupt or inconsistent restart data)
        `JobParametersInvalidException` - if the parameters are not valid for this job

    - #### start

          public java.lang.Long start(java.lang.String jobName,
                                      java.lang.String parameters)
                               throws NoSuchJobException,
                                      JobInstanceAlreadyExistsException,
                                      JobParametersInvalidException

      Description copied from interface: `JobOperator`
      Start a new instance of a job with the parameters specified.
      Specified by:
        `start` in interface `JobOperator`
      Parameters:
        `jobName` - the name of the `Job` to launch
        `parameters` - the parameters to launch it with (comma or newline separated name=value pairs)
      Returns:
        the id of the `JobExecution` that is launched
      Throws:
        `NoSuchJobException` - if there is no `Job` with the specified name
        `JobInstanceAlreadyExistsException` - if a job instance with this name and parameters already exists
        `JobParametersInvalidException`

    - #### startNextInstance

          public java.lang.Long startNextInstance(java.lang.String jobName)
                                           throws NoSuchJobException,
                                                  JobParametersNotFoundException,
                                                  UnexpectedJobExecutionException,
                                                  JobParametersInvalidException

      Description copied from interface: `JobOperator`
      Launch the next in a sequence of `JobInstance` determined by the `JobParametersIncrementer` attached to the specified job. If the previous instance is still in a failed state, this method should still create a new instance and run it with different parameters (as long as the `JobParametersIncrementer` is working).
      The last three exception described below should be extremely unlikely, but cannot be ruled out entirely. It points to some other thread or process trying to use this method (or a similar one) at the same time.
      Specified by:
        `startNextInstance` in interface `JobOperator`
      Parameters:
        `jobName` - the name of the job to launch
      Returns:
        the `JobExecution` id of the execution created when the job is launched
      Throws:
        `NoSuchJobException` - if there is no such job definition available
        `JobParametersNotFoundException` - if the parameters cannot be found
        `UnexpectedJobExecutionException`
        `JobParametersInvalidException`

    - #### stop

          @Transactional
          public boolean stop(long executionId)
                                      throws NoSuchJobExecutionException,
                                             JobExecutionNotRunningException

      Description copied from interface: `JobOperator`
      Send a stop signal to the `JobExecution` with the supplied id. The signal is successfully sent if this method returns true, but that doesn't mean that the job has stopped. The only way to be sure of that is to poll the job execution status.
      Specified by:
        `stop` in interface `JobOperator`
      Parameters:
        `executionId` - the id of a running `JobExecution`
      Returns:
        true if the message was successfully sent (does not guarantee that the job has stopped)
      Throws:
        `NoSuchJobExecutionException` - if there is no `JobExecution` with the id supplied
        `JobExecutionNotRunningException` - if the `JobExecution` is not running (so cannot be stopped)

    - #### abandon

          public JobExecution abandon(long jobExecutionId)
                               throws NoSuchJobExecutionException,
                                      JobExecutionAlreadyRunningException

      Description copied from interface: `JobOperator`
      Mark the `JobExecution` as ABANDONED. If a stop signal is ignored because the process died this is the best way to mark a job as finished with (as opposed to STOPPED). An abandoned job execution can be restarted, but a stopping one cannot.
      Specified by:
        `abandon` in interface `JobOperator`
      Parameters:
        `jobExecutionId` - the job execution id to abort
      Returns:
        the `JobExecution` that was aborted
      Throws:
        `NoSuchJobExecutionException`
        `JobExecutionAlreadyRunningException` - if the job is running (it should be stopped first)