From 0b6d8122b45cc7d29a41328590631b902bd44a9b Mon Sep 17 00:00:00 2001 From: Mahmoud Ben Hassine Date: Wed, 2 May 2018 09:35:45 +0200 Subject: [PATCH] BATCH-2686: Address Michael's remarks: - Add missing assertions on input channel and output channel - Use this keyword for local fields - Rename RemoteChunkingWorkerFlowBuilder to RemoteChunkingWorkerBuilder --- .../asciidoc/spring-batch-integration.adoc | 14 +++++++------- .../chunk/RemoteChunkingMasterStepBuilder.java | 10 ++++++---- ...der.java => RemoteChunkingWorkerBuilder.java} | 16 ++++++++-------- .../BatchIntegrationConfiguration.java | 6 +++--- .../annotation/EnableBatchIntegration.java | 10 +++++----- ...java => RemoteChunkingWorkerBuilderTest.java} | 6 +++--- spring-batch-samples/README.md | 2 +- .../remotechunking/WorkerConfiguration.java | 8 ++++---- .../sample/RemoteChunkingJobFunctionalTests.java | 2 +- 9 files changed, 38 insertions(+), 36 deletions(-) rename spring-batch-integration/src/main/java/org/springframework/batch/integration/chunk/{RemoteChunkingWorkerFlowBuilder.java => RemoteChunkingWorkerBuilder.java} (87%) rename spring-batch-integration/src/test/java/org/springframework/batch/integration/chunk/{RemoteChunkingWorkerFlowBuilderTest.java => RemoteChunkingWorkerBuilderTest.java} (88%) diff --git a/spring-batch-docs/asciidoc/spring-batch-integration.adoc b/spring-batch-docs/asciidoc/spring-batch-integration.adoc index cb8f62f84a..5c6a9daf6c 100644 --- a/spring-batch-docs/asciidoc/spring-batch-integration.adoc +++ b/spring-batch-docs/asciidoc/spring-batch-integration.adoc @@ -953,7 +953,7 @@ annotation that can be used to simplify remote chunking setup. This annotation p two beans that can be autowired in the application context: * `RemoteChunkingMasterStepBuilderFactory`: used to configure the master step -* `RemoteChunkingWorkerFlowBuilder`: used to configure the remote worker flow +* `RemoteChunkingWorkerBuilder`: used to configure the remote worker integration flow The following example shows how to use these APIs: @@ -970,7 +970,7 @@ public class RemoteChunkingConfiguration { @Bean public TaskletStep masterStep() { - return masterStepBuilderFactory.get("masterStep") + return this.masterStepBuilderFactory.get("masterStep") .chunk(100) .reader(itemReader()) .outputChannel(requests()) // requests sent to workers @@ -986,11 +986,11 @@ public class RemoteChunkingConfiguration { public static class WorkerConfiguration { @Autowired - private RemoteChunkingWorkerFlowBuilder workerFlowBuilder; + private RemoteChunkingWorkerBuilder workerBuilder; @Bean public IntegrationFlow workerFlow(DirectChannel requests, DirectChannel replies){ - return workerFlowBuilder + return this.workerBuilder .itemProcessor(itemProcessor()) .itemWriter(itemWriter()) .inputChannel(requests) // requests received from the master @@ -1004,13 +1004,13 @@ public class RemoteChunkingConfiguration { } ---- -On the master side, the `RemoteChunkingMasterStepBuilderFactory` makes it possible -to configure a master step by declaring the item reader, the output channel +On the master side, the `RemoteChunkingMasterStepBuilderFactory` allows you to +configure a master step by declaring the item reader, the output channel (to send requests to workers) and the input channel (to receive replies from workers). There is no need anymore to explicitly configure the `ChunkMessageChannelItemWriter` and `RemoteChunkHandlerFactoryBean`. -On the worker side, the `RemoteChunkingWorkerFlowBuilder` allows you to configure +On the worker side, the `RemoteChunkingWorkerBuilder` allows you to configure the worker flow to listens to requests sent by the master on the input channel, call the `ChunkProcessorChunkHandler` for each request with the configured `ItemProcessor` and `ItemWriter` and finally send replies on the output channel to the master. diff --git a/spring-batch-integration/src/main/java/org/springframework/batch/integration/chunk/RemoteChunkingMasterStepBuilder.java b/spring-batch-integration/src/main/java/org/springframework/batch/integration/chunk/RemoteChunkingMasterStepBuilder.java index 07593e77ac..18560cb343 100644 --- a/spring-batch-integration/src/main/java/org/springframework/batch/integration/chunk/RemoteChunkingMasterStepBuilder.java +++ b/spring-batch-integration/src/main/java/org/springframework/batch/integration/chunk/RemoteChunkingMasterStepBuilder.java @@ -163,12 +163,14 @@ public void throttleLimit(long throttleLimit) { public TaskletStep build() { Assert.notNull(applicationContext, "A GenericApplicationContext must be provided"); + Assert.notNull(inputChannel, "inputChannel must not be null"); + Assert.notNull(outputChannel, "outputChannel must not be null"); // configure messaging template - if (messagingTemplate == null) { - messagingTemplate = new MessagingTemplate(); + if (this.messagingTemplate == null) { + this.messagingTemplate = new MessagingTemplate(); } - messagingTemplate.setDefaultChannel(outputChannel); + this.messagingTemplate.setDefaultChannel(outputChannel); // configure item writer ChunkMessageChannelItemWriter chunkMessageChannelItemWriter = new ChunkMessageChannelItemWriter<>(); @@ -184,7 +186,7 @@ public TaskletStep build() { .addPropertyValue("chunkWriter", chunkMessageChannelItemWriter) .addPropertyValue("step", step) .getBeanDefinition(); - applicationContext.registerBeanDefinition(step.getName() + "_remoteChunkHandler", remoteChunkHandlerFactoryBeanDefinition); + this.applicationContext.registerBeanDefinition(step.getName() + "_remoteChunkHandler", remoteChunkHandlerFactoryBeanDefinition); return step; } diff --git a/spring-batch-integration/src/main/java/org/springframework/batch/integration/chunk/RemoteChunkingWorkerFlowBuilder.java b/spring-batch-integration/src/main/java/org/springframework/batch/integration/chunk/RemoteChunkingWorkerBuilder.java similarity index 87% rename from spring-batch-integration/src/main/java/org/springframework/batch/integration/chunk/RemoteChunkingWorkerFlowBuilder.java rename to spring-batch-integration/src/main/java/org/springframework/batch/integration/chunk/RemoteChunkingWorkerBuilder.java index 8ca0e58197..af7da26dc9 100644 --- a/spring-batch-integration/src/main/java/org/springframework/batch/integration/chunk/RemoteChunkingWorkerFlowBuilder.java +++ b/spring-batch-integration/src/main/java/org/springframework/batch/integration/chunk/RemoteChunkingWorkerBuilder.java @@ -25,7 +25,7 @@ import org.springframework.util.Assert; /** - * Builder for a worker flow in a remote chunking setup. This builder: + * Builder for a worker in a remote chunking setup. This builder: * * * @@ -50,11 +50,11 @@ * private RemoteChunkingMasterStepBuilderFactory masterBuilderFactory; * * @Autowired - * private RemoteChunkingWorkerFlowBuilder workerBuilder; + * private RemoteChunkingWorkerBuilder workerBuilder; * * @Bean * public Step master() { - * masterBuilderFactory + * this.masterBuilderFactory * .get("masterStep") * .reader(itemReader()) * .outputChannel(outgoingRequestsToWorkers()) @@ -64,7 +64,7 @@ * * @Bean * public IntegrationFlow worker() { - * workerBuilder + * this.workerBuilder * .itemProcessor(itemProcessor()) * .itemWriter(itemWriter()) * .inputChannel(incomingRequestsFromMaster()) diff --git a/spring-batch-integration/src/test/java/org/springframework/batch/integration/chunk/RemoteChunkingWorkerFlowBuilderTest.java b/spring-batch-integration/src/test/java/org/springframework/batch/integration/chunk/RemoteChunkingWorkerBuilderTest.java similarity index 88% rename from spring-batch-integration/src/test/java/org/springframework/batch/integration/chunk/RemoteChunkingWorkerFlowBuilderTest.java rename to spring-batch-integration/src/test/java/org/springframework/batch/integration/chunk/RemoteChunkingWorkerBuilderTest.java index c927a12fe7..9cf67d6780 100644 --- a/spring-batch-integration/src/test/java/org/springframework/batch/integration/chunk/RemoteChunkingWorkerFlowBuilderTest.java +++ b/spring-batch-integration/src/test/java/org/springframework/batch/integration/chunk/RemoteChunkingWorkerBuilderTest.java @@ -28,7 +28,7 @@ /** * @author Mahmoud Ben Hassine */ -public class RemoteChunkingWorkerFlowBuilderTest { +public class RemoteChunkingWorkerBuilderTest { @Rule public ExpectedException expectedException = ExpectedException.none(); @@ -39,7 +39,7 @@ public class RemoteChunkingWorkerFlowBuilderTest { @Test public void testMandatoryItemWriter() { // given - RemoteChunkingWorkerFlowBuilder builder = new RemoteChunkingWorkerFlowBuilder<>(); + RemoteChunkingWorkerBuilder builder = new RemoteChunkingWorkerBuilder<>(); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("An ItemWriter must be provided"); @@ -56,7 +56,7 @@ public void testIntegrationFlowCreation() { // given DirectChannel inputChannel = new DirectChannel(); DirectChannel outputChannel = new DirectChannel(); - RemoteChunkingWorkerFlowBuilder builder = new RemoteChunkingWorkerFlowBuilder() + RemoteChunkingWorkerBuilder builder = new RemoteChunkingWorkerBuilder() .itemProcessor(itemProcessor) .itemWriter(itemWriter) .inputChannel(inputChannel) diff --git a/spring-batch-samples/README.md b/spring-batch-samples/README.md index 7228ea9e45..e824ac93f7 100644 --- a/spring-batch-samples/README.md +++ b/spring-batch-samples/README.md @@ -649,7 +649,7 @@ not get shared across threads of execution. This sample shows how to configure a remote chunking job. The sample uses the `RemoteChunkingMasterStepBuilderFactory` to create a master step and -the `RemoteChunkingWorkerFlowBuilder` to configure an integration flow on +the `RemoteChunkingWorkerBuilder` to configure an integration flow on the worker side. This example also shows how to use rabbitmq as a communication middleware between the master and workers. diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/remotechunking/WorkerConfiguration.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/remotechunking/WorkerConfiguration.java index 3ef8b181b8..23bf8a7f5f 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/remotechunking/WorkerConfiguration.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/remotechunking/WorkerConfiguration.java @@ -25,7 +25,7 @@ import org.springframework.amqp.rabbit.connection.ConnectionFactory; import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; -import org.springframework.batch.integration.chunk.RemoteChunkingWorkerFlowBuilder; +import org.springframework.batch.integration.chunk.RemoteChunkingWorkerBuilder; import org.springframework.batch.integration.config.annotation.EnableBatchIntegration; import org.springframework.batch.item.ItemProcessor; import org.springframework.batch.item.ItemWriter; @@ -64,7 +64,7 @@ public static void main(String[] args) { } @Autowired - private RemoteChunkingWorkerFlowBuilder workerFlowBuilder; + private RemoteChunkingWorkerBuilder workerBuilder; @Bean public ConnectionFactory rabbitConnectionFactory() { @@ -139,8 +139,8 @@ public IntegrationFlow outgoingReplies(AmqpTemplate rabbitTemplate) { } @Bean - public IntegrationFlow integrationFlow(DirectChannel requests, DirectChannel replies) { - return workerFlowBuilder + public IntegrationFlow workerIntegrationFlow(DirectChannel requests, DirectChannel replies) { + return this.workerBuilder .itemProcessor(itemProcessor()) .itemWriter(itemWriter()) .inputChannel(requests) diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/RemoteChunkingJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/RemoteChunkingJobFunctionalTests.java index 8811f5e5b4..3e22ceb384 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/RemoteChunkingJobFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/RemoteChunkingJobFunctionalTests.java @@ -148,7 +148,7 @@ public IntegrationFlow inboundFlow(ConnectionFactory rabbitConnectionFactory, Po @Bean public TaskletStep masterStep() { - return masterStepBuilderFactory.get("masterStep") + return this.masterStepBuilderFactory.get("masterStep") .chunk(3) .reader(itemReader()) .outputChannel(requests())