Rename SimpleJobOperator to TaskExecutorJobOperator

Resolves #4834
This commit is contained in:
Mahmoud Ben Hassine
2025-05-07 23:52:26 +02:00
parent 2514346441
commit e5bda0d40a
13 changed files with 86 additions and 33 deletions

View File

@@ -89,7 +89,7 @@ import org.springframework.transaction.PlatformTransactionManager;
* {@link org.springframework.batch.core.configuration.support.MapJobRegistry})</li>
* <li>a {@link org.springframework.batch.core.launch.JobOperator} (bean name
* "jobOperator" of type
* {@link org.springframework.batch.core.launch.support.SimpleJobOperator})</li>
* {@link org.springframework.batch.core.launch.support.TaskExecutorJobOperator})</li>
* <li>a
* {@link org.springframework.batch.core.configuration.support.JobRegistrySmartInitializingSingleton}
* (bean name "jobRegistrySmartInitializingSingleton" of type

View File

@@ -45,7 +45,7 @@ import org.springframework.util.Assert;
* {@link JobOperator}.
*
* @see JobOperator
* @see SimpleJobOperator
* @see TaskExecutorJobOperator
* @author Mahmoud Ben Hassine
* @since 5.0
*/
@@ -174,15 +174,15 @@ public class JobOperatorFactoryBean implements FactoryBean<JobOperator>, Initial
return (JobOperator) this.proxyFactory.getProxy(getClass().getClassLoader());
}
private SimpleJobOperator getTarget() throws Exception {
SimpleJobOperator simpleJobOperator = new SimpleJobOperator();
simpleJobOperator.setJobRegistry(this.jobRegistry);
simpleJobOperator.setJobRepository(this.jobRepository);
simpleJobOperator.setTaskExecutor(this.taskExecutor);
simpleJobOperator.setMeterRegistry(this.meterRegistry);
simpleJobOperator.setJobParametersConverter(this.jobParametersConverter);
simpleJobOperator.afterPropertiesSet();
return simpleJobOperator;
private TaskExecutorJobOperator getTarget() throws Exception {
TaskExecutorJobOperator taskExecutorJobOperator = new TaskExecutorJobOperator();
taskExecutorJobOperator.setJobRegistry(this.jobRegistry);
taskExecutorJobOperator.setJobRepository(this.jobRepository);
taskExecutorJobOperator.setTaskExecutor(this.taskExecutor);
taskExecutorJobOperator.setMeterRegistry(this.meterRegistry);
taskExecutorJobOperator.setJobParametersConverter(this.jobParametersConverter);
taskExecutorJobOperator.afterPropertiesSet();
return taskExecutorJobOperator;
}
}

View File

@@ -81,15 +81,18 @@ import org.springframework.util.Assert;
* @author Will Schipp
* @author Mahmoud Ben Hassine
* @since 2.0
* @deprecated since 6.0 in favor of {@link TaskExecutorJobOperator}. Scheduled for
* removal in 6.2 or later.
*/
@Deprecated(since = "6.0", forRemoval = true)
public class SimpleJobOperator extends TaskExecutorJobLauncher implements JobOperator, InitializingBean {
private static final String ILLEGAL_STATE_MSG = "Illegal state (only happens on a race condition): "
+ "%s with name=%s and parameters=%s";
private ListableJobLocator jobRegistry;
protected ListableJobLocator jobRegistry;
private JobParametersConverter jobParametersConverter = new DefaultJobParametersConverter();
protected JobParametersConverter jobParametersConverter = new DefaultJobParametersConverter();
private final Log logger = LogFactory.getLog(getClass());

View File

@@ -0,0 +1,52 @@
/*
* Copyright 2022-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.core.launch.support;
import org.springframework.batch.core.configuration.JobRegistry;
import org.springframework.batch.core.configuration.ListableJobLocator;
import org.springframework.batch.core.launch.JobOperator;
import org.springframework.batch.core.repository.JobRepository;
/**
* A {@link org.springframework.core.task.TaskExecutor}-based implementation of the
* {@link JobOperator} interface. The following dependencies are required:
*
* <ul>
* <li>{@link JobRepository}
* <li>{@link JobRegistry}
* </ul>
*
* This class can be instantiated with a {@link JobOperatorFactoryBean} to create a
* transactional proxy around the job operator.
*
* @see JobOperatorFactoryBean
* @author Dave Syer
* @author Lucas Ward
* @author Will Schipp
* @author Mahmoud Ben Hassine
* @since 6.0
*/
public class TaskExecutorJobOperator extends SimpleJobOperator {
/**
* Public setter for the {@link ListableJobLocator}.
* @param jobRegistry the {@link ListableJobLocator} to set
*/
public void setJobRegistry(ListableJobLocator jobRegistry) {
this.jobRegistry = jobRegistry;
}
}

View File

@@ -61,7 +61,7 @@ class JobOperatorFactoryBeanTests {
// then
Assertions.assertNotNull(jobOperator);
Object targetObject = AopTestUtils.getTargetObject(jobOperator);
Assertions.assertInstanceOf(SimpleJobOperator.class, targetObject);
Assertions.assertInstanceOf(TaskExecutorJobOperator.class, targetObject);
Assertions.assertEquals(this.transactionManager, getTransactionManagerSetOnJobOperator(jobOperator));
}

View File

@@ -47,9 +47,7 @@ import org.springframework.batch.core.launch.NoSuchJobException;
import org.springframework.batch.core.launch.NoSuchJobExecutionException;
import org.springframework.batch.core.launch.NoSuchJobInstanceException;
import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException;
import org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.repository.JobRestartException;
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.core.step.tasklet.StoppableTasklet;
import org.springframework.batch.core.step.tasklet.TaskletStep;
@@ -74,9 +72,9 @@ import static org.mockito.Mockito.when;
* @author Jinwoo Bae
*
*/
class SimpleJobOperatorTests {
class TaskExecutorJobOperatorTests {
private SimpleJobOperator jobOperator;
private TaskExecutorJobOperator jobOperator;
protected Job job;
@@ -99,7 +97,7 @@ class SimpleJobOperatorTests {
}
};
jobOperator = new SimpleJobOperator() {
jobOperator = new TaskExecutorJobOperator() {
@Override
public JobExecution run(Job job, JobParameters jobParameters) {
return new JobExecution(new JobInstance(123L, job.getName()), 999L, jobParameters);
@@ -143,13 +141,13 @@ class SimpleJobOperatorTests {
@Test
void testMandatoryProperties() {
jobOperator = new SimpleJobOperator();
jobOperator = new TaskExecutorJobOperator();
assertThrows(IllegalStateException.class, jobOperator::afterPropertiesSet);
}
/**
* Test method for
* {@link org.springframework.batch.core.launch.support.SimpleJobOperator#startNextInstance(java.lang.String)}
* {@link org.springframework.batch.core.launch.support.TaskExecutorJobOperator#startNextInstance(java.lang.String)}
* .
*/
@Test

View File

@@ -48,7 +48,7 @@
<bean id="jobRegistry" class="org.springframework.batch.core.configuration.support.MapJobRegistry"/>
<bean id="jobOperator" class="org.springframework.batch.core.launch.support.SimpleJobOperator">
<bean id="jobOperator" class="org.springframework.batch.core.launch.support.TaskExecutorJobOperator">
<property name="jobRepository" ref="jobRepository"/>
<property name="jobRegistry" ref="jobRegistry"/>
<property name="taskExecutor">

View File

@@ -15,7 +15,7 @@
p:dataSource-ref="dataSource" p:transactionManager-ref="transactionManager" />
<bean id="jobOperator"
class="org.springframework.batch.core.launch.support.SimpleJobOperator"
class="org.springframework.batch.core.launch.support.TaskExecutorJobOperator"
p:jobRepository-ref="jobRepository" p:jobRegistry-ref="jobRegistry" />
<bean id="jobExplorer"

View File

@@ -348,14 +348,14 @@ public interface JobOperator {
The preceding operations represent methods from many different interfaces, such as
`JobLauncher`, `JobRepository`, `JobExplorer`, and `JobRegistry`. For this reason, the
provided implementation of `JobOperator` (`SimpleJobOperator`) has many dependencies.
provided implementation of `JobOperator` (`TaskExecutorJobOperator`) has many dependencies.
[tabs]
====
Java::
+
The following example shows a typical bean definition for `SimpleJobOperator` in Java:
The following example shows a typical bean definition for `TaskExecutorJobOperator` in Java:
+
[source, java]
----
@@ -364,12 +364,12 @@ The following example shows a typical bean definition for `SimpleJobOperator` in
* infrastructure out of the box.
*/
@Bean
public SimpleJobOperator jobOperator(JobExplorer jobExplorer,
public TaskExecutorJobOperator jobOperator(JobExplorer jobExplorer,
JobRepository jobRepository,
JobRegistry jobRegistry,
JobLauncher jobLauncher) {
SimpleJobOperator jobOperator = new SimpleJobOperator();
TaskExecutorJobOperator jobOperator = new TaskExecutorJobOperator();
jobOperator.setJobExplorer(jobExplorer);
jobOperator.setJobRepository(jobRepository);
jobOperator.setJobRegistry(jobRegistry);
@@ -381,11 +381,11 @@ The following example shows a typical bean definition for `SimpleJobOperator` in
XML::
+
The following example shows a typical bean definition for `SimpleJobOperator` in XML:
The following example shows a typical bean definition for `TaskExecutorJobOperator` in XML:
+
[source, xml]
----
<bean id="jobOperator" class="org.spr...SimpleJobOperator">
<bean id="jobOperator" class="org.spr...TaskExecutorJobOperator">
<property name="jobExplorer">
<bean class="org.spr...JobExplorerFactoryBean">
<property name="dataSource" ref="dataSource" />

View File

@@ -43,7 +43,7 @@
</bean>
<bean id="notificationPublisher" class="org.springframework.batch.samples.misc.jmx.JobExecutionNotificationPublisher" />
<bean id="jobOperator" class="org.springframework.batch.core.launch.support.SimpleJobOperator">
<bean id="jobOperator" class="org.springframework.batch.core.launch.support.TaskExecutorJobOperator">
<property name="jobRepository" ref="jobRepository" />
<property name="jobRegistry" ref="jobRegistry" />
<property name="taskExecutor">

View File

@@ -14,7 +14,7 @@
p:dataSource-ref="dataSource" p:transactionManager-ref="transactionManager"/>
<bean id="jobOperator"
class="org.springframework.batch.core.launch.support.SimpleJobOperator"
class="org.springframework.batch.core.launch.support.TaskExecutorJobOperator"
p:jobRepository-ref="jobRepository" p:jobRegistry-ref="jobRegistry">
<property name="taskExecutor">
<bean class="org.springframework.core.task.SimpleAsyncTaskExecutor"/>

View File

@@ -9,7 +9,7 @@
<bean id="jobRepository" class="org.springframework.batch.core.repository.support.JdbcJobRepositoryFactoryBean"
p:dataSource-ref="dataSource" p:transactionManager-ref="transactionManager" />
<bean id="jobOperator" class="org.springframework.batch.core.launch.support.SimpleJobOperator"
<bean id="jobOperator" class="org.springframework.batch.core.launch.support.TaskExecutorJobOperator"
p:jobRepository-ref="jobRepository" p:jobRegistry-ref="jobRegistry" />
<bean id="jobExplorer" class="org.springframework.batch.core.repository.explore.support.JobExplorerFactoryBean"

View File

@@ -15,7 +15,7 @@
p:dataSource-ref="dataSource" p:transactionManager-ref="transactionManager"/>
<bean id="jobOperator"
class="org.springframework.batch.core.launch.support.SimpleJobOperator"
class="org.springframework.batch.core.launch.support.TaskExecutorJobOperator"
p:jobRepository-ref="jobRepository" p:jobRegistry-ref="jobRegistry" />
<bean id="jobRegistry"