Skip to content

Commit c34a1fc

Browse files
committed
Replace usage of JobLauncher with JobOperator in JobLaunchingGateway and JobLaunchingMessageHandler
Resolves #4924
1 parent b105c8e commit c34a1fc

File tree

6 files changed

+45
-41
lines changed

6 files changed

+45
-41
lines changed

spring-batch-integration/src/main/java/org/springframework/batch/integration/config/xml/JobLaunchingGatewayParser.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,7 +17,7 @@
1717

1818
import org.apache.commons.logging.Log;
1919
import org.apache.commons.logging.LogFactory;
20-
import org.springframework.batch.core.launch.JobLauncher;
20+
import org.springframework.batch.core.launch.JobOperator;
2121
import org.springframework.batch.integration.launch.JobLaunchingGateway;
2222
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
2323
import org.springframework.beans.factory.xml.ParserContext;
@@ -28,10 +28,11 @@
2828

2929
/**
3030
* The parser for the Job-Launching Gateway, which will instantiate a
31-
* {@link JobLaunchingGatewayParser}. If no {@link JobLauncher} reference has been
32-
* provided, this parse will use the use the globally registered bean 'jobLauncher'.
31+
* {@link JobLaunchingGatewayParser}. If no {@link JobOperator} reference has been
32+
* provided, this parse will use the globally registered bean 'jobOperator'.
3333
*
3434
* @author Gunnar Hillert
35+
* @author Mahmoud Ben Hassine
3536
* @since 1.3
3637
*
3738
*/
@@ -50,16 +51,16 @@ protected BeanDefinitionBuilder parseHandler(Element element, ParserContext pars
5051
final BeanDefinitionBuilder jobLaunchingGatewayBuilder = BeanDefinitionBuilder
5152
.genericBeanDefinition(JobLaunchingGateway.class);
5253

53-
final String jobLauncher = element.getAttribute("job-launcher");
54+
final String jobOperator = element.getAttribute("job-operator");
5455

55-
if (StringUtils.hasText(jobLauncher)) {
56-
jobLaunchingGatewayBuilder.addConstructorArgReference(jobLauncher);
56+
if (StringUtils.hasText(jobOperator)) {
57+
jobLaunchingGatewayBuilder.addConstructorArgReference(jobOperator);
5758
}
5859
else {
5960
if (logger.isDebugEnabled()) {
60-
logger.debug("No jobLauncher specified, using default 'jobLauncher' reference instead.");
61+
logger.debug("No jobOperator specified, using default 'jobOperator' reference instead.");
6162
}
62-
jobLaunchingGatewayBuilder.addConstructorArgReference("jobLauncher");
63+
jobLaunchingGatewayBuilder.addConstructorArgReference("jobOperator");
6364
}
6465

6566
IntegrationNamespaceUtils.setValueIfAttributeDefined(jobLaunchingGatewayBuilder, element, "reply-timeout",

spring-batch-integration/src/main/java/org/springframework/batch/integration/launch/JobLaunchingGateway.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,7 +18,7 @@
1818

1919
import org.springframework.batch.core.job.JobExecution;
2020
import org.springframework.batch.core.job.JobExecutionException;
21-
import org.springframework.batch.core.launch.JobLauncher;
21+
import org.springframework.batch.core.launch.JobOperator;
2222
import org.springframework.integration.handler.AbstractReplyProducingMessageHandler;
2323
import org.springframework.messaging.Message;
2424
import org.springframework.messaging.MessageHandlingException;
@@ -29,20 +29,21 @@
2929
* to a {@link JobLaunchingMessageHandler}.
3030
*
3131
* @author Gunnar Hillert
32+
* @author Mahmoud Ben Hassine
3233
* @since 1.3
3334
*/
3435
public class JobLaunchingGateway extends AbstractReplyProducingMessageHandler {
3536

3637
private final JobLaunchingMessageHandler jobLaunchingMessageHandler;
3738

3839
/**
39-
* Constructor taking a {@link JobLauncher} as parameter.
40-
* @param jobLauncher Must not be null.
40+
* Constructor taking a {@link JobOperator} as parameter.
41+
* @param jobOperator Must not be null.
4142
*
4243
*/
43-
public JobLaunchingGateway(JobLauncher jobLauncher) {
44-
Assert.notNull(jobLauncher, "jobLauncher must not be null.");
45-
this.jobLaunchingMessageHandler = new JobLaunchingMessageHandler(jobLauncher);
44+
public JobLaunchingGateway(JobOperator jobOperator) {
45+
Assert.notNull(jobOperator, "jobLauncher must not be null.");
46+
this.jobLaunchingMessageHandler = new JobLaunchingMessageHandler(jobOperator);
4647
}
4748

4849
/**

spring-batch-integration/src/main/java/org/springframework/batch/integration/launch/JobLaunchingMessageHandler.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2023 the original author or authors.
2+
* Copyright 2006-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,7 +20,7 @@
2020
import org.springframework.batch.core.job.JobExecution;
2121
import org.springframework.batch.core.job.JobExecutionException;
2222
import org.springframework.batch.core.job.parameters.JobParameters;
23-
import org.springframework.batch.core.launch.JobLauncher;
23+
import org.springframework.batch.core.launch.JobOperator;
2424
import org.springframework.integration.annotation.ServiceActivator;
2525

2626
/**
@@ -30,19 +30,20 @@
3030
* @author Jonas Partner
3131
* @author Dave Syer
3232
* @author Gunnar Hillert
33+
* @author Mahmoud Ben Hassine
3334
*
3435
*/
3536
public class JobLaunchingMessageHandler implements JobLaunchRequestHandler {
3637

37-
private final JobLauncher jobLauncher;
38+
private final JobOperator jobOperator;
3839

3940
/**
40-
* @param jobLauncher {@link org.springframework.batch.core.launch.JobLauncher} used
41+
* @param jobOperator {@link org.springframework.batch.core.launch.JobOperator} used
4142
* to execute Spring Batch jobs
4243
*/
43-
public JobLaunchingMessageHandler(JobLauncher jobLauncher) {
44+
public JobLaunchingMessageHandler(JobOperator jobOperator) {
4445
super();
45-
this.jobLauncher = jobLauncher;
46+
this.jobOperator = jobOperator;
4647
}
4748

4849
@Override
@@ -51,7 +52,7 @@ public JobExecution launch(JobLaunchRequest request) throws JobExecutionExceptio
5152
Job job = request.getJob();
5253
JobParameters jobParameters = request.getJobParameters();
5354

54-
return jobLauncher.run(job, jobParameters);
55+
return jobOperator.start(job, jobParameters);
5556
}
5657

5758
}

spring-batch-integration/src/main/resources/org/springframework/batch/integration/config/xml/spring-batch-integration.xsd

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,20 +79,20 @@
7979
]]></xsd:documentation>
8080
</xsd:annotation>
8181
</xsd:attribute>
82-
<xsd:attribute name="job-launcher" type="xsd:string">
82+
<xsd:attribute name="job-operator" type="xsd:string">
8383
<xsd:annotation>
8484
<xsd:appinfo>
8585
<xsd:documentation><![CDATA[
86-
Pass in a custom JobLauncher bean reference.
86+
Pass in a custom JobOperator bean reference.
8787
This attribute is optional. If not specified the
8888
adapter will re-use the default instance (under
89-
the id 'jobLauncher', e.g. when using the
89+
the id 'jobOperator', e.g. when using the
9090
@EnableBatchProcessing annotation via JavaConfig).
9191
If no default instance exists an exception is
9292
thrown.
9393
]]></xsd:documentation>
9494
<tool:annotation kind="ref">
95-
<tool:expected-type type="org.springframework.batch.core.launch.JobLauncher"/>
95+
<tool:expected-type type="org.springframework.batch.core.launch.JobOperator"/>
9696
</tool:annotation>
9797
</xsd:appinfo>
9898
</xsd:annotation>

spring-batch-integration/src/test/java/org/springframework/batch/integration/launch/JobLaunchingGatewayTests.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,7 +19,7 @@
1919
import org.springframework.batch.core.job.Job;
2020
import org.springframework.batch.core.job.parameters.JobParameters;
2121
import org.springframework.batch.core.job.parameters.JobParametersInvalidException;
22-
import org.springframework.batch.core.launch.JobLauncher;
22+
import org.springframework.batch.core.launch.JobOperator;
2323
import org.springframework.batch.integration.JobSupport;
2424
import org.springframework.integration.support.MessageBuilder;
2525
import org.springframework.messaging.Message;
@@ -33,6 +33,7 @@
3333

3434
/**
3535
* @author Gunnar Hillert
36+
* @author Mahmoud Ben Hassine
3637
* @since 1.3
3738
*
3839
*/
@@ -45,11 +46,11 @@ void testExceptionRaised() throws Exception {
4546
.withPayload(new JobLaunchRequest(new JobSupport("testJob"), new JobParameters()))
4647
.build();
4748

48-
final JobLauncher jobLauncher = mock();
49-
when(jobLauncher.run(any(Job.class), any(JobParameters.class)))
49+
final JobOperator jobOperator = mock();
50+
when(jobOperator.start(any(Job.class), any(JobParameters.class)))
5051
.thenThrow(new JobParametersInvalidException("This is a JobExecutionException."));
5152

52-
JobLaunchingGateway jobLaunchingGateway = new JobLaunchingGateway(jobLauncher);
53+
JobLaunchingGateway jobLaunchingGateway = new JobLaunchingGateway(jobOperator);
5354
Exception exception = assertThrows(MessageHandlingException.class,
5455
() -> jobLaunchingGateway.handleMessage(message));
5556
assertEquals("This is a JobExecutionException.", exception.getCause().getMessage());

spring-batch-integration/src/test/java/org/springframework/batch/integration/launch/JobLaunchingMessageHandlerTests.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2008-2023 the original author or authors.
2+
* Copyright 2008-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -27,7 +27,7 @@
2727
import org.springframework.batch.core.job.JobExecution;
2828
import org.springframework.batch.core.job.JobInstance;
2929
import org.springframework.batch.core.job.parameters.JobParameters;
30-
import org.springframework.batch.core.launch.JobLauncher;
30+
import org.springframework.batch.core.launch.support.TaskExecutorJobOperator;
3131
import org.springframework.batch.integration.JobSupport;
3232
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
3333

@@ -36,24 +36,24 @@ class JobLaunchingMessageHandlerTests {
3636

3737
JobLaunchRequestHandler messageHandler;
3838

39-
StubJobLauncher jobLauncher;
39+
StubJobOperator jobOperator;
4040

4141
@BeforeEach
4242
void setUp() {
43-
jobLauncher = new StubJobLauncher();
44-
messageHandler = new JobLaunchingMessageHandler(jobLauncher);
43+
jobOperator = new StubJobOperator();
44+
messageHandler = new JobLaunchingMessageHandler(jobOperator);
4545
}
4646

4747
@Test
4848
void testSimpleDelivery() throws Exception {
4949
messageHandler.launch(new JobLaunchRequest(new JobSupport("testjob"), null));
5050

51-
assertEquals(1, jobLauncher.jobs.size(), "Wrong job count");
52-
assertEquals("testjob", jobLauncher.jobs.get(0).getName(), "Wrong job name");
51+
assertEquals(1, jobOperator.jobs.size(), "Wrong job count");
52+
assertEquals("testjob", jobOperator.jobs.get(0).getName(), "Wrong job name");
5353

5454
}
5555

56-
private static class StubJobLauncher implements JobLauncher {
56+
private static class StubJobOperator extends TaskExecutorJobOperator {
5757

5858
List<Job> jobs = new ArrayList<>();
5959

@@ -62,7 +62,7 @@ private static class StubJobLauncher implements JobLauncher {
6262
AtomicLong jobId = new AtomicLong();
6363

6464
@Override
65-
public JobExecution run(Job job, JobParameters jobParameters) {
65+
public JobExecution start(Job job, JobParameters jobParameters) {
6666
jobs.add(job);
6767
parameters.add(jobParameters);
6868
return new JobExecution(new JobInstance(jobId.getAndIncrement(), job.getName()), jobParameters);

0 commit comments

Comments
 (0)