org.springframework.batch.admin.service
Interface JobService

All Known Implementing Classes:
SimpleJobService

public interface JobService

Interface for general purpose monitoring and management of Batch jobs. The features here can generally be composed from existing Spring Batch interfaces (although for performance reasons, implementations might choose special-purpose optimisations via a relation database, for instance).

Author:
Dave Syer

Method Summary
 JobExecution abandon(Long jobExecutionId)
          Mark the JobExecution as ABANDONED.
 int countJobExecutions()
          Count the maximum number of executions that could be returned by listJobExecutions(int, int).
 int countJobExecutionsForJob(String jobName)
          Count the job executions in the repository for a job.
 int countJobInstances(String jobName)
          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 listJobs(int, int).
 int countStepExecutionsForStep(String jobName, String stepName)
          Count the step executions in the repository for a given step name (or pattern).
 JobExecution getJobExecution(Long jobExecutionId)
          Get a JobExecution by id.
 Collection<JobExecution> getJobExecutionsForJobInstance(String jobName, Long jobInstanceId)
          Get all the job executions for a given job instance.
 JobInstance getJobInstance(long jobInstanceId)
          Get a job instance by id.
 JobParameters getLastJobParameters(String jobName)
          Get the last JobParameters used to execute a job successfully.
 StepExecution getStepExecution(Long jobExecutionId, Long stepExecutionId)
          Locate a StepExecution from its id and that of its parent JobExecution.
 Collection<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).
 boolean isIncrementable(String jobName)
          Check if a job has a JobParametersIncrementer.
 boolean isLaunchable(String jobName)
          Convenience method to determine if a job is available for launching.
 JobExecution launch(String jobName, JobParameters params)
          Launch a job with the parameters provided.
 Collection<JobExecution> listJobExecutions(int start, int count)
          List the job executions in descending order of creation (usually close to execution order).
 Collection<JobExecution> listJobExecutionsForJob(String jobName, int start, int count)
          List the job executions for a job in descending order of creation (usually close to execution order).
 Collection<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<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).
 JobExecution restart(Long jobExecutionId)
          Launch a job with the parameters provided.
 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.
 

Method Detail

isLaunchable

boolean isLaunchable(String jobName)
Convenience method to determine if a job is available for launching. Job names returned from listJobs(int, int) might be in the repository, but not be launchable if the host application has no configuration for them.

Parameters:
jobName - the name of the job
Returns:
true if the job is available for launching

launch

JobExecution launch(String jobName,
                    JobParameters params)
                    throws NoSuchJobException,
                           JobExecutionAlreadyRunningException,
                           JobRestartException,
                           JobInstanceAlreadyCompleteException,
                           JobParametersInvalidException
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.

Parameters:
jobName - the job name
params - the JobParameters
Returns:
the resulting JobExecution if successful
Throws:
NoSuchJobException
JobExecutionAlreadyRunningException
JobRestartException
JobInstanceAlreadyCompleteException
JobParametersInvalidException

getLastJobParameters

JobParameters getLastJobParameters(String jobName)
                                   throws NoSuchJobException
Get the last JobParameters used to execute a job successfully.

Parameters:
jobName - the name of the job
Returns:
the last parameters used to execute this job or empty if there are none
Throws:
NoSuchJobException

restart

JobExecution restart(Long jobExecutionId)
                     throws NoSuchJobExecutionException,
                            JobExecutionAlreadyRunningException,
                            JobRestartException,
                            JobInstanceAlreadyCompleteException,
                            NoSuchJobException,
                            JobParametersInvalidException
Launch a job with the parameters provided.

Parameters:
jobExecutionId - the job execution to restart
Returns:
the resulting JobExecution if successful
Throws:
NoSuchJobExecutionException
JobExecutionAlreadyRunningException
JobRestartException
JobInstanceAlreadyCompleteException
NoSuchJobException
JobParametersInvalidException

stop

JobExecution stop(Long jobExecutionId)
                  throws NoSuchJobExecutionException,
                         JobExecutionNotRunningException
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.

Parameters:
jobExecutionId - the job execution id to stop
Returns:
the JobExecution that was stopped
Throws:
NoSuchJobExecutionException
JobExecutionNotRunningException

abandon

JobExecution abandon(Long jobExecutionId)
                     throws NoSuchJobExecutionException,
                            JobExecutionAlreadyRunningException
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.

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)

listJobs

Collection<String> listJobs(int start,
                            int count)
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.

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

int countJobs()
Count the total number of jobs that can be returned by listJobs(int, int).

Returns:
the total number of jobs

getJobInstance

JobInstance getJobInstance(long jobInstanceId)
                           throws NoSuchJobInstanceException
Get a job instance by id.

Parameters:
jobInstanceId - the id of the instance
Returns:
a job instance
Throws:
NoSuchJobException
NoSuchJobInstanceException

listJobInstances

Collection<JobInstance> listJobInstances(String jobName,
                                         int start,
                                         int count)
                                         throws NoSuchJobException
List the job instances in descending order of creation (usually close to order of execution).

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:
NoSuchJobException

countJobInstances

int countJobInstances(String jobName)
                      throws NoSuchJobException
Count the number of job instances in the repository for a given job name.

Parameters:
jobName - the name of the job
Returns:
the number of job instances available
Throws:
NoSuchJobException

listJobExecutionsForJob

Collection<JobExecution> listJobExecutionsForJob(String jobName,
                                                 int start,
                                                 int count)
                                                 throws NoSuchJobException
List the job executions for a job in descending order of creation (usually close to execution order).

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 JobExecution
Throws:
NoSuchJobException

countJobExecutionsForJob

int countJobExecutionsForJob(String jobName)
                             throws NoSuchJobException
Count the job executions in the repository for a job.

Parameters:
jobName - the job name
Returns:
the number of executions
Throws:
NoSuchJobException

getJobExecutionsForJobInstance

Collection<JobExecution> getJobExecutionsForJobInstance(String jobName,
                                                        Long jobInstanceId)
                                                        throws NoSuchJobException
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.

Parameters:
jobName - the name of the job
jobInstanceId - the id of the job instance
Returns:
all the job executions
Throws:
NoSuchJobException

listJobExecutions

Collection<JobExecution> listJobExecutions(int start,
                                           int count)
List the job executions in descending order of creation (usually close to execution order).

Parameters:
start - the index of the first execution to return
count - the maximum number of executions
Returns:
a collection of JobExecution

countJobExecutions

int countJobExecutions()
Count the maximum number of executions that could be returned by listJobExecutions(int, int).

Returns:
the number of job executions in the job repository

getJobExecution

JobExecution getJobExecution(Long jobExecutionId)
                             throws NoSuchJobExecutionException
Get a JobExecution by id.

Parameters:
jobExecutionId - the job execution id
Returns:
the JobExecution
Throws:
NoSuchJobExecutionException

getStepExecutions

Collection<StepExecution> getStepExecutions(Long jobExecutionId)
                                            throws NoSuchJobExecutionException
Get the step executions for a given job execution (by id).

Parameters:
jobExecutionId - the parent job execution id
Returns:
the step executions for the job execution
Throws:
NoSuchJobExecutionException

listStepExecutionsForStep

Collection<StepExecution> listStepExecutionsForStep(String jobName,
                                                    String stepName,
                                                    int start,
                                                    int count)
                                                    throws NoSuchStepException
List the step executions for a step in descending order of creation (usually close to execution order).

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:
NoSuchStepException

countStepExecutionsForStep

int countStepExecutionsForStep(String jobName,
                               String stepName)
                               throws NoSuchStepException
Count the step executions in the repository for a given step name (or pattern).

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:
NoSuchStepException

getStepExecution

StepExecution getStepExecution(Long jobExecutionId,
                               Long stepExecutionId)
                               throws NoSuchStepExecutionException,
                                      NoSuchJobExecutionException
Locate a StepExecution from its id and that of its parent JobExecution.

Parameters:
jobExecutionId - the job execution id
stepExecutionId - the step execution id
Returns:
the StepExecution
Throws:
NoSuchStepExecutionException
NoSuchJobExecutionException

stopAll

int stopAll()
Send a stop signal to all running job executions.

Returns:
the number of executions affected

isIncrementable

boolean isIncrementable(String jobName)
Check if a job has a JobParametersIncrementer.

Parameters:
jobName - the job name
Returns:
true if the job exists and has an incrementer

getStepNamesForJob

Collection<String> getStepNamesForJob(String jobName)
                                      throws NoSuchJobException
Get the names of the steps in a job (or a historical list of recent execution names if the Job is not launchable).

Parameters:
jobName - the name of the job
Throws:
NoSuchJobException - if the job name cannot be located


Copyright © 2011. All Rights Reserved.