|
1 | 1 | /* |
2 | | - * Copyright 2016-2017 the original author or authors. |
| 2 | + * Copyright 2016-2018 the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
|
36 | 36 | import org.springframework.util.Assert; |
37 | 37 |
|
38 | 38 | /** |
39 | | - * A public API for dynamic (manual) registration of {@link IntegrationFlow}, |
| 39 | + * A public API for dynamic (manual) registration of {@link IntegrationFlow}s, |
40 | 40 | * not via standard bean registration phase. |
41 | 41 | * <p> |
42 | 42 | * The bean of this component is provided via framework automatically. |
|
45 | 45 | * <p> |
46 | 46 | * The typical use-case, and, therefore algorithm, is: |
47 | 47 | * <ul> |
48 | | - * <li> create {@link IntegrationFlow} depending of the business logic |
| 48 | + * <li> create an {@link IntegrationFlow} instance depending of the business logic |
49 | 49 | * <li> register that {@link IntegrationFlow} in this {@link IntegrationFlowContext}, |
50 | 50 | * with optional {@code id} and {@code autoStartup} flag |
51 | 51 | * <li> obtain a {@link MessagingTemplate} for that {@link IntegrationFlow} |
@@ -98,6 +98,11 @@ private void register(IntegrationFlowRegistrationBuilder builder) { |
98 | 98 | flowId = generateBeanName(integrationFlow, null); |
99 | 99 | builder.id(flowId); |
100 | 100 | } |
| 101 | + else if (this.registry.containsKey(flowId)) { |
| 102 | + throw new IllegalArgumentException("An IntegrationFlow '" + this.registry.get(flowId) + |
| 103 | + "' with flowId '" + flowId + "' is already registered.\n" + |
| 104 | + "An existing IntegrationFlowRegistration must be destroyed before overriding."); |
| 105 | + } |
101 | 106 | IntegrationFlow theFlow = (IntegrationFlow) registerBean(integrationFlow, flowId, null); |
102 | 107 | builder.integrationFlowRegistration.setIntegrationFlow(theFlow); |
103 | 108 |
|
@@ -209,31 +214,66 @@ public final class IntegrationFlowRegistrationBuilder { |
209 | 214 |
|
210 | 215 | private boolean autoStartup = true; |
211 | 216 |
|
212 | | - private IntegrationFlowRegistrationBuilder(IntegrationFlow integrationFlow) { |
| 217 | + IntegrationFlowRegistrationBuilder(IntegrationFlow integrationFlow) { |
213 | 218 | this.integrationFlowRegistration = new IntegrationFlowRegistration(integrationFlow); |
214 | 219 | this.integrationFlowRegistration.setBeanFactory(IntegrationFlowContext.this.beanFactory); |
215 | 220 | this.integrationFlowRegistration.setIntegrationFlowContext(IntegrationFlowContext.this); |
216 | 221 | } |
217 | 222 |
|
| 223 | + /** |
| 224 | + * Specify an {@code id} for the {@link IntegrationFlow} to register. |
| 225 | + * Must be unique per context. |
| 226 | + * The registration with this {@code id} must be destroyed before reusing for |
| 227 | + * a new {@link IntegrationFlow} instance. |
| 228 | + * @param id the id for the {@link IntegrationFlow} to register |
| 229 | + * @return the current builder instance |
| 230 | + */ |
218 | 231 | public IntegrationFlowRegistrationBuilder id(String id) { |
219 | 232 | this.integrationFlowRegistration.setId(id); |
220 | 233 | return this; |
221 | 234 | } |
222 | 235 |
|
| 236 | + /** |
| 237 | + * The {@code boolean} flag to indication if an {@link IntegrationFlow} must be started |
| 238 | + * automatically after registration. Defaults to {@code true}. |
| 239 | + * @param autoStartup start or not the {@link IntegrationFlow} automatically after registration. |
| 240 | + * @return the current builder instance |
| 241 | + */ |
223 | 242 | public IntegrationFlowRegistrationBuilder autoStartup(boolean autoStartup) { |
224 | 243 | this.autoStartup = autoStartup; |
225 | 244 | return this; |
226 | 245 | } |
227 | 246 |
|
| 247 | + /** |
| 248 | + * Add an object which will be registered as an {@link IntegrationFlow} dependant bean in the |
| 249 | + * application context. Usually it is some support component, which needs an application context. |
| 250 | + * For example dynamically created connection factories or header mappers for AMQP, JMS, TCP etc. |
| 251 | + * @param bean an additional arbitrary bean to register into the application context. |
| 252 | + * @return the current builder instance |
| 253 | + */ |
228 | 254 | public IntegrationFlowRegistrationBuilder addBean(Object bean) { |
229 | 255 | return addBean(null, bean); |
230 | 256 | } |
231 | 257 |
|
| 258 | + /** |
| 259 | + * Add an object which will be registered as an {@link IntegrationFlow} dependant bean in the |
| 260 | + * application context. Usually it is some support component, which needs an application context. |
| 261 | + * For example dynamically created connection factories or header mappers for AMQP, JMS, TCP etc. |
| 262 | + * @param name the name for the bean to register. |
| 263 | + * @param bean an additional arbitrary bean to register into the application context. |
| 264 | + * @return the current builder instance |
| 265 | + */ |
232 | 266 | public IntegrationFlowRegistrationBuilder addBean(String name, Object bean) { |
233 | 267 | this.additionalBeans.put(bean, name); |
234 | 268 | return this; |
235 | 269 | } |
236 | 270 |
|
| 271 | + /** |
| 272 | + * Register an {@link IntegrationFlow} and all the dependant and support components |
| 273 | + * in the application context and return an associated {@link IntegrationFlowRegistration} |
| 274 | + * control object. |
| 275 | + * @return the {@link IntegrationFlowRegistration} instance. |
| 276 | + */ |
237 | 277 | public IntegrationFlowRegistration register() { |
238 | 278 | IntegrationFlowContext.this.register(this); |
239 | 279 | return this.integrationFlowRegistration; |
|
0 commit comments