001/*
002 * Copyright 2018 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *       https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.springframework.batch.integration.config.annotation;
017
018import java.lang.annotation.Documented;
019import java.lang.annotation.ElementType;
020import java.lang.annotation.Retention;
021import java.lang.annotation.RetentionPolicy;
022import java.lang.annotation.Target;
023
024import org.springframework.batch.integration.chunk.RemoteChunkingWorkerBuilder;
025import org.springframework.batch.integration.chunk.RemoteChunkingMasterStepBuilderFactory;
026import org.springframework.batch.integration.partition.RemotePartitioningMasterStepBuilderFactory;
027import org.springframework.batch.integration.partition.RemotePartitioningWorkerStepBuilderFactory;
028import org.springframework.context.annotation.Import;
029import org.springframework.integration.config.EnableIntegration;
030
031/**
032 * Enable Spring Batch Integration features and provide a base configuration for
033 * setting up remote chunking or partitioning infrastructure beans.
034 *
035 * By adding this annotation on a {@link org.springframework.context.annotation.Configuration}
036 * class, it will be possible to autowire the following beans:
037 *
038 * <ul>
039 *     <li>{@link RemoteChunkingMasterStepBuilderFactory}:
040 *     used to create a master step of a remote chunking setup by automatically
041 *     setting the job repository and transaction manager.</li>
042 *     <li>{@link RemoteChunkingWorkerBuilder}: used to create the integration
043 *     flow on the worker side of a remote chunking setup.</li>
044 *     <li>{@link RemotePartitioningMasterStepBuilderFactory}: used to create
045 *     a master step of a remote partitioning setup by automatically setting
046 *     the job repository, job explorer, bean factory and transaction manager.</li>
047 *     <li>{@link RemotePartitioningWorkerStepBuilderFactory}: used to create
048 *     a worker step of a remote partitioning setup by automatically setting
049 *     the job repository, job explorer, bean factory and transaction manager.</li>
050 * </ul>
051 *
052 * For remote chunking, an example of a configuration class would be:
053 *
054 * <pre class="code">
055 * &#064;Configuration
056 * &#064;EnableBatchIntegration
057 * &#064;EnableBatchProcessing
058 * public class RemoteChunkingAppConfig {
059 *
060 *      &#064;Autowired
061 *      private RemoteChunkingMasterStepBuilderFactory masterStepBuilderFactory;
062 *
063 *      &#064;Autowired
064 *      private RemoteChunkingWorkerBuilder workerBuilder;
065 *
066 *      &#064;Bean
067 *      public TaskletStep masterStep() {
068 *               return this.masterStepBuilderFactory
069 *                      .get("masterStep")
070 *                      .chunk(100)
071 *                      .reader(itemReader())
072 *                      .outputChannel(outgoingRequestsToWorkers())
073 *                      .inputChannel(incomingRepliesFromWorkers())
074 *                      .build();
075 *      }
076 *
077 *      &#064;Bean
078 *      public IntegrationFlow worker() {
079 *               return this.workerBuilder
080 *                      .itemProcessor(itemProcessor())
081 *                      .itemWriter(itemWriter())
082 *                      .inputChannel(incomingRequestsFromMaster())
083 *                      .outputChannel(outgoingRepliesToMaster())
084 *                      .build();
085 *      }
086 *
087 *      // Middleware beans omitted
088 *
089 * }
090 * </pre>
091 *
092 * For remote partitioning, an example of a configuration class would be:
093 *
094 * <pre class="code">
095 * &#064;Configuration
096 * &#064;EnableBatchIntegration
097 * &#064;EnableBatchProcessing
098 * public class RemotePartitioningAppConfig {
099 *
100 *      &#064;Autowired
101 *      private RemotePartitioningMasterStepBuilderFactory masterStepBuilderFactory;
102 *
103 *      &#064;Autowired
104 *      private RemotePartitioningWorkerStepBuilderFactory workerStepBuilderFactory;
105 *
106 *      &#064;Bean
107 *      public Step masterStep() {
108 *               return this.masterStepBuilderFactory
109 *                      .get("masterStep")
110 *                      .partitioner("workerStep", partitioner())
111 *                      .gridSize(10)
112 *                      .outputChannel(outgoingRequestsToWorkers())
113 *                      .inputChannel(incomingRepliesFromWorkers())
114 *                      .build();
115 *      }
116 *
117 *      &#064;Bean
118 *      public Step workerStep() {
119 *               return this.workerStepBuilderFactory
120 *                      .get("workerStep")
121 *                      .inputChannel(incomingRequestsFromMaster())
122 *                      .outputChannel(outgoingRepliesToMaster())
123 *                      .chunk(100)
124 *                      .reader(itemReader())
125 *                      .processor(itemProcessor())
126 *                      .writer(itemWriter())
127 *                      .build();
128 *      }
129 *
130 *      // Middleware beans omitted
131 *
132 * }
133 * </pre>
134 * @since 4.1
135 * @author Mahmoud Ben Hassine
136 */
137@Target(ElementType.TYPE)
138@Retention(RetentionPolicy.RUNTIME)
139@Documented
140@EnableIntegration
141@Import(BatchIntegrationConfiguration.class)
142public @interface EnableBatchIntegration {
143}