org.springframework.cloud.dataflow.server.batch

## Class SimpleJobService

- java.lang.Object
- - org.springframework.cloud.dataflow.server.batch.SimpleJobService

- All Implemented Interfaces:
    org.springframework.beans.factory.DisposableBean, JobService

      public class SimpleJobService
      extends Object
      implements JobService, org.springframework.beans.factory.DisposableBean

  Implementation of `JobService` that delegates most of its work to other off-the-shelf components.
  Author:
    Dave Syer, Michael Minella, Glenn Renfro

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `SimpleJobService(SearchableJobInstanceDao jobInstanceDao, SearchableJobExecutionDao jobExecutionDao, SearchableStepExecutionDao stepExecutionDao, org.springframework.batch.core.repository.JobRepository jobRepository, org.springframework.batch.core.repository.dao.ExecutionContextDao executionContextDao, javax.batch.operations.JobOperator jsrJobOperator)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `org.springframework.batch.core.JobExecution` | `abandon(Long jobExecutionId)` Mark the `JobExecution` as ABANDONED.
    `int` | `countJobExecutions()` Count the maximum number of executions that could be returned by `JobService.listJobExecutions(int, int)`.
    `int` | `countJobExecutionsForJob(String name, org.springframework.batch.core.BatchStatus status)` Count the job executions in the repository for a job.
    `int` | `countJobInstances(String name)` Count the number of `job instances` in the repository for a given job name.
    `int` | `countJobs()` Count the total number of jobs that can be returned by `JobService.listJobs(int, int)`.
    `int` | `countStepExecutionsForJobExecution(long jobExecutionId)` Count the step executions in the repository for a given job execution.
    `int` | `countStepExecutionsForStep(String jobName, String stepName)` Count the step executions in the repository for a given step name (or pattern).
    `void` | `destroy()` Stop all the active jobs and wait for them (up to a time out) to finish processing.
    `org.springframework.batch.core.JobExecution` | `getJobExecution(Long jobExecutionId)` Get a `JobExecution` by id.
    `Collection<org.springframework.batch.core.JobExecution>` | `getJobExecutionsForJobInstance(String name, Long jobInstanceId)` Get all the job executions for a given job instance.
    `org.springframework.batch.core.JobInstance` | `getJobInstance(long jobInstanceId)` Get a `job instance` by id.
    `org.springframework.batch.core.JobParameters` | `getLastJobParameters(String jobName)` Get the last `JobParameters` used to execute a job successfully.
    `org.springframework.batch.core.StepExecution` | `getStepExecution(Long jobExecutionId, Long stepExecutionId)` Locate a `StepExecution` from its id and that of its parent `JobExecution`.
    `Collection<org.springframework.batch.core.StepExecution>` | `getStepExecutions(Long jobExecutionId)` Get the `step executions` for a given job execution (by id).
    `Collection<String>` | `getStepNamesForJob(String jobName)` Get the names of the steps in a job (or a historical list of recent execution names if the Job is not launchable).
    `org.springframework.batch.core.JobExecution` | `launch(String jobName, org.springframework.batch.core.JobParameters jobParameters)` Launch a job with the parameters provided.
    `Collection<org.springframework.batch.core.JobExecution>` | `listJobExecutions(int start, int count)` List the `job executions` in descending order of creation (usually close to execution order).
    `Collection<org.springframework.batch.core.JobExecution>` | `listJobExecutionsForJob(String jobName, org.springframework.batch.core.BatchStatus status, int pageOffset, int pageSize)` List the `job executions` for a job in descending order of creation (usually close to execution order).
    `Collection<JobExecutionWithStepCount>` | `listJobExecutionsForJobWithStepCount(Date fromDate, Date toDate, int start, int count)` List the `job executions` filtered by date range in descending order of creation (usually close to execution order).
    `Collection<JobExecutionWithStepCount>` | `listJobExecutionsForJobWithStepCount(String jobName, int start, int count)` List the `job executions` for a job in descending order of creation (usually close to execution order).
    `Collection<JobExecutionWithStepCount>` | `listJobExecutionsForJobWithStepCountFilteredByJobInstanceId(int jobInstanceId, int start, int count)` List the `job executions` filtered by job instance id in descending order of creation (usually close to execution order).
    `Collection<JobExecutionWithStepCount>` | `listJobExecutionsForJobWithStepCountFilteredByTaskExecutionId(int taskExecutionId, int start, int count)` List the `job executions` filtered by task execution id in descending order of creation (usually close to execution order).
    `Collection<JobExecutionWithStepCount>` | `listJobExecutionsWithStepCount(int start, int count)` List the `JobExecutions` in descending order of creation (usually close to execution order) without step execution data.
    `Collection<org.springframework.batch.core.JobInstance>` | `listJobInstances(String jobName, int start, int count)` List the `job instances` in descending order of creation (usually close to order of execution).
    `Collection<String>` | `listJobs(int start, int count)` Query the job names in the system, either launchable or not.
    `Collection<org.springframework.batch.core.StepExecution>` | `listStepExecutionsForStep(String jobName, String stepName, int start, int count)` List the `step executions` for a step in descending order of creation (usually close to execution order).
    `void` | `removeInactiveExecutions()` Check all the active executions and see if they are still actually running.
    `org.springframework.batch.core.JobExecution` | `restart(Long jobExecutionId)` Delegates launching to `restart(Long, org.springframework.batch.core.JobParameters)`
    `org.springframework.batch.core.JobExecution` | `restart(Long jobExecutionId, org.springframework.batch.core.JobParameters params)` Launch a job with the parameters provided.
    `void` | `setShutdownTimeout(int shutdownTimeout)` Timeout for shutdown waiting for jobs to finish processing.
    `org.springframework.batch.core.JobExecution` | `stop(Long jobExecutionId)` Send a signal to a job execution to stop processing.
    `int` | `stopAll()` Send a stop signal to all running job executions.

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

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

- - ### Constructor Detail

    - #### SimpleJobService

          public SimpleJobService(SearchableJobInstanceDao jobInstanceDao,
                                  SearchableJobExecutionDao jobExecutionDao,
                                  SearchableStepExecutionDao stepExecutionDao,
                                  org.springframework.batch.core.repository.JobRepository jobRepository,
                                  org.springframework.batch.core.repository.dao.ExecutionContextDao executionContextDao,
                                  javax.batch.operations.JobOperator jsrJobOperator)

  - ### Method Detail

    - #### setShutdownTimeout

          public void setShutdownTimeout(int shutdownTimeout)

      Timeout for shutdown waiting for jobs to finish processing.
      Parameters:
        `shutdownTimeout` - in milliseconds (default 60 secs)

    - #### getStepExecutions

          public Collection<org.springframework.batch.core.StepExecution> getStepExecutions(Long jobExecutionId)
                                                                                     throws org.springframework.batch.core.launch.NoSuchJobExecutionException

      Description copied from interface: `JobService`
      Get the `step executions` for a given job execution (by id).
      Specified by:
        `getStepExecutions` in interface `JobService`
      Parameters:
        `jobExecutionId` - the parent job execution id
      Returns:
        the step executions for the job execution
      Throws:
        `org.springframework.batch.core.launch.NoSuchJobExecutionException` - thrown if job execution specified does not exist

    - #### restart

          public org.springframework.batch.core.JobExecution restart(Long jobExecutionId)
                                                              throws org.springframework.batch.core.launch.NoSuchJobException

      Delegates launching to `restart(Long, org.springframework.batch.core.JobParameters)`
      Specified by:
        `restart` in interface `JobService`
      Parameters:
        `jobExecutionId` - the job execution to restart
      Returns:
        Instance of `JobExecution` associated with the restart.
      Throws:
        `org.springframework.batch.core.launch.NoSuchJobException` - thrown if job does not exist

    - #### restart

          public org.springframework.batch.core.JobExecution restart(Long jobExecutionId,
                                                                     org.springframework.batch.core.JobParameters params)
                                                              throws org.springframework.batch.core.launch.NoSuchJobException

      Description copied from interface: `JobService`
      Launch a job with the parameters provided. JSR-352 supports restarting of jobs with a new set of parameters. This method exposes this functionality
      Specified by:
        `restart` in interface `JobService`
      Parameters:
        `jobExecutionId` - the job execution to restart
        `params` - the job parameters to use in the restart
      Returns:
        the resulting `JobExecution` if successful
      Throws:
        `org.springframework.batch.core.launch.NoSuchJobException` - thrown if job specified does not exist

    - #### launch

          public org.springframework.batch.core.JobExecution launch(String jobName,
                                                                    org.springframework.batch.core.JobParameters jobParameters)
                                                             throws org.springframework.batch.core.launch.NoSuchJobException

      Description copied from interface: `JobService`
      Launch a job with the parameters provided. If an instance with the parameters provided has already failed (and is not abandoned) it will be restarted.
      Specified by:
        `launch` in interface `JobService`
      Parameters:
        `jobName` - the job name
        `jobParameters` - the `JobParameters`
      Returns:
        the resulting `JobExecution` if successful
      Throws:
        `org.springframework.batch.core.launch.NoSuchJobException` - thrown if job specified does not exist

    - #### getLastJobParameters

          public org.springframework.batch.core.JobParameters getLastJobParameters(String jobName)

      Description copied from interface: `JobService`
      Get the last `JobParameters` used to execute a job successfully.
      Specified by:
        `getLastJobParameters` in interface `JobService`
      Parameters:
        `jobName` - the name of the job
      Returns:
        the last parameters used to execute this job or empty if there are none

    - #### listJobExecutions

          public Collection<org.springframework.batch.core.JobExecution> listJobExecutions(int start,
                                                                                           int count)

      Description copied from interface: `JobService`
      List the `job executions` in descending order of creation (usually close to execution order).
      Specified by:
        `listJobExecutions` in interface `JobService`
      Parameters:
        `start` - the index of the first execution to return
        `count` - the maximum number of executions
      Returns:
        a collection of `JobExecution`

    - #### listJobExecutionsWithStepCount

          public Collection<JobExecutionWithStepCount> listJobExecutionsWithStepCount(int start,
                                                                                      int count)

      Description copied from interface: `JobService`
      List the `JobExecutions` in descending order of creation (usually close to execution order) without step execution data.
      Specified by:
        `listJobExecutionsWithStepCount` in interface `JobService`
      Parameters:
        `start` - the index of the first execution to return
        `count` - the maximum number of executions
      Returns:
        a collection of `JobExecutionWithStepCount`

    - #### countJobExecutions

          public int countJobExecutions()

      Description copied from interface: `JobService`
      Count the maximum number of executions that could be returned by `JobService.listJobExecutions(int, int)`.
      Specified by:
        `countJobExecutions` in interface `JobService`
      Returns:
        the number of job executions in the job repository

    - #### listJobs

          public Collection<String> listJobs(int start,
                                             int count)

      Description copied from interface: `JobService`
      Query the job names in the system, either launchable or not. If not launchable, then there must be a history of the job having been launched previously in the `JobRepository`.
      Specified by:
        `listJobs` in interface `JobService`
      Parameters:
        `start` - the start index of the job names to return
        `count` - the maximum number of job names to return
      Returns:
        a collection of job names

    - #### countJobs

          public int countJobs()

      Description copied from interface: `JobService`
      Count the total number of jobs that can be returned by `JobService.listJobs(int, int)`.
      Specified by:
        `countJobs` in interface `JobService`
      Returns:
        the total number of jobs

    - #### stopAll

          public int stopAll()

      Description copied from interface: `JobService`
      Send a stop signal to all running job executions.
      Specified by:
        `stopAll` in interface `JobService`
      Returns:
        the number of executions affected

    - #### stop

          public org.springframework.batch.core.JobExecution stop(Long jobExecutionId)
                                                           throws org.springframework.batch.core.launch.NoSuchJobExecutionException,
                                                                  org.springframework.batch.core.launch.JobExecutionNotRunningException

      Description copied from interface: `JobService`
      Send a signal to a job execution to stop processing. This method does not guarantee that the processing will stop, only that the signal will be delivered. It is up to the individual `Job` and `Step` implementations to ensure that the signal is obeyed. In particular, if users provide a custom `Tasklet` to a `Step` it must check the signal in the `JobExecution` itself.
      Specified by:
        `stop` in interface `JobService`
      Parameters:
        `jobExecutionId` - the job execution id to stop
      Returns:
        the `JobExecution` that was stopped
      Throws:
        `org.springframework.batch.core.launch.NoSuchJobExecutionException` - thrown if job execution specified does not exist
        `org.springframework.batch.core.launch.JobExecutionNotRunningException` - thrown if the job execution specified is not running

    - #### abandon

          public org.springframework.batch.core.JobExecution abandon(Long jobExecutionId)
                                                              throws org.springframework.batch.core.launch.NoSuchJobExecutionException,
                                                                     org.springframework.batch.core.repository.JobExecutionAlreadyRunningException

      Description copied from interface: `JobService`
      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 `JobService`
      Parameters:
        `jobExecutionId` - the job execution id to abort
      Returns:
        the `JobExecution` that was aborted
      Throws:
        `org.springframework.batch.core.launch.NoSuchJobExecutionException` - thrown if job execution specified does not exist
        `org.springframework.batch.core.repository.JobExecutionAlreadyRunningException` - thrown if the job is running (it should be stopped first)

    - #### countJobExecutionsForJob

          public int countJobExecutionsForJob(String name,
                                              org.springframework.batch.core.BatchStatus status)
                                       throws org.springframework.batch.core.launch.NoSuchJobException

      Description copied from interface: `JobService`
      Count the job executions in the repository for a job.
      Specified by:
        `countJobExecutionsForJob` in interface `JobService`
      Parameters:
        `name` - the job name
        `status` - the status of the job
      Returns:
        the number of executions
      Throws:
        `org.springframework.batch.core.launch.NoSuchJobException` - thrown if job specified does not exist

    - #### countJobInstances

          public int countJobInstances(String name)

      Description copied from interface: `JobService`
      Count the number of `job instances` in the repository for a given job name.
      Specified by:
        `countJobInstances` in interface `JobService`
      Parameters:
        `name` - the name of the job
      Returns:
        the number of job instances available

    - #### getJobExecution

          public org.springframework.batch.core.JobExecution getJobExecution(Long jobExecutionId)
                                                                      throws org.springframework.batch.core.launch.NoSuchJobExecutionException

      Description copied from interface: `JobService`
      Get a `JobExecution` by id.
      Specified by:
        `getJobExecution` in interface `JobService`
      Parameters:
        `jobExecutionId` - the job execution id
      Returns:
        the `JobExecution`
      Throws:
        `org.springframework.batch.core.launch.NoSuchJobExecutionException` - thrown if job execution specified does not exist

    - #### getJobExecutionsForJobInstance

          public Collection<org.springframework.batch.core.JobExecution> getJobExecutionsForJobInstance(String name,
                                                                                                        Long jobInstanceId)
                                                                                                 throws org.springframework.batch.core.launch.NoSuchJobException

      Description copied from interface: `JobService`
      Get all the job executions for a given job instance. On a sunny day there would be only one. If there have been failures and restarts there may be many, and they will be listed in reverse order of primary key.
      Specified by:
        `getJobExecutionsForJobInstance` in interface `JobService`
      Parameters:
        `name` - the name of the job
        `jobInstanceId` - the id of the job instance
      Returns:
        all the job executions
      Throws:
        `org.springframework.batch.core.launch.NoSuchJobException` - thrown if job specified does not exist

    - #### getStepExecution

          public org.springframework.batch.core.StepExecution getStepExecution(Long jobExecutionId,
                                                                               Long stepExecutionId)
                                                                        throws org.springframework.batch.core.launch.NoSuchJobExecutionException,
                                                                               NoSuchStepExecutionException

      Description copied from interface: `JobService`
      Locate a `StepExecution` from its id and that of its parent `JobExecution`.
      Specified by:
        `getStepExecution` in interface `JobService`
      Parameters:
        `jobExecutionId` - the job execution id
        `stepExecutionId` - the step execution id
      Returns:
        the `StepExecution`
      Throws:
        `org.springframework.batch.core.launch.NoSuchJobExecutionException` - thrown if job execution specified does not exist
        `NoSuchStepExecutionException` - thrown if the step execution specified does not exist

    - #### listJobExecutionsForJobWithStepCount

          public Collection<JobExecutionWithStepCount> listJobExecutionsForJobWithStepCount(String jobName,
                                                                                            int start,
                                                                                            int count)
                                                                                     throws org.springframework.batch.core.launch.NoSuchJobException

      Description copied from interface: `JobService`
      List the `job executions` for a job in descending order of creation (usually close to execution order).
      Specified by:
        `listJobExecutionsForJobWithStepCount` in interface `JobService`
      Parameters:
        `jobName` - the job name
        `start` - the start index of the first job execution
        `count` - the maximum number of executions to return
      Returns:
        a collection of `JobExecutionWithStepCount`
      Throws:
        `org.springframework.batch.core.launch.NoSuchJobException` - thrown if job specified does not exist

    - #### listStepExecutionsForStep

          public Collection<org.springframework.batch.core.StepExecution> listStepExecutionsForStep(String jobName,
                                                                                                    String stepName,
                                                                                                    int start,
                                                                                                    int count)
                                                                                             throws org.springframework.batch.core.step.NoSuchStepException

      Description copied from interface: `JobService`
      List the `step executions` for a step in descending order of creation (usually close to execution order).
      Specified by:
        `listStepExecutionsForStep` in interface `JobService`
      Parameters:
        `jobName` - the name of the job associated with the step (or a pattern with wildcards)
        `stepName` - the step name (or a pattern with wildcards)
        `start` - the start index of the first execution
        `count` - the maximum number of executions to return
      Returns:
        a collection of `StepExecution`
      Throws:
        `org.springframework.batch.core.step.NoSuchStepException` - thrown if step specified does not exist

    - #### countStepExecutionsForStep

          public int countStepExecutionsForStep(String jobName,
                                                String stepName)
                                         throws org.springframework.batch.core.step.NoSuchStepException

      Description copied from interface: `JobService`
      Count the step executions in the repository for a given step name (or pattern).
      Specified by:
        `countStepExecutionsForStep` in interface `JobService`
      Parameters:
        `jobName` - the job name (or a pattern with wildcards)
        `stepName` - the step name (or a pattern with wildcards)
      Returns:
        the number of executions
      Throws:
        `org.springframework.batch.core.step.NoSuchStepException` - thrown if step specified does not exist

    - #### countStepExecutionsForJobExecution

          public int countStepExecutionsForJobExecution(long jobExecutionId)

      Description copied from interface: `JobService`
      Count the step executions in the repository for a given job execution.
      Specified by:
        `countStepExecutionsForJobExecution` in interface `JobService`
      Parameters:
        `jobExecutionId` - the id of the job execution.
      Returns:
        the number of executions.

    - #### getJobInstance

          public org.springframework.batch.core.JobInstance getJobInstance(long jobInstanceId)
                                                                    throws org.springframework.batch.core.launch.NoSuchJobInstanceException

      Description copied from interface: `JobService`
      Get a `job instance` by id.
      Specified by:
        `getJobInstance` in interface `JobService`
      Parameters:
        `jobInstanceId` - the id of the instance
      Returns:
        a `job instance`
      Throws:
        `org.springframework.batch.core.launch.NoSuchJobInstanceException` - thrown if the job instance specified does not exist

    - #### listJobInstances

          public Collection<org.springframework.batch.core.JobInstance> listJobInstances(String jobName,
                                                                                         int start,
                                                                                         int count)
                                                                                  throws org.springframework.batch.core.launch.NoSuchJobException

      Description copied from interface: `JobService`
      List the `job instances` in descending order of creation (usually close to order of execution).
      Specified by:
        `listJobInstances` in interface `JobService`
      Parameters:
        `jobName` - the name of the job
        `start` - the index of the first to return
        `count` - the maximum number of instances to return
      Returns:
        a collection of `job instances`
      Throws:
        `org.springframework.batch.core.launch.NoSuchJobException` - thrown if job specified does not exist

    - #### getStepNamesForJob

          public Collection<String> getStepNamesForJob(String jobName)
                                                throws org.springframework.batch.core.launch.NoSuchJobException

      Description copied from interface: `JobService`
      Get the names of the steps in a job (or a historical list of recent execution names if the Job is not launchable).
      Specified by:
        `getStepNamesForJob` in interface `JobService`
      Parameters:
        `jobName` - the name of the job
      Returns:
        `Collection` of step names.
      Throws:
        `org.springframework.batch.core.launch.NoSuchJobException` - thrown if the job name cannot be located

    - #### listJobExecutionsForJob

          public Collection<org.springframework.batch.core.JobExecution> listJobExecutionsForJob(String jobName,
                                                                                                 org.springframework.batch.core.BatchStatus status,
                                                                                                 int pageOffset,
                                                                                                 int pageSize)

      Description copied from interface: `JobService`
      List the `job executions` for a job in descending order of creation (usually close to execution order).
      Specified by:
        `listJobExecutionsForJob` in interface `JobService`
      Parameters:
        `jobName` - the job name
        `status` - the status of the job execution
        `pageOffset` - the start index of the first job execution
        `pageSize` - the maximum number of executions to return
      Returns:
        a collection of `JobExecution`

    - #### listJobExecutionsForJobWithStepCount

          public Collection<JobExecutionWithStepCount> listJobExecutionsForJobWithStepCount(Date fromDate,
                                                                                            Date toDate,
                                                                                            int start,
                                                                                            int count)

      Description copied from interface: `JobService`
      List the `job executions` filtered by date range in descending order of creation (usually close to execution order).
      Specified by:
        `listJobExecutionsForJobWithStepCount` in interface `JobService`
      Parameters:
        `fromDate` - the date which start date must be greater than.
        `toDate` - the date which start date must be less than.
        `start` - the start index of the first job execution
        `count` - the maximum number of executions to return
      Returns:
        a collection of `JobExecutionWithStepCount`

    - #### listJobExecutionsForJobWithStepCountFilteredByJobInstanceId

          public Collection<JobExecutionWithStepCount> listJobExecutionsForJobWithStepCountFilteredByJobInstanceId(int jobInstanceId,
                                                                                                                   int start,
                                                                                                                   int count)

      Description copied from interface: `JobService`
      List the `job executions` filtered by job instance id in descending order of creation (usually close to execution order).
      Specified by:
        `listJobExecutionsForJobWithStepCountFilteredByJobInstanceId` in interface `JobService`
      Parameters:
        `jobInstanceId` - the job instance id associated with the execution.
        `start` - the start index of the first job execution
        `count` - the maximum number of executions to return
      Returns:
        a collection of `JobExecutionWithStepCount`

    - #### listJobExecutionsForJobWithStepCountFilteredByTaskExecutionId

          public Collection<JobExecutionWithStepCount> listJobExecutionsForJobWithStepCountFilteredByTaskExecutionId(int taskExecutionId,
                                                                                                                     int start,
                                                                                                                     int count)

      Description copied from interface: `JobService`
      List the `job executions` filtered by task execution id in descending order of creation (usually close to execution order).
      Specified by:
        `listJobExecutionsForJobWithStepCountFilteredByTaskExecutionId` in interface `JobService`
      Parameters:
        `taskExecutionId` - the task execution id associated with the execution.
        `start` - the start index of the first job execution
        `count` - the maximum number of executions to return
      Returns:
        a collection of `JobExecutionWithStepCount`

    - #### destroy

          public void destroy()
                       throws Exception

      Stop all the active jobs and wait for them (up to a time out) to finish processing.
      Specified by:
        `destroy` in interface `org.springframework.beans.factory.DisposableBean`
      Throws:
        `Exception`

    - #### removeInactiveExecutions

          @Scheduled(fixedDelay=60000L)
          public void removeInactiveExecutions()

      Check all the active executions and see if they are still actually running. Remove the ones that have completed.

Copyright © 2021 Pivotal Software, Inc.. All rights reserved.