Skip to content

Commit 04f2116

Browse files
committed
Rename ChunkHandler to ChunkRequestHandler
Resolves #4964
1 parent 1ed351e commit 04f2116

File tree

14 files changed

+77
-74
lines changed

14 files changed

+77
-74
lines changed

spring-batch-docs/modules/ROOT/pages/faq.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,4 @@ and message-oriented middleware (JMS, AQ, MQ, Tibco etc.) gives us a lot of resi
6363
a system where there is feedback between downstream and upstream stages, so the number of consumers can be adjusted to account for the amount of demand.
6464
So how does this fit into Spring Batch? The spring-batch-integration project has this pattern implemented in Spring Integration,
6565
and can be used to scale up the remote processing of any step with many items to process.
66-
See in particular the "chunk" package, and the `ItemWriter` and `ChunkHandler` implementations in there.
66+
See in particular the "chunk" package, and the `ItemWriter` and `ChunkRequestHandler` implementations in there.

spring-batch-docs/modules/ROOT/pages/spring-batch-integration/sub-elements.adoc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ XML::
545545
The following example shows the worker configuration in XML:
546546
+
547547
.XML Configuration
548-
[source, xml]
548+
[source,xml]
549549
----
550550
<bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
551551
<property name="brokerURL" value="tcp://localhost:61616"/>
@@ -570,7 +570,7 @@ The following example shows the worker configuration in XML:
570570
method="handleChunk"/>
571571
572572
<bean id="chunkProcessorChunkHandler"
573-
class="org.springframework.batch.integration.chunk.ChunkProcessorChunkHandler">
573+
class="org.springframework.batch.integration.chunk.ChunkProcessorChunkRequestHandler">
574574
<property name="chunkProcessor">
575575
<bean class="org.springframework.batch.core.step.item.SimpleChunkProcessor">
576576
<property name="itemWriter">
@@ -593,7 +593,7 @@ manager configuration. Workers do not need access to
593593
the Spring Batch `JobRepository` nor
594594
to the actual job configuration file. The main bean of interest
595595
is the `chunkProcessorChunkHandler`. The
596-
`chunkProcessor` property of `ChunkProcessorChunkHandler` takes a
596+
`chunkProcessor` property of `ChunkProcessorChunkRequestHandler` takes a
597597
configured `SimpleChunkProcessor`, which is where you would provide a reference to your
598598
`ItemWriter` (and, optionally, your
599599
`ItemProcessor`) that will run on the worker
@@ -627,12 +627,12 @@ You need not explicitly configure `ChunkMessageChannelItemWriter` and the `Messa
627627
On the worker side, the `RemoteChunkingWorkerBuilder` lets you configure a worker to:
628628

629629
* Listen to requests sent by the manager on the input channel ("`Incoming requests`")
630-
* Call the `handleChunk` method of `ChunkProcessorChunkHandler` for each request
630+
* Call the `handleChunk` method of `ChunkProcessorChunkRequestHandler` for each request
631631
with the configured `ItemProcessor` and `ItemWriter`
632632
* Send replies on the output channel ("`Outgoing replies`") to the manager
633633

634634
You need not explicitly configure the `SimpleChunkProcessor`
635-
and the `ChunkProcessorChunkHandler`. (You can still explicitly configure them if you find
635+
and the `ChunkProcessorChunkRequestHandler`. (You can still explicitly configure them if you find
636636
a reason to do so).
637637

638638
The following example shows how to use these APIs:
Lines changed: 9 additions & 9 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.
@@ -33,20 +33,20 @@
3333
import org.springframework.util.Assert;
3434

3535
/**
36-
* A {@link ChunkHandler} based on a {@link ChunkProcessor}. Knows how to distinguish
37-
* between a processor that is fault tolerant, and one that is not. If the processor is
38-
* fault tolerant then exceptions can be propagated on the assumption that there will be a
39-
* roll back and the request will be re-delivered.
36+
* A {@link ChunkRequestHandler} based on a {@link ChunkProcessor}. Knows how to
37+
* distinguish between a processor that is fault tolerant, and one that is not. If the
38+
* processor is fault tolerant then exceptions can be propagated on the assumption that
39+
* there will be a roll back and the request will be re-delivered.
4040
*
4141
* @author Dave Syer
4242
* @author Michael Minella
4343
* @author Mahmoud Ben Hassine
4444
* @param <S> the type of the items in the chunk to be handled
4545
*/
4646
@MessageEndpoint
47-
public class ChunkProcessorChunkHandler<S> implements ChunkHandler<S>, InitializingBean {
47+
public class ChunkProcessorChunkRequestHandler<S> implements ChunkRequestHandler<S>, InitializingBean {
4848

49-
private static final Log logger = LogFactory.getLog(ChunkProcessorChunkHandler.class);
49+
private static final Log logger = LogFactory.getLog(ChunkProcessorChunkRequestHandler.class);
5050

5151
private ChunkProcessor<S> chunkProcessor;
5252

@@ -65,11 +65,11 @@ public void setChunkProcessor(ChunkProcessor<S> chunkProcessor) {
6565

6666
/**
6767
*
68-
* @see ChunkHandler#handleChunk(ChunkRequest)
68+
* @see ChunkRequestHandler#handle(ChunkRequest)
6969
*/
7070
@Override
7171
@ServiceActivator
72-
public ChunkResponse handleChunk(ChunkRequest<S> chunkRequest) throws Exception {
72+
public ChunkResponse handle(ChunkRequest<S> chunkRequest) throws Exception {
7373

7474
if (logger.isDebugEnabled()) {
7575
logger.debug("Handling chunk: " + chunkRequest);
Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2007 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.
@@ -22,22 +22,23 @@
2222
* response needs to be generated containing a summary of the result.
2323
*
2424
* @author Dave Syer
25+
* @author Mahmoud Ben Hassine
2526
* @param <T> the type of the items to be processed (it is recommended to use a Memento
2627
* like a primary key)
2728
*/
28-
public interface ChunkHandler<T> {
29+
public interface ChunkRequestHandler<T> {
2930

3031
/**
31-
* Handle the chunk, processing all the items and returning a response summarising the
32-
* result. If the result is a failure then the response should say so. The handler
33-
* only throws an exception if it needs to roll back a transaction and knows that the
34-
* request will be re-delivered (if not to the same handler then to one processing the
35-
* same Step).
32+
* Handle the chunk request, processing all the items and returning a response
33+
* summarising the result. If the result is a failure then the response should say so.
34+
* The handler only throws an exception if it needs to roll back a transaction and
35+
* knows that the request will be re-delivered (if not to the same handler then to one
36+
* processing the same Step).
3637
* @param chunk a request containing the chunk to process
3738
* @return a response summarising the result
3839
* @throws Exception if the handler needs to roll back a transaction and have the
3940
* chunk re-delivered
4041
*/
41-
ChunkResponse handleChunk(ChunkRequest<T> chunk) throws Exception;
42+
ChunkResponse handle(ChunkRequest<T> chunk) throws Exception;
4243

4344
}

spring-batch-integration/src/main/java/org/springframework/batch/integration/chunk/RemoteChunkHandlerFactoryBean.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
* @author Mahmoud Ben Hassine
5050
*
5151
*/
52-
public class RemoteChunkHandlerFactoryBean<T> implements FactoryBean<ChunkHandler<T>> {
52+
public class RemoteChunkHandlerFactoryBean<T> implements FactoryBean<ChunkRequestHandler<T>> {
5353

5454
private static final Log logger = LogFactory.getLog(RemoteChunkHandlerFactoryBean.class);
5555

@@ -87,13 +87,14 @@ public void setStepContributionSource(StepContributionSource stepContributionSou
8787
}
8888

8989
/**
90-
* The type of object created by this factory. Returns {@link ChunkHandler} class.
90+
* The type of object created by this factory. Returns {@link ChunkRequestHandler}
91+
* class.
9192
*
9293
* @see FactoryBean#getObjectType()
9394
*/
9495
@Override
9596
public Class<?> getObjectType() {
96-
return ChunkHandler.class;
97+
return ChunkRequestHandler.class;
9798
}
9899

99100
/**
@@ -107,14 +108,15 @@ public boolean isSingleton() {
107108
}
108109

109110
/**
110-
* Builds a {@link ChunkHandler} from the {@link ChunkProcessor} extracted from the
111-
* {@link #setStep(TaskletStep) step} provided. Also modifies the step to send chunks
112-
* to the chunk handler via the {@link #setChunkWriter(ItemWriter) chunk writer}.
111+
* Builds a {@link ChunkRequestHandler} from the {@link ChunkProcessor} extracted from
112+
* the {@link #setStep(TaskletStep) step} provided. Also modifies the step to send
113+
* chunks to the chunk handler via the {@link #setChunkWriter(ItemWriter) chunk
114+
* writer}.
113115
*
114116
* @see FactoryBean#getObject()
115117
*/
116118
@Override
117-
public ChunkHandler<T> getObject() throws Exception {
119+
public ChunkRequestHandler<T> getObject() throws Exception {
118120

119121
if (stepContributionSource == null) {
120122
Assert.state(chunkWriter instanceof StepContributionSource,
@@ -143,7 +145,7 @@ public ChunkHandler<T> getObject() throws Exception {
143145
step.registerStepExecutionListener(stepExecutionListener);
144146
}
145147

146-
ChunkProcessorChunkHandler<T> handler = new ChunkProcessorChunkHandler<>();
148+
ChunkProcessorChunkRequestHandler<T> handler = new ChunkProcessorChunkRequestHandler<>();
147149
setNonBuffering(chunkProcessor);
148150
handler.setChunkProcessor(chunkProcessor);
149151
// TODO: create step context for the processor in case it has

spring-batch-integration/src/main/java/org/springframework/batch/integration/chunk/RemoteChunkingWorkerBuilder.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2018-2022 the original author or authors.
2+
* Copyright 2018-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,12 +27,13 @@
2727
* Builder for a worker in a remote chunking setup. This builder:
2828
*
2929
* <ul>
30-
* <li>creates a {@link ChunkProcessorChunkHandler} with the provided item processor and
31-
* writer. If no item processor is provided, a {@link PassThroughItemProcessor} will be
32-
* used</li>
33-
* <li>creates an {@link IntegrationFlow} with the {@link ChunkProcessorChunkHandler} as a
34-
* service activator which listens to incoming requests on <code>inputChannel</code> and
35-
* sends replies on <code>outputChannel</code></li>
30+
* <li>creates a {@link ChunkProcessorChunkRequestHandler} with the provided item
31+
* processor and writer. If no item processor is provided, a
32+
* {@link PassThroughItemProcessor} will be used</li>
33+
* <li>creates an {@link IntegrationFlow} with the
34+
* {@link ChunkProcessorChunkRequestHandler} as a service activator which listens to
35+
* incoming requests on <code>inputChannel</code> and sends replies on
36+
* <code>outputChannel</code></li>
3637
* </ul>
3738
*
3839
* @param <I> type of input items
@@ -42,7 +43,7 @@
4243
*/
4344
public class RemoteChunkingWorkerBuilder<I, O> {
4445

45-
private static final String SERVICE_ACTIVATOR_METHOD_NAME = "handleChunk";
46+
private static final String SERVICE_ACTIVATOR_METHOD_NAME = "handle";
4647

4748
private ItemProcessor<I, O> itemProcessor;
4849

@@ -97,7 +98,7 @@ public RemoteChunkingWorkerBuilder<I, O> outputChannel(MessageChannel outputChan
9798
}
9899

99100
/**
100-
* Create an {@link IntegrationFlow} with a {@link ChunkProcessorChunkHandler}
101+
* Create an {@link IntegrationFlow} with a {@link ChunkProcessorChunkRequestHandler}
101102
* configured as a service activator listening to the input channel and replying on
102103
* the output channel.
103104
* @return the integration flow
@@ -113,11 +114,11 @@ public IntegrationFlow build() {
113114
}
114115
SimpleChunkProcessor<I, O> chunkProcessor = new SimpleChunkProcessor<>(this.itemProcessor, this.itemWriter);
115116

116-
ChunkProcessorChunkHandler<I> chunkProcessorChunkHandler = new ChunkProcessorChunkHandler<>();
117-
chunkProcessorChunkHandler.setChunkProcessor(chunkProcessor);
117+
ChunkProcessorChunkRequestHandler<I> chunkProcessorChunkRequestHandler = new ChunkProcessorChunkRequestHandler<>();
118+
chunkProcessorChunkRequestHandler.setChunkProcessor(chunkProcessor);
118119

119120
return IntegrationFlow.from(this.inputChannel)
120-
.handle(chunkProcessorChunkHandler, SERVICE_ACTIVATOR_METHOD_NAME)
121+
.handle(chunkProcessorChunkRequestHandler, SERVICE_ACTIVATOR_METHOD_NAME)
121122
.channel(this.outputChannel)
122123
.get();
123124
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2023 the original author or authors.
2+
* Copyright 2014-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
import org.w3c.dom.Element;
1919

2020
import org.springframework.batch.core.step.item.SimpleChunkProcessor;
21-
import org.springframework.batch.integration.chunk.ChunkProcessorChunkHandler;
21+
import org.springframework.batch.integration.chunk.ChunkProcessorChunkRequestHandler;
2222
import org.springframework.batch.item.support.PassThroughItemProcessor;
2323
import org.springframework.beans.factory.config.BeanDefinition;
2424
import org.springframework.beans.factory.config.RuntimeBeanReference;
@@ -60,7 +60,7 @@ public class RemoteChunkingWorkerParser extends AbstractBeanDefinitionParser {
6060

6161
private static final String CHUNK_PROCESSOR_PROPERTY_NAME = "chunkProcessor";
6262

63-
private static final String CHUNK_PROCESSOR_CHUNK_HANDLER_BEAN_NAME_PREFIX = "chunkProcessorChunkHandler_";
63+
private static final String CHUNK_PROCESSOR_CHUNK_HANDLER_BEAN_NAME_PREFIX = "chunkProcessorChunkRequestHandler_";
6464

6565
@Override
6666
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
@@ -92,7 +92,7 @@ protected AbstractBeanDefinition parseInternal(Element element, ParserContext pa
9292
}
9393

9494
BeanDefinition chunkProcessorChunkHandler = BeanDefinitionBuilder
95-
.genericBeanDefinition(ChunkProcessorChunkHandler.class)
95+
.genericBeanDefinition(ChunkProcessorChunkRequestHandler.class)
9696
.addPropertyValue(CHUNK_PROCESSOR_PROPERTY_NAME, chunkProcessorBuilder.getBeanDefinition())
9797
.getBeanDefinition();
9898

@@ -110,9 +110,9 @@ private static class ServiceActivatorParser extends AbstractConsumerEndpointPars
110110

111111
private static final String TARGET_OBJECT_PROPERTY_NAME = "targetObject";
112112

113-
private static final String HANDLE_CHUNK_METHOD_NAME = "handleChunk";
113+
private static final String HANDLE_CHUNK_METHOD_NAME = "handle";
114114

115-
private static final String CHUNK_PROCESSOR_CHUNK_HANDLER_BEAN_NAME_PREFIX = "chunkProcessorChunkHandler_";
115+
private static final String CHUNK_PROCESSOR_CHUNK_HANDLER_BEAN_NAME_PREFIX = "chunkProcessorChunkRequestHandler_";
116116

117117
private final String id;
118118

Lines changed: 4 additions & 4 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.
@@ -24,9 +24,9 @@
2424
import static org.junit.jupiter.api.Assertions.assertEquals;
2525
import static org.junit.jupiter.api.Assertions.assertTrue;
2626

27-
class ChunkProcessorChunkHandlerTests {
27+
class ChunkProcessorChunkRequestHandlerTests {
2828

29-
private final ChunkProcessorChunkHandler<Object> handler = new ChunkProcessorChunkHandler<>();
29+
private final ChunkProcessorChunkRequestHandler<Object> handler = new ChunkProcessorChunkRequestHandler<>();
3030

3131
protected int count = 0;
3232

@@ -39,7 +39,7 @@ void testVanillaHandleChunk() throws Exception {
3939
ChunkRequest chunkRequest = new ChunkRequest<>(0, items, 12L, stepContribution);
4040

4141
// when
42-
ChunkResponse response = handler.handleChunk(chunkRequest);
42+
ChunkResponse response = handler.handle(chunkRequest);
4343

4444
// then
4545
assertEquals(stepContribution, response.getStepContribution());

spring-batch-integration/src/test/java/org/springframework/batch/integration/config/xml/RemoteChunkingParserTests.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2022 the original author or authors.
2+
* Copyright 2014-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,9 +19,9 @@
1919

2020
import org.springframework.batch.core.step.item.ChunkProcessor;
2121
import org.springframework.batch.core.step.item.SimpleChunkProcessor;
22-
import org.springframework.batch.integration.chunk.ChunkHandler;
22+
import org.springframework.batch.integration.chunk.ChunkRequestHandler;
2323
import org.springframework.batch.integration.chunk.ChunkMessageChannelItemWriter;
24-
import org.springframework.batch.integration.chunk.ChunkProcessorChunkHandler;
24+
import org.springframework.batch.integration.chunk.ChunkProcessorChunkRequestHandler;
2525
import org.springframework.batch.integration.chunk.RemoteChunkHandlerFactoryBean;
2626
import org.springframework.batch.item.Chunk;
2727
import org.springframework.batch.item.ItemProcessor;
@@ -60,8 +60,8 @@ void testRemoteChunkingWorkerParserWithProcessorDefined() {
6060
ApplicationContext applicationContext = new ClassPathXmlApplicationContext(
6161
"/org/springframework/batch/integration/config/xml/RemoteChunkingWorkerParserTests.xml");
6262

63-
ChunkHandler chunkHandler = applicationContext.getBean(ChunkProcessorChunkHandler.class);
64-
ChunkProcessor chunkProcessor = (SimpleChunkProcessor) TestUtils.getPropertyValue(chunkHandler,
63+
ChunkRequestHandler chunkRequestHandler = applicationContext.getBean(ChunkProcessorChunkRequestHandler.class);
64+
ChunkProcessor chunkProcessor = (SimpleChunkProcessor) TestUtils.getPropertyValue(chunkRequestHandler,
6565
"chunkProcessor");
6666
assertNotNull(chunkProcessor, "ChunkProcessor must not be null");
6767

@@ -84,10 +84,9 @@ void testRemoteChunkingWorkerParserWithProcessorDefined() {
8484

8585
String targetMethodName = (String) TestUtils.getPropertyValue(serviceActivatorFactoryBean, "targetMethodName");
8686
assertNotNull(targetMethodName, "Target method name must not be null");
87-
assertEquals("handleChunk", targetMethodName,
88-
"Target method name must be handleChunk, got: " + targetMethodName);
87+
assertEquals("handle", targetMethodName, "Target method name must be handle, got: " + targetMethodName);
8988

90-
ChunkHandler targetObject = (ChunkHandler) TestUtils.getPropertyValue(serviceActivatorFactoryBean,
89+
ChunkRequestHandler targetObject = (ChunkRequestHandler) TestUtils.getPropertyValue(serviceActivatorFactoryBean,
9190
"targetObject");
9291
assertNotNull(targetObject, "Target object must not be null");
9392
}
@@ -98,8 +97,8 @@ void testRemoteChunkingWorkerParserWithProcessorNotDefined() {
9897
ApplicationContext applicationContext = new ClassPathXmlApplicationContext(
9998
"/org/springframework/batch/integration/config/xml/RemoteChunkingWorkerParserNoProcessorTests.xml");
10099

101-
ChunkHandler chunkHandler = applicationContext.getBean(ChunkProcessorChunkHandler.class);
102-
ChunkProcessor chunkProcessor = (SimpleChunkProcessor) TestUtils.getPropertyValue(chunkHandler,
100+
ChunkRequestHandler chunkRequestHandler = applicationContext.getBean(ChunkProcessorChunkRequestHandler.class);
101+
ChunkProcessor chunkProcessor = (SimpleChunkProcessor) TestUtils.getPropertyValue(chunkRequestHandler,
103102
"chunkProcessor");
104103
assertNotNull(chunkProcessor, "ChunkProcessor must not be null");
105104

@@ -120,7 +119,7 @@ void testRemoteChunkingManagerParser() {
120119
"Messaging template must not be null");
121120
assertNotNull(TestUtils.getPropertyValue(itemWriter, "replyChannel"), "Reply channel must not be null");
122121

123-
FactoryBean<ChunkHandler> remoteChunkingHandlerFactoryBean = applicationContext
122+
FactoryBean<ChunkRequestHandler> remoteChunkingHandlerFactoryBean = applicationContext
124123
.getBean(RemoteChunkHandlerFactoryBean.class);
125124
assertNotNull(TestUtils.getPropertyValue(remoteChunkingHandlerFactoryBean, "chunkWriter"),
126125
"Chunk writer must not be null");

0 commit comments

Comments
 (0)