Skip to content

Commit bd0fd50

Browse files
garyrussellartembilan
authored andcommitted
INT-4514: Integration Graph, include dynamic flows
JIRA: https://jira.spring.io/browse/INT-4514 `getBeansOfType()` with eager init does not currently return late registered singletons. We should not be eagerly initializing here anyway. **cherry-pick to 5.0.x**
1 parent cdba9a7 commit bd0fd50

File tree

2 files changed

+37
-20
lines changed

2 files changed

+37
-20
lines changed

spring-integration-core/src/main/java/org/springframework/integration/graph/IntegrationGraphServer.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ private synchronized Graph buildGraph() {
136136

137137
private Map<String, MessageChannelNode> channels(Collection<IntegrationNode> nodes) {
138138
Map<String, MessageChannel> channels = this.applicationContext
139-
.getBeansOfType(MessageChannel.class);
139+
.getBeansOfType(MessageChannel.class, true, false);
140140
Map<String, MessageChannelNode> channelNodes = new HashMap<>();
141141
for (Entry<String, MessageChannel> entry : channels.entrySet()) {
142142
MessageChannel channel = entry.getValue();
@@ -152,7 +152,7 @@ private void pollingAdapters(Collection<IntegrationNode> nodes, Collection<LinkN
152152
Map<String, MessageChannelNode> channelNodes) {
153153

154154
Map<String, SourcePollingChannelAdapter> spcas = this.applicationContext
155-
.getBeansOfType(SourcePollingChannelAdapter.class);
155+
.getBeansOfType(SourcePollingChannelAdapter.class, true, false);
156156
for (Entry<String, SourcePollingChannelAdapter> entry : spcas.entrySet()) {
157157
SourcePollingChannelAdapter adapter = entry.getValue();
158158
MessageSourceNode sourceNode = this.nodeFactory.sourceNode(entry.getKey(), adapter);
@@ -165,15 +165,15 @@ private void gateways(Collection<IntegrationNode> nodes, Collection<LinkNode> li
165165
Map<String, MessageChannelNode> channelNodes) {
166166

167167
Map<String, MessagingGatewaySupport> gateways = this.applicationContext
168-
.getBeansOfType(MessagingGatewaySupport.class);
168+
.getBeansOfType(MessagingGatewaySupport.class, true, false);
169169
for (Entry<String, MessagingGatewaySupport> entry : gateways.entrySet()) {
170170
MessagingGatewaySupport gateway = entry.getValue();
171171
MessageGatewayNode gatewayNode = this.nodeFactory.gatewayNode(entry.getKey(), gateway);
172172
nodes.add(gatewayNode);
173173
producerLink(links, channelNodes, gatewayNode);
174174
}
175175
Map<String, GatewayProxyFactoryBean> gpfbs = this.applicationContext
176-
.getBeansOfType(GatewayProxyFactoryBean.class);
176+
.getBeansOfType(GatewayProxyFactoryBean.class, true, false);
177177
for (Entry<String, GatewayProxyFactoryBean> entry : gpfbs.entrySet()) {
178178
Map<Method, MessagingGatewaySupport> methodMap = entry.getValue().getGateways();
179179
for (Entry<Method, MessagingGatewaySupport> gwEntry : methodMap.entrySet()) {
@@ -199,7 +199,7 @@ private void producers(Collection<IntegrationNode> nodes, Collection<LinkNode> l
199199
Map<String, MessageChannelNode> channelNodes) {
200200

201201
Map<String, MessageProducerSupport> producers = this.applicationContext
202-
.getBeansOfType(MessageProducerSupport.class);
202+
.getBeansOfType(MessageProducerSupport.class, true, false);
203203
for (Entry<String, MessageProducerSupport> entry : producers.entrySet()) {
204204
MessageProducerSupport producer = entry.getValue();
205205
MessageProducerNode producerNode = this.nodeFactory.producerNode(entry.getKey(), producer);
@@ -211,7 +211,8 @@ private void producers(Collection<IntegrationNode> nodes, Collection<LinkNode> l
211211
private void consumers(Collection<IntegrationNode> nodes, Collection<LinkNode> links,
212212
Map<String, MessageChannelNode> channelNodes) {
213213

214-
Map<String, IntegrationConsumer> consumers = this.applicationContext.getBeansOfType(IntegrationConsumer.class);
214+
Map<String, IntegrationConsumer> consumers = this.applicationContext.getBeansOfType(IntegrationConsumer.class,
215+
true, false);
215216
for (Entry<String, IntegrationConsumer> entry : consumers.entrySet()) {
216217
IntegrationConsumer consumer = entry.getValue();
217218
MessageHandlerNode handlerNode = consumer instanceof PollingConsumer

spring-integration-core/src/test/java/org/springframework/integration/support/management/graph/IntegrationGraphServerTests.java

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@
1616

1717
package org.springframework.integration.support.management.graph;
1818

19-
import static org.hamcrest.Matchers.equalTo;
20-
import static org.hamcrest.Matchers.is;
21-
import static org.hamcrest.Matchers.notNullValue;
22-
import static org.junit.Assert.assertThat;
19+
import static org.assertj.core.api.Assertions.assertThat;
2320

2421
import java.io.ByteArrayOutputStream;
2522
import java.util.Arrays;
@@ -45,6 +42,9 @@
4542
import org.springframework.integration.config.EnableIntegration;
4643
import org.springframework.integration.config.EnableIntegrationManagement;
4744
import org.springframework.integration.core.MessageProducer;
45+
import org.springframework.integration.dsl.IntegrationFlow;
46+
import org.springframework.integration.dsl.context.IntegrationFlowContext;
47+
import org.springframework.integration.dsl.context.IntegrationFlowContext.IntegrationFlowRegistration;
4848
import org.springframework.integration.endpoint.EventDrivenConsumer;
4949
import org.springframework.integration.endpoint.MessageProducerSupport;
5050
import org.springframework.integration.endpoint.PollingConsumer;
@@ -85,6 +85,9 @@ public class IntegrationGraphServerTests {
8585
@Autowired
8686
private MessageChannel toRouter;
8787

88+
@Autowired
89+
private IntegrationFlowContext flowContext;
90+
8891
@SuppressWarnings("unchecked")
8992
@Test
9093
public void test() throws Exception {
@@ -97,13 +100,13 @@ public void test() throws Exception {
97100
// System . out . println(new String(baos.toByteArray()));
98101

99102
Map<?, ?> map = objectMapper.readValue(baos.toByteArray(), Map.class);
100-
assertThat(map.size(), is(equalTo(3)));
103+
assertThat(map.size()).isEqualTo(3);
101104
List<Map<?, ?>> nodes = (List<Map<?, ?>>) map.get("nodes");
102-
assertThat(nodes, is(notNullValue()));
103-
assertThat(nodes.size(), is(equalTo(32)));
105+
assertThat(nodes).isNotNull();
106+
assertThat(nodes.size()).isEqualTo(32);
104107
List<Map<?, ?>> links = (List<Map<?, ?>>) map.get("links");
105-
assertThat(links, is(notNullValue()));
106-
assertThat(links.size(), is(equalTo(33)));
108+
assertThat(links).isNotNull();
109+
assertThat(links.size()).isEqualTo(33);
107110

108111
toRouter.send(MessageBuilder.withPayload("foo").setHeader("foo", "bar").build());
109112
toRouter.send(MessageBuilder.withPayload("foo").setHeader("foo", "baz").build());
@@ -119,13 +122,26 @@ public void test() throws Exception {
119122
// System . out . println(new String(baos.toByteArray()));
120123

121124
map = objectMapper.readValue(baos.toByteArray(), Map.class);
122-
assertThat(map.size(), is(equalTo(3)));
125+
assertThat(map.size()).isEqualTo(3);
123126
nodes = (List<Map<?, ?>>) map.get("nodes");
124-
assertThat(nodes, is(notNullValue()));
125-
assertThat(nodes.size(), is(equalTo(32)));
127+
assertThat(nodes).isNotNull();
128+
assertThat(nodes.size()).isEqualTo(32);
126129
links = (List<Map<?, ?>>) map.get("links");
127-
assertThat(links, is(notNullValue()));
128-
assertThat(links.size(), is(equalTo(35)));
130+
assertThat(links).isNotNull();
131+
assertThat(links.size()).isEqualTo(35);
132+
}
133+
134+
@Test
135+
public void testIncludesDynamic() {
136+
Graph graph = this.server.getGraph();
137+
assertThat(graph.getNodes().size()).isEqualTo(32);
138+
IntegrationFlow flow = f -> f.handle(m -> { });
139+
IntegrationFlowRegistration reg = this.flowContext.registration(flow).register();
140+
graph = this.server.rebuild();
141+
assertThat(graph.getNodes().size()).isEqualTo(34);
142+
this.flowContext.remove(reg.getId());
143+
graph = this.server.rebuild();
144+
assertThat(graph.getNodes().size()).isEqualTo(32);
129145
}
130146

131147
@Configuration

0 commit comments

Comments
 (0)