public class JsrJobOperator
extends java.lang.Object
implements javax.batch.operations.JobOperator, org.springframework.context.ApplicationContextAware, org.springframework.beans.factory.InitializingBean
ApplicationContext that is the equivalent to the following:
<beans>
<batch:job-repository id="jobRepository" ... />
<bean id="jobLauncher" class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
...
</bean>
<bean id="batchJobOperator" class="org.springframework.batch.core.launch.support.SimpleJobOperator">
...
</bean>
<bean id="jobExplorer" class="org.springframework.batch.core.explore.support.JobExplorerFactoryBean">
...
</bean>
<bean id="dataSource"
class="org.apache.commons.dbcp2.BasicDataSource">
...
</bean>
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
...
</bean>
<bean id="jobParametersConverter" class="org.springframework.batch.core.jsr.JsrJobParametersConverter"/>
<bean id="jobRegistry" class="org.springframework.batch.core.configuration.support.MapJobRegistry"/>
<bean id="placeholderProperties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
...
</bean>
</beans>
A custom configuration of the above components can be specified by providing a system property JSR-352-BASE-CONTEXT.
The location that is provided by this system property will override any beans as defined in baseContext.xml.
Calls to JobOperator.start(String, Properties) will provide a child context to the above context
using the job definition and batch.xml if provided.
By default, calls to start/restart will result in asynchronous execution of the batch job (via an asynchronous TaskExecutor.
For synchronous behavior or customization of thread behavior, a different TaskExecutor implementation is required to
be provided.
Note: This class is intended to only be used for JSR-352 configured jobs. Use of
this JobOperator to start/stop/restart Spring Batch jobs may result in unexpected behaviors due to
how job instances are identified differently.| Modifier and Type | Class and Description |
|---|---|
protected static class |
JsrJobOperator.BaseContextHolder
A singleton holder used to lazily bootstrap the base context used in JSR-352.
|
| Constructor and Description |
|---|
JsrJobOperator()
Public constructor used by
BatchRuntime.getJobOperator(). |
JsrJobOperator(JobExplorer jobExplorer,
JobRepository jobRepository,
JobParametersConverter jobParametersConverter,
org.springframework.transaction.PlatformTransactionManager transactionManager)
The no-arg constructor is used by the
BatchRuntime.getJobOperator() and so bootstraps
an ApplicationContext. |
| Modifier and Type | Method and Description |
|---|---|
void |
abandon(long jobExecutionId) |
void |
afterPropertiesSet() |
javax.batch.runtime.JobExecution |
getJobExecution(long executionId) |
java.util.List<javax.batch.runtime.JobExecution> |
getJobExecutions(javax.batch.runtime.JobInstance jobInstance) |
javax.batch.runtime.JobInstance |
getJobInstance(long executionId) |
int |
getJobInstanceCount(java.lang.String jobName) |
java.util.List<javax.batch.runtime.JobInstance> |
getJobInstances(java.lang.String jobName,
int start,
int count) |
java.util.Set<java.lang.String> |
getJobNames() |
protected java.util.Properties |
getJobRestartProperties(java.util.Properties params,
JobExecution previousJobExecution) |
java.util.Properties |
getParameters(long executionId) |
java.util.List<java.lang.Long> |
getRunningExecutions(java.lang.String name) |
java.util.List<javax.batch.runtime.StepExecution> |
getStepExecutions(long executionId) |
protected org.springframework.core.task.TaskExecutor |
getTaskExecutor() |
long |
restart(long executionId,
java.util.Properties params)
Creates a child
ApplicationContext for the job being requested based upon
the /META-INF/batch.xml (if exists) and the /META-INF/batch-jobs/<jobName>.xml
configuration and restart the job. |
void |
setApplicationContext(org.springframework.context.ApplicationContext applicationContext) |
void |
setJobExplorer(JobExplorer jobExplorer) |
void |
setJobParametersConverter(JobParametersConverter converter)
Used to convert the
Properties objects used by JSR-352 to the JobParameters
objects used in Spring Batch. |
void |
setJobRepository(JobRepository jobRepository) |
void |
setTaskExecutor(org.springframework.core.task.TaskExecutor taskExecutor) |
void |
setTransactionManager(org.springframework.transaction.PlatformTransactionManager transactionManager) |
long |
start(java.lang.String jobName,
java.util.Properties params)
Creates a child
ApplicationContext for the job being requested based upon
the /META-INF/batch.xml (if exists) and the /META-INF/batch-jobs/<jobName>.xml
configuration and launches the job. |
void |
stop(long executionId)
Stops the running job execution if it is currently running.
|
public JsrJobOperator()
BatchRuntime.getJobOperator(). This will bootstrap a
singleton ApplicationContext if one has not already been created (and will utilize the existing
one if it has) to populate itself.public JsrJobOperator(JobExplorer jobExplorer, JobRepository jobRepository, JobParametersConverter jobParametersConverter, org.springframework.transaction.PlatformTransactionManager transactionManager)
BatchRuntime.getJobOperator() and so bootstraps
an ApplicationContext. This constructor does not and is therefore dependency injection
friendly. Also useful for unit testing.jobExplorer - an instance of Spring Batch's JobExplorer.jobRepository - an instance of Spring Batch's JobOperator.jobParametersConverter - an instance of Spring Batch's JobParametersConverter.transactionManager - a PlatformTransactionManager.public void setJobExplorer(JobExplorer jobExplorer)
public void setJobRepository(JobRepository jobRepository)
public void setTransactionManager(org.springframework.transaction.PlatformTransactionManager transactionManager)
public void setTaskExecutor(org.springframework.core.task.TaskExecutor taskExecutor)
protected org.springframework.core.task.TaskExecutor getTaskExecutor()
public void afterPropertiesSet()
throws java.lang.Exception
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBeanjava.lang.Exceptionpublic void setJobParametersConverter(JobParametersConverter converter)
Properties objects used by JSR-352 to the JobParameters
objects used in Spring Batch. The default implementation used will configure all parameters
to be non-identifying (per the JSR).converter - A Converter implementation used to convert Properties to
JobParameterspublic void abandon(long jobExecutionId)
throws javax.batch.operations.NoSuchJobExecutionException,
javax.batch.operations.JobExecutionIsRunningException,
javax.batch.operations.JobSecurityException
abandon in interface javax.batch.operations.JobOperatorjavax.batch.operations.NoSuchJobExecutionExceptionjavax.batch.operations.JobExecutionIsRunningExceptionjavax.batch.operations.JobSecurityExceptionpublic javax.batch.runtime.JobExecution getJobExecution(long executionId)
throws javax.batch.operations.NoSuchJobExecutionException,
javax.batch.operations.JobSecurityException
getJobExecution in interface javax.batch.operations.JobOperatorjavax.batch.operations.NoSuchJobExecutionExceptionjavax.batch.operations.JobSecurityExceptionpublic java.util.List<javax.batch.runtime.JobExecution> getJobExecutions(javax.batch.runtime.JobInstance jobInstance)
throws javax.batch.operations.NoSuchJobInstanceException,
javax.batch.operations.JobSecurityException
getJobExecutions in interface javax.batch.operations.JobOperatorjavax.batch.operations.NoSuchJobInstanceExceptionjavax.batch.operations.JobSecurityExceptionpublic javax.batch.runtime.JobInstance getJobInstance(long executionId)
throws javax.batch.operations.NoSuchJobExecutionException,
javax.batch.operations.JobSecurityException
getJobInstance in interface javax.batch.operations.JobOperatorjavax.batch.operations.NoSuchJobExecutionExceptionjavax.batch.operations.JobSecurityExceptionpublic int getJobInstanceCount(java.lang.String jobName)
throws javax.batch.operations.NoSuchJobException,
javax.batch.operations.JobSecurityException
getJobInstanceCount in interface javax.batch.operations.JobOperatorjavax.batch.operations.NoSuchJobExceptionjavax.batch.operations.JobSecurityExceptionpublic java.util.List<javax.batch.runtime.JobInstance> getJobInstances(java.lang.String jobName,
int start,
int count)
throws javax.batch.operations.NoSuchJobException,
javax.batch.operations.JobSecurityException
getJobInstances in interface javax.batch.operations.JobOperatorjavax.batch.operations.NoSuchJobExceptionjavax.batch.operations.JobSecurityExceptionpublic java.util.Set<java.lang.String> getJobNames()
throws javax.batch.operations.JobSecurityException
getJobNames in interface javax.batch.operations.JobOperatorjavax.batch.operations.JobSecurityExceptionpublic java.util.Properties getParameters(long executionId)
throws javax.batch.operations.NoSuchJobExecutionException,
javax.batch.operations.JobSecurityException
getParameters in interface javax.batch.operations.JobOperatorjavax.batch.operations.NoSuchJobExecutionExceptionjavax.batch.operations.JobSecurityExceptionpublic java.util.List<java.lang.Long> getRunningExecutions(java.lang.String name)
throws javax.batch.operations.NoSuchJobException,
javax.batch.operations.JobSecurityException
getRunningExecutions in interface javax.batch.operations.JobOperatorjavax.batch.operations.NoSuchJobExceptionjavax.batch.operations.JobSecurityExceptionpublic java.util.List<javax.batch.runtime.StepExecution> getStepExecutions(long executionId)
throws javax.batch.operations.NoSuchJobExecutionException,
javax.batch.operations.JobSecurityException
getStepExecutions in interface javax.batch.operations.JobOperatorjavax.batch.operations.NoSuchJobExecutionExceptionjavax.batch.operations.JobSecurityExceptionpublic long restart(long executionId,
java.util.Properties params)
throws javax.batch.operations.JobExecutionAlreadyCompleteException,
javax.batch.operations.NoSuchJobExecutionException,
javax.batch.operations.JobExecutionNotMostRecentException,
javax.batch.operations.JobRestartException,
javax.batch.operations.JobSecurityException
ApplicationContext for the job being requested based upon
the /META-INF/batch.xml (if exists) and the /META-INF/batch-jobs/<jobName>.xml
configuration and restart the job.restart in interface javax.batch.operations.JobOperatorexecutionId - the database id of the job execution to be restarted.params - any job parameters to be used during the execution of this job.javax.batch.operations.JobExecutionAlreadyCompleteException - thrown if the requested job execution has
a status of COMPLETEjavax.batch.operations.NoSuchJobExecutionException - throw if the requested job execution does not exist
in the repositoryjavax.batch.operations.JobExecutionNotMostRecentException - thrown if the requested job execution is not
the most recent attempt for the job instance it's related to.javax.batch.operations.JobRestartException - thrown for any general errors during the job restart processjavax.batch.operations.JobSecurityExceptionprotected java.util.Properties getJobRestartProperties(java.util.Properties params,
JobExecution previousJobExecution)
public long start(java.lang.String jobName,
java.util.Properties params)
throws javax.batch.operations.JobStartException,
javax.batch.operations.JobSecurityException
ApplicationContext for the job being requested based upon
the /META-INF/batch.xml (if exists) and the /META-INF/batch-jobs/<jobName>.xml
configuration and launches the job. Per JSR-352, calls to this method will always
create a new JobInstance (and related JobExecution).start in interface javax.batch.operations.JobOperatorjobName - the name of the job XML file without the .xml that is located within the
/META-INF/batch-jobs directory.params - any job parameters to be used during the execution of this job.javax.batch.operations.JobStartExceptionjavax.batch.operations.JobSecurityExceptionpublic void stop(long executionId)
throws javax.batch.operations.NoSuchJobExecutionException,
javax.batch.operations.JobExecutionNotRunningException,
javax.batch.operations.JobSecurityException
stop in interface javax.batch.operations.JobOperatorexecutionId - the database id for the JobExecution to be stopped.javax.batch.operations.NoSuchJobExecutionException - thrown if JobExecution instance does not exist.javax.batch.operations.JobExecutionNotRunningException - thrown if JobExecution is not running.javax.batch.operations.JobSecurityExceptionpublic void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
throws org.springframework.beans.BeansException
setApplicationContext in interface org.springframework.context.ApplicationContextAwareorg.springframework.beans.BeansException