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 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:
This class can be instantiated with a
JobOperatorFactoryBean
to create a
transactional proxy around the job operator.- Since:
- 2.0
- Author:
- Dave Syer, Lucas Ward, Will Schipp, Mahmoud Ben Hassine
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionabandon
(long jobExecutionId) Mark theJobExecution
as ABANDONED.void
Check mandatory properties.getExecutions
(long instanceId) List theJobExecutions
associated with a particularJobInstance
, in reverse order of creation (and therefore usually of execution).getJobInstance
(String jobName, JobParameters jobParameters) getJobInstances
(String jobName, int start, int count) List theJobInstances
for a given job name, in reverse order of creation (and therefore usually of first execution).List the available job names that can be launched withJobOperator.start(String, Properties)
.getParameters
(long executionId) Get theJobParameters
as a human readable String (new line separated key=value pairs).getRunningExecutions
(String jobName) Get the id values of all the runningJobExecutions
with the given job name.getStepExecutionSummaries
(long executionId) Summarise theStepExecution
instances belonging to theJobExecution
with the supplied id, giving details of status, start and end times etc.getSummary
(long executionId) Summarise theJobExecution
with the supplied id, giving details of status, start and end times etc.restart
(long executionId) Restart a failed or stoppedJobExecution
.void
setJobExplorer
(JobExplorer jobExplorer) Public setter for theJobExplorer
.void
setJobLauncher
(JobLauncher jobLauncher) Public setter for theJobLauncher
.void
setJobParametersConverter
(JobParametersConverter jobParametersConverter) Public setter for theJobParametersConverter
.void
setJobRegistry
(ListableJobLocator jobRegistry) Public setter for theListableJobLocator
.void
setJobRepository
(JobRepository jobRepository) Deprecated, for removal: This API element is subject to removal in a future version.start
(String jobName, Properties parameters) Start a new instance of a job with the parameters specified.startNextInstance
(String jobName) Launch the next in a sequence ofJobInstance
determined by theJobParametersIncrementer
attached to the specified job.boolean
stop
(long executionId) Send a stop signal to theJobExecution
with the supplied id.
-
Constructor Details
-
SimpleJobOperator
public SimpleJobOperator()
-
-
Method Details
-
afterPropertiesSet
Check mandatory properties.- Specified by:
afterPropertiesSet
in interfaceorg.springframework.beans.factory.InitializingBean
- Throws:
Exception
- See Also:
-
InitializingBean.afterPropertiesSet()
-
setJobParametersConverter
Public setter for theJobParametersConverter
.- Parameters:
jobParametersConverter
- theJobParametersConverter
to set
-
setJobRegistry
Public setter for theListableJobLocator
.- Parameters:
jobRegistry
- theListableJobLocator
to set
-
setJobExplorer
Public setter for theJobExplorer
.- Parameters:
jobExplorer
- theJobExplorer
to set
-
setJobRepository
-
setJobLauncher
Public setter for theJobLauncher
.- Parameters:
jobLauncher
- theJobLauncher
to set
-
getExecutions
Description copied from interface:JobOperator
List theJobExecutions
associated with a particularJobInstance
, in reverse order of creation (and therefore usually of execution).- Specified by:
getExecutions
in interfaceJobOperator
- Parameters:
instanceId
- the id of aJobInstance
- Returns:
- the id values of all the
JobExecutions
associated with this instance - Throws:
NoSuchJobInstanceException
- if theJobInstance
associated with theinstanceId
cannot be found.
-
getJobNames
Description copied from interface:JobOperator
List the available job names that can be launched withJobOperator.start(String, Properties)
.- Specified by:
getJobNames
in interfaceJobOperator
- Returns:
- a set of job names
-
getJobInstances
Description copied from interface:JobOperator
List theJobInstances
for a given job name, in reverse order of creation (and therefore usually of first execution).- Specified by:
getJobInstances
in interfaceJobOperator
- Parameters:
jobName
- the job name that all the instances havestart
- the start index of the instancescount
- the maximum number of values to return- Returns:
- the id values of the
JobInstances
- Throws:
NoSuchJobException
- is thrown if noJobInstance
s for the jobName exist.
-
getJobInstance
- Specified by:
getJobInstance
in interfaceJobOperator
- Parameters:
jobName
-String
name of the job.jobParameters
-JobParameters
parameters for the job instance.- Returns:
- the
JobInstance
with the given name and parameters, ornull
.
-
getParameters
Description copied from interface:JobOperator
Get theJobParameters
as a human readable String (new line separated key=value pairs).- Specified by:
getParameters
in interfaceJobOperator
- Parameters:
executionId
- the id of an existingJobExecution
- Returns:
- the job parameters that were used to launch the associated instance
- Throws:
NoSuchJobExecutionException
- if the id was not associated with anyJobExecution
-
getRunningExecutions
Description copied from interface:JobOperator
Get the id values of all the runningJobExecutions
with the given job name.- Specified by:
getRunningExecutions
in interfaceJobOperator
- Parameters:
jobName
- the name of the job to search under- Returns:
- the id values of the running
JobExecution
instances - Throws:
NoSuchJobException
- if there are noJobExecutions
with that job name
-
getStepExecutionSummaries
public Map<Long,String> getStepExecutionSummaries(long executionId) throws NoSuchJobExecutionException Description copied from interface:JobOperator
Summarise theStepExecution
instances belonging to theJobExecution
with the supplied id, giving details of status, start and end times etc.- Specified by:
getStepExecutionSummaries
in interfaceJobOperator
- Parameters:
executionId
- the id of an existingJobExecution
- Returns:
- a map of step execution id to String summarising the state of the execution
- Throws:
NoSuchJobExecutionException
- if there is noJobExecution
with the supplied id
-
getSummary
Description copied from interface:JobOperator
Summarise theJobExecution
with the supplied id, giving details of status, start and end times etc.- Specified by:
getSummary
in interfaceJobOperator
- Parameters:
executionId
- the id of an existingJobExecution
- Returns:
- a String summarising the state of the job execution
- Throws:
NoSuchJobExecutionException
- if there is noJobExecution
with the supplied id
-
restart
public Long restart(long executionId) throws JobInstanceAlreadyCompleteException, NoSuchJobExecutionException, NoSuchJobException, JobRestartException, JobParametersInvalidException Description copied from interface:JobOperator
Restart a failed or stoppedJobExecution
. Fails with an exception if the id provided does not exist or corresponds to aJobInstance
that in normal circumstances already completed successfully.- Specified by:
restart
in interfaceJobOperator
- Parameters:
executionId
- the id of a failed or stoppedJobExecution
- Returns:
- the id of the
JobExecution
that was started - Throws:
JobInstanceAlreadyCompleteException
- if the job was already successfully completedNoSuchJobExecutionException
- if the id was not associated with anyJobExecution
NoSuchJobException
- if theJobExecution
was found, but its correspondingJob
is no longer available for launchingJobRestartException
- 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
@Deprecated(since="5.0.1", forRemoval=true) public Long start(String jobName, String parameters) throws NoSuchJobException, JobInstanceAlreadyExistsException, JobParametersInvalidException Deprecated, for removal: This API element is subject to removal in a future version.Description copied from interface:JobOperator
Start a new instance of a job with the parameters specified.- Specified by:
start
in interfaceJobOperator
- Parameters:
jobName
- the name of theJob
to launchparameters
- the parameters to launch it with (new line separated key=value pairs)- Returns:
- the id of the
JobExecution
that is launched - Throws:
NoSuchJobException
- if there is noJob
with the specified nameJobInstanceAlreadyExistsException
- if a job instance with this name and parameters already existsJobParametersInvalidException
- thrown if any of the job parameters are invalid.
-
start
public Long start(String jobName, Properties 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 interfaceJobOperator
- Parameters:
jobName
- the name of theJob
to launchparameters
- the parameters to launch it with- Returns:
- the id of the
JobExecution
that is launched - Throws:
NoSuchJobException
- if there is noJob
with the specified nameJobInstanceAlreadyExistsException
- if a job instance with this name and parameters already existsJobParametersInvalidException
- thrown if any of the job parameters are invalid.
-
startNextInstance
public Long startNextInstance(String jobName) throws NoSuchJobException, UnexpectedJobExecutionException, JobParametersInvalidException Description copied from interface:JobOperator
Launch the next in a sequence ofJobInstance
determined by theJobParametersIncrementer
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 theJobParametersIncrementer
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 interfaceJobOperator
- 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 availableUnexpectedJobExecutionException
- if an unexpected condition arisesJobParametersInvalidException
- thrown if some of the job parameters are invalid.
-
stop
public boolean stop(long executionId) throws NoSuchJobExecutionException, JobExecutionNotRunningException Description copied from interface:JobOperator
Send a stop signal to theJobExecution
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 interfaceJobOperator
- Parameters:
executionId
- the id of a runningJobExecution
- Returns:
- true if the message was successfully sent (does not guarantee that the job has stopped)
- Throws:
NoSuchJobExecutionException
- if there is noJobExecution
with the id suppliedJobExecutionNotRunningException
- if theJobExecution
is not running (so cannot be stopped)
-
abandon
public JobExecution abandon(long jobExecutionId) throws NoSuchJobExecutionException, JobExecutionAlreadyRunningException Description copied from interface:JobOperator
Mark theJobExecution
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 cannot be restarted by the framework.- Specified by:
abandon
in interfaceJobOperator
- Parameters:
jobExecutionId
- the job execution id to abort- Returns:
- the
JobExecution
that was aborted - Throws:
NoSuchJobExecutionException
- thrown if there is no job execution for the jobExecutionId.JobExecutionAlreadyRunningException
- if the job is running (it should be stopped first)
-