public class SimpleJobService extends Object implements JobService, DisposableBean
JobService that delegates most of its work to other
off-the-shelf components.| Constructor and Description |
|---|
SimpleJobService(SearchableJobInstanceDao jobInstanceDao,
SearchableJobExecutionDao jobExecutionDao,
SearchableStepExecutionDao stepExecutionDao,
JobRepository jobRepository,
JobLauncher jobLauncher,
ListableJobLocator jobLocator,
ExecutionContextDao executionContextDao) |
SimpleJobService(SearchableJobInstanceDao jobInstanceDao,
SearchableJobExecutionDao jobExecutionDao,
SearchableStepExecutionDao stepExecutionDao,
JobRepository jobRepository,
JobLauncher jobLauncher,
ListableJobLocator jobLocator,
ExecutionContextDao executionContextDao,
javax.batch.operations.JobOperator jsrJobOperator) |
| Modifier and Type | Method and Description |
|---|---|
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)
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 |
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.
|
JobExecution |
getJobExecution(Long jobExecutionId)
Get a
JobExecution by id. |
Collection<JobExecution> |
getJobExecutionsForJobInstance(String name,
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 jobParameters)
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). |
void |
removeInactiveExecutions()
Check all the active executions and see if they are still actually
running.
|
JobExecution |
restart(Long jobExecutionId)
Delegates launching to
restart(Long, org.springframework.batch.core.JobParameters) |
JobExecution |
restart(Long jobExecutionId,
JobParameters params)
Launch a job with the parameters provided.
|
void |
setShutdownTimeout(int shutdownTimeout)
Timeout for shutdown waiting for jobs to finish processing.
|
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.
|
public SimpleJobService(SearchableJobInstanceDao jobInstanceDao, SearchableJobExecutionDao jobExecutionDao, SearchableStepExecutionDao stepExecutionDao, JobRepository jobRepository, JobLauncher jobLauncher, ListableJobLocator jobLocator, ExecutionContextDao executionContextDao)
public SimpleJobService(SearchableJobInstanceDao jobInstanceDao, SearchableJobExecutionDao jobExecutionDao, SearchableStepExecutionDao stepExecutionDao, JobRepository jobRepository, JobLauncher jobLauncher, ListableJobLocator jobLocator, ExecutionContextDao executionContextDao, javax.batch.operations.JobOperator jsrJobOperator)
public void setShutdownTimeout(int shutdownTimeout)
shutdownTimeout - in milliseconds (default 60 secs)public Collection<StepExecution> getStepExecutions(Long jobExecutionId) throws NoSuchJobExecutionException
JobServicestep executions for a given job execution
(by id).getStepExecutions in interface JobServicejobExecutionId - the parent job execution idNoSuchJobExecutionExceptionpublic boolean isLaunchable(String jobName)
JobServiceJobService.listJobs(int, int) might be in the
repository, but not be launchable if the host application has no
configuration for them.isLaunchable in interface JobServicejobName - the name of the jobpublic boolean isIncrementable(String jobName)
JobServiceJobParametersIncrementer.isIncrementable in interface JobServicejobName - the job namepublic JobExecution restart(Long jobExecutionId) throws NoSuchJobExecutionException, JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException, NoSuchJobException, JobParametersInvalidException
restart(Long, org.springframework.batch.core.JobParameters)restart in interface JobServicejobExecutionId - the job execution to restartNoSuchJobExecutionExceptionJobExecutionAlreadyRunningExceptionJobRestartExceptionJobInstanceAlreadyCompleteExceptionNoSuchJobExceptionJobParametersInvalidExceptionpublic JobExecution restart(Long jobExecutionId, JobParameters params) throws NoSuchJobExecutionException, JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException, NoSuchJobException, JobParametersInvalidException
JobServicerestart in interface JobServicejobExecutionId - the job execution to restartparams - the job parameters to use in the restartJobExecution if successfulNoSuchJobExecutionExceptionJobExecutionAlreadyRunningExceptionJobRestartExceptionJobInstanceAlreadyCompleteExceptionNoSuchJobExceptionJobParametersInvalidExceptionpublic JobExecution launch(String jobName, JobParameters jobParameters) throws NoSuchJobException, JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException, JobParametersInvalidException
JobServicelaunch in interface JobServicejobName - the job namejobParameters - the JobParametersJobExecution if successfulNoSuchJobExceptionJobExecutionAlreadyRunningExceptionJobRestartExceptionJobInstanceAlreadyCompleteExceptionJobParametersInvalidExceptionpublic JobParameters getLastJobParameters(String jobName) throws NoSuchJobException
JobServiceJobParameters used to execute a job successfully.getLastJobParameters in interface JobServicejobName - the name of the jobNoSuchJobExceptionpublic Collection<JobExecution> listJobExecutions(int start, int count)
JobServicejob executions in descending order of
creation (usually close to execution order).listJobExecutions in interface JobServicestart - the index of the first execution to returncount - the maximum number of executionsJobExecutionpublic int countJobExecutions()
JobServiceJobService.listJobExecutions(int, int).countJobExecutions in interface JobServicepublic Collection<String> listJobs(int start, int count)
JobServiceJobRepository.listJobs in interface JobServicestart - the start index of the job names to returncount - the maximum number of job names to returnpublic int countJobs()
JobServiceJobService.listJobs(int, int).countJobs in interface JobServicepublic int stopAll()
JobServicestopAll in interface JobServicepublic JobExecution stop(Long jobExecutionId) throws NoSuchJobExecutionException, JobExecutionNotRunningException
JobServiceJob 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.stop in interface JobServicejobExecutionId - the job execution id to stopJobExecution that was stoppedNoSuchJobExecutionExceptionJobExecutionNotRunningExceptionpublic JobExecution abandon(Long jobExecutionId) throws NoSuchJobExecutionException, JobExecutionAlreadyRunningException
JobServiceJobExecution 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.abandon in interface JobServicejobExecutionId - the job execution id to abortJobExecution that was abortedNoSuchJobExecutionExceptionJobExecutionAlreadyRunningException - if the job is running (it
should be stopped first)public int countJobExecutionsForJob(String name) throws NoSuchJobException
JobServicecountJobExecutionsForJob in interface JobServicename - the job nameNoSuchJobExceptionpublic int countJobInstances(String name) throws NoSuchJobException
JobServicejob instances in the repository
for a given job name.countJobInstances in interface JobServicename - the name of the jobNoSuchJobExceptionpublic JobExecution getJobExecution(Long jobExecutionId) throws NoSuchJobExecutionException
JobServiceJobExecution by id.getJobExecution in interface JobServicejobExecutionId - the job execution idJobExecutionNoSuchJobExecutionExceptionpublic Collection<JobExecution> getJobExecutionsForJobInstance(String name, Long jobInstanceId) throws NoSuchJobException
JobServicegetJobExecutionsForJobInstance in interface JobServicename - the name of the jobjobInstanceId - the id of the job instanceNoSuchJobExceptionpublic StepExecution getStepExecution(Long jobExecutionId, Long stepExecutionId) throws NoSuchJobExecutionException, NoSuchStepExecutionException
JobServiceStepExecution from its id and that of its parent
JobExecution.getStepExecution in interface JobServicejobExecutionId - the job execution idstepExecutionId - the step execution idStepExecutionNoSuchJobExecutionExceptionNoSuchStepExecutionExceptionpublic Collection<JobExecution> listJobExecutionsForJob(String jobName, int start, int count) throws NoSuchJobException
JobServicejob executions for a job in descending
order of creation (usually close to execution order).listJobExecutionsForJob in interface JobServicejobName - the job namestart - the start index of the first job executioncount - the maximum number of executions to returnJobExecutionNoSuchJobExceptionpublic Collection<StepExecution> listStepExecutionsForStep(String jobName, String stepName, int start, int count) throws NoSuchStepException
JobServicestep executions for a step in descending
order of creation (usually close to execution order).listStepExecutionsForStep in interface JobServicejobName - 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 executioncount - the maximum number of executions to returnStepExecutionNoSuchStepExceptionpublic int countStepExecutionsForStep(String jobName, String stepName) throws NoSuchStepException
JobServicecountStepExecutionsForStep in interface JobServicejobName - the job name (or a pattern with wildcards)stepName - the step name (or a pattern with wildcards)NoSuchStepExceptionpublic JobInstance getJobInstance(long jobInstanceId) throws NoSuchJobInstanceException
JobServicejob instance by id.getJobInstance in interface JobServicejobInstanceId - the id of the instancejob instanceNoSuchJobInstanceExceptionpublic Collection<JobInstance> listJobInstances(String jobName, int start, int count) throws NoSuchJobException
JobServicejob instances in descending order of
creation (usually close to order of execution).listJobInstances in interface JobServicejobName - the name of the jobstart - the index of the first to returncount - the maximum number of instances to returnjob instancesNoSuchJobExceptionpublic Collection<String> getStepNamesForJob(String jobName) throws NoSuchJobException
JobServicegetStepNamesForJob in interface JobServicejobName - the name of the jobNoSuchJobException - if the job name cannot be locatedpublic void destroy()
throws Exception
destroy in interface DisposableBeanException@Scheduled(fixedDelay=60000L) public void removeInactiveExecutions()
Copyright © 2015. All rights reserved.