类 JsrJobOperator
- java.lang.Object
- org.springframework.batch.core.jsr.launch.JsrJobOperator
- 所有已实现的接口:
javax.batch.operations.JobOperator
,org.springframework.beans.factory.Aware
,org.springframework.beans.factory.InitializingBean
,org.springframework.context.ApplicationContextAware
public class JsrJobOperator extends java.lang.Object implements javax.batch.operations.JobOperator, org.springframework.context.ApplicationContextAware, org.springframework.beans.factory.InitializingBean
The entrance for executing batch jobs as defined by JSR-352. This class provides a single baseApplicationContext
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 toJobOperator.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 asynchronousTaskExecutor
. For synchronous behavior or customization of thread behavior, a differentTaskExecutor
implementation is required to be provided. Note: This class is intended to only be used for JSR-352 configured jobs. Use of thisJobOperator
to start/stop/restart Spring Batch jobs may result in unexpected behaviors due to how job instances are identified differently.- 从以下版本开始:
- 3.0
- 作者:
- Michael Minella, Chris Schaefer
嵌套类概要
嵌套类 修饰符和类型 类 说明 protected static class
JsrJobOperator.BaseContextHolder
A singleton holder used to lazily bootstrap the base context used in JSR-352.
构造器概要
构造器 构造器 说明 JsrJobOperator()
Public constructor used byBatchRuntime.getJobOperator()
.JsrJobOperator(JobExplorer jobExplorer, JobRepository jobRepository, JobParametersConverter jobParametersConverter, org.springframework.transaction.PlatformTransactionManager transactionManager)
The no-arg constructor is used by theBatchRuntime.getJobOperator()
and so bootstraps anApplicationContext
.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 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 childApplicationContext
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 theProperties
objects used by JSR-352 to theJobParameters
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 childApplicationContext
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.
构造器详细资料
JsrJobOperator
public JsrJobOperator()
Public constructor used byBatchRuntime.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.
JsrJobOperator
public JsrJobOperator(JobExplorer jobExplorer, JobRepository jobRepository, JobParametersConverter jobParametersConverter, org.springframework.transaction.PlatformTransactionManager transactionManager)
The no-arg constructor is used by theBatchRuntime.getJobOperator()
and so bootstraps anApplicationContext
. This constructor does not and is therefore dependency injection friendly. Also useful for unit testing.- 参数:
jobExplorer
- an instance of Spring Batch'sJobExplorer
.jobRepository
- an instance of Spring Batch'sJobOperator
.jobParametersConverter
- an instance of Spring Batch'sJobParametersConverter
.transactionManager
- aTransactionManager
.
方法详细资料
setJobExplorer
public void setJobExplorer(JobExplorer jobExplorer)
setJobRepository
public void setJobRepository(JobRepository jobRepository)
setTransactionManager
public void setTransactionManager(org.springframework.transaction.PlatformTransactionManager transactionManager)
setTaskExecutor
public void setTaskExecutor(org.springframework.core.task.TaskExecutor taskExecutor)
getTaskExecutor
protected org.springframework.core.task.TaskExecutor getTaskExecutor()
afterPropertiesSet
public void afterPropertiesSet() throws java.lang.Exception
- 指定者:
afterPropertiesSet
在接口中org.springframework.beans.factory.InitializingBean
- 抛出:
java.lang.Exception
setJobParametersConverter
public void setJobParametersConverter(JobParametersConverter converter)
Used to convert theProperties
objects used by JSR-352 to theJobParameters
objects used in Spring Batch. The default implementation used will configure all parameters to be non-identifying (per the JSR).- 参数:
converter
- AConverter
implementation used to convertProperties
toJobParameters
abandon
public void abandon(long jobExecutionId) throws javax.batch.operations.NoSuchJobExecutionException, javax.batch.operations.JobExecutionIsRunningException, javax.batch.operations.JobSecurityException
- 指定者:
abandon
在接口中javax.batch.operations.JobOperator
- 抛出:
javax.batch.operations.NoSuchJobExecutionException
javax.batch.operations.JobExecutionIsRunningException
javax.batch.operations.JobSecurityException
getJobExecution
public javax.batch.runtime.JobExecution getJobExecution(long executionId) throws javax.batch.operations.NoSuchJobExecutionException, javax.batch.operations.JobSecurityException
- 指定者:
getJobExecution
在接口中javax.batch.operations.JobOperator
- 抛出:
javax.batch.operations.NoSuchJobExecutionException
javax.batch.operations.JobSecurityException
getJobExecutions
public java.util.List<javax.batch.runtime.JobExecution> getJobExecutions(javax.batch.runtime.JobInstance jobInstance) throws javax.batch.operations.NoSuchJobInstanceException, javax.batch.operations.JobSecurityException
- 指定者:
getJobExecutions
在接口中javax.batch.operations.JobOperator
- 抛出:
javax.batch.operations.NoSuchJobInstanceException
javax.batch.operations.JobSecurityException
getJobInstance
public javax.batch.runtime.JobInstance getJobInstance(long executionId) throws javax.batch.operations.NoSuchJobExecutionException, javax.batch.operations.JobSecurityException
- 指定者:
getJobInstance
在接口中javax.batch.operations.JobOperator
- 抛出:
javax.batch.operations.NoSuchJobExecutionException
javax.batch.operations.JobSecurityException
getJobInstanceCount
public int getJobInstanceCount(java.lang.String jobName) throws javax.batch.operations.NoSuchJobException, javax.batch.operations.JobSecurityException
- 指定者:
getJobInstanceCount
在接口中javax.batch.operations.JobOperator
- 抛出:
javax.batch.operations.NoSuchJobException
javax.batch.operations.JobSecurityException
getJobInstances
public 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
在接口中javax.batch.operations.JobOperator
- 抛出:
javax.batch.operations.NoSuchJobException
javax.batch.operations.JobSecurityException
getJobNames
public java.util.Set<java.lang.String> getJobNames() throws javax.batch.operations.JobSecurityException
- 指定者:
getJobNames
在接口中javax.batch.operations.JobOperator
- 抛出:
javax.batch.operations.JobSecurityException
getParameters
public java.util.Properties getParameters(long executionId) throws javax.batch.operations.NoSuchJobExecutionException, javax.batch.operations.JobSecurityException
- 指定者:
getParameters
在接口中javax.batch.operations.JobOperator
- 抛出:
javax.batch.operations.NoSuchJobExecutionException
javax.batch.operations.JobSecurityException
getRunningExecutions
public java.util.List<java.lang.Long> getRunningExecutions(java.lang.String name) throws javax.batch.operations.NoSuchJobException, javax.batch.operations.JobSecurityException
- 指定者:
getRunningExecutions
在接口中javax.batch.operations.JobOperator
- 抛出:
javax.batch.operations.NoSuchJobException
javax.batch.operations.JobSecurityException
getStepExecutions
public java.util.List<javax.batch.runtime.StepExecution> getStepExecutions(long executionId) throws javax.batch.operations.NoSuchJobExecutionException, javax.batch.operations.JobSecurityException
- 指定者:
getStepExecutions
在接口中javax.batch.operations.JobOperator
- 抛出:
javax.batch.operations.NoSuchJobExecutionException
javax.batch.operations.JobSecurityException
restart
public 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
Creates a childApplicationContext
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
在接口中javax.batch.operations.JobOperator
- 参数:
executionId
- 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.JobSecurityException
getJobRestartProperties
protected java.util.Properties getJobRestartProperties(java.util.Properties params, JobExecution previousJobExecution)
start
public long start(java.lang.String jobName, java.util.Properties params) throws javax.batch.operations.JobStartException, javax.batch.operations.JobSecurityException
Creates a childApplicationContext
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 newJobInstance
(and relatedJobExecution
).- 指定者:
start
在接口中javax.batch.operations.JobOperator
- 参数:
jobName
- 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.JobStartException
javax.batch.operations.JobSecurityException
stop
public void stop(long executionId) throws javax.batch.operations.NoSuchJobExecutionException, javax.batch.operations.JobExecutionNotRunningException, javax.batch.operations.JobSecurityException
Stops the running job execution if it is currently running.- 指定者:
stop
在接口中javax.batch.operations.JobOperator
- 参数:
executionId
- the database id for theJobExecution
to be stopped.- 抛出:
javax.batch.operations.NoSuchJobExecutionException
- thrown ifJobExecution
instance does not exist.javax.batch.operations.JobExecutionNotRunningException
- thrown ifJobExecution
is not running.javax.batch.operations.JobSecurityException
setApplicationContext
public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) throws org.springframework.beans.BeansException
- 指定者:
setApplicationContext
在接口中org.springframework.context.ApplicationContextAware
- 抛出:
org.springframework.beans.BeansException