Skip to content

Commit c50a135

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** # Conflicts: # spring-integration-core/src/main/java/org/springframework/integration/support/management/graph/IntegrationGraphServer.java
1 parent b47c0de commit c50a135

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/support/management/graph/IntegrationGraphServer.java

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

136136
private Map<String, MessageChannelNode> channels(Collection<IntegrationNode> nodes) {
137137
Map<String, MessageChannel> channels = this.applicationContext
138-
.getBeansOfType(MessageChannel.class);
138+
.getBeansOfType(MessageChannel.class, true, false);
139139
Map<String, MessageChannelNode> channelNodes = new HashMap<String, MessageChannelNode>();
140140
for (Entry<String, MessageChannel> entry : channels.entrySet()) {
141141
MessageChannel channel = entry.getValue();
@@ -150,7 +150,7 @@ private Map<String, MessageChannelNode> channels(Collection<IntegrationNode> nod
150150
private void pollingAdapters(Collection<IntegrationNode> nodes, Collection<LinkNode> links,
151151
Map<String, MessageChannelNode> channelNodes) {
152152
Map<String, SourcePollingChannelAdapter> spcas = this.applicationContext
153-
.getBeansOfType(SourcePollingChannelAdapter.class);
153+
.getBeansOfType(SourcePollingChannelAdapter.class, true, false);
154154
for (Entry<String, SourcePollingChannelAdapter> entry : spcas.entrySet()) {
155155
SourcePollingChannelAdapter adapter = entry.getValue();
156156
MessageSourceNode sourceNode = this.nodeFactory.sourceNode(entry.getKey(), adapter);
@@ -162,15 +162,15 @@ private void pollingAdapters(Collection<IntegrationNode> nodes, Collection<LinkN
162162
private void gateways(Collection<IntegrationNode> nodes, Collection<LinkNode> links,
163163
Map<String, MessageChannelNode> channelNodes) {
164164
Map<String, MessagingGatewaySupport> gateways = this.applicationContext
165-
.getBeansOfType(MessagingGatewaySupport.class);
165+
.getBeansOfType(MessagingGatewaySupport.class, true, false);
166166
for (Entry<String, MessagingGatewaySupport> entry : gateways.entrySet()) {
167167
MessagingGatewaySupport gateway = entry.getValue();
168168
MessageGatewayNode gatewayNode = this.nodeFactory.gatewayNode(entry.getKey(), gateway);
169169
nodes.add(gatewayNode);
170170
producerLink(links, channelNodes, gatewayNode);
171171
}
172172
Map<String, GatewayProxyFactoryBean> gpfbs = this.applicationContext
173-
.getBeansOfType(GatewayProxyFactoryBean.class);
173+
.getBeansOfType(GatewayProxyFactoryBean.class, true, false);
174174
for (Entry<String, GatewayProxyFactoryBean> entry : gpfbs.entrySet()) {
175175
Map<Method, MessagingGatewaySupport> methodMap = entry.getValue().getGateways();
176176
for (Entry<Method, MessagingGatewaySupport> gwEntry : methodMap.entrySet()) {
@@ -195,7 +195,7 @@ private void gateways(Collection<IntegrationNode> nodes, Collection<LinkNode> li
195195
private void producers(Collection<IntegrationNode> nodes, Collection<LinkNode> links,
196196
Map<String, MessageChannelNode> channelNodes) {
197197
Map<String, MessageProducerSupport> producers = this.applicationContext
198-
.getBeansOfType(MessageProducerSupport.class);
198+
.getBeansOfType(MessageProducerSupport.class, true, false);
199199
for (Entry<String, MessageProducerSupport> entry : producers.entrySet()) {
200200
MessageProducerSupport producer = entry.getValue();
201201
MessageProducerNode producerNode = this.nodeFactory.producerNode(entry.getKey(), producer);
@@ -206,7 +206,8 @@ private void producers(Collection<IntegrationNode> nodes, Collection<LinkNode> l
206206

207207
private void consumers(Collection<IntegrationNode> nodes, Collection<LinkNode> links,
208208
Map<String, MessageChannelNode> channelNodes) {
209-
Map<String, IntegrationConsumer> consumers = this.applicationContext.getBeansOfType(IntegrationConsumer.class);
209+
Map<String, IntegrationConsumer> consumers = this.applicationContext.getBeansOfType(IntegrationConsumer.class,
210+
true, false);
210211
for (Entry<String, IntegrationConsumer> entry : consumers.entrySet()) {
211212
IntegrationConsumer consumer = entry.getValue();
212213
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.IntegrationFlowRegistration;
4848
import org.springframework.integration.endpoint.EventDrivenConsumer;
4949
import org.springframework.integration.endpoint.MessageProducerSupport;
5050
import org.springframework.integration.endpoint.PollingConsumer;
@@ -82,6 +82,9 @@ public class IntegrationGraphServerTests {
8282
@Autowired
8383
private MessageChannel toRouter;
8484

85+
@Autowired
86+
private IntegrationFlowContext flowContext;
87+
8588
@SuppressWarnings("unchecked")
8689
@Test
8790
public void test() throws Exception {
@@ -94,13 +97,13 @@ public void test() throws Exception {
9497
// System . out . println(new String(baos.toByteArray()));
9598

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

105108
toRouter.send(MessageBuilder.withPayload("foo").setHeader("foo", "bar").build());
106109
toRouter.send(MessageBuilder.withPayload("foo").setHeader("foo", "baz").build());
@@ -116,13 +119,26 @@ public void test() throws Exception {
116119
// System . out . println(new String(baos.toByteArray()));
117120

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

128144
@Configuration

0 commit comments

Comments
 (0)