From ae9cfc3ea5b52377901c4f71078e8218bfda2193 Mon Sep 17 00:00:00 2001 From: Gary Russell Date: Sat, 16 Apr 2016 10:03:33 -0400 Subject: [PATCH] INT-3967: Sonar Issues https://sonar.spring.io/issues/search#componentRoots=org.springframework.integration%3Aspring-integration|createdAt=2016-04-16T02%3A56%3A21%2B0000|sort=UPDATE_DATE|asc=false --- .../graph/IntegrationGraphServer.java | 51 ++++++++++++++----- 1 file changed, 38 insertions(+), 13 deletions(-) diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/management/graph/IntegrationGraphServer.java b/spring-integration-core/src/main/java/org/springframework/integration/support/management/graph/IntegrationGraphServer.java index dd8e2666c6..8122b07e82 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/management/graph/IntegrationGraphServer.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/support/management/graph/IntegrationGraphServer.java @@ -61,7 +61,7 @@ public class IntegrationGraphServer implements ApplicationContextAware, Applicat * @see #rebuild() */ public Graph getGraph() { - if (this.graph == null) { + if (this.graph == null) { //NOSONAR (sync) synchronized (this) { if (this.graph == null) { buildGraph(); @@ -80,17 +80,20 @@ public class IntegrationGraphServer implements ApplicationContextAware, Applicat private synchronized Graph buildGraph() { this.nodeFactory.reset(); - Map channels = this.applicationContext - .getBeansOfType(MessageChannel.class); - Map spcas = this.applicationContext - .getBeansOfType(SourcePollingChannelAdapter.class); - Map gateways = this.applicationContext - .getBeansOfType(MessagingGatewaySupport.class); - Map producers = this.applicationContext - .getBeansOfType(MessageProducerSupport.class); - Map consumers = this.applicationContext.getBeansOfType(IntegrationConsumer.class); Collection nodes = new ArrayList(); Collection links = new ArrayList(); + Map channelNodes = channels(nodes); + pollingAdapters(nodes, links, channelNodes); + gateways(nodes, links, channelNodes); + producers(nodes, links, channelNodes); + consumers(nodes, links, channelNodes); + this.graph = new Graph(nodes, links); + return this.graph; + } + + private Map channels(Collection nodes) { + Map channels = this.applicationContext + .getBeansOfType(MessageChannel.class); Map channelNodes = new HashMap(); for (Entry entry : channels.entrySet()) { MessageChannel channel = entry.getValue(); @@ -99,6 +102,13 @@ public class IntegrationGraphServer implements ApplicationContextAware, Applicat nodes.add(channelNode); channelNodes.put(beanName, channelNode); } + return channelNodes; + } + + private void pollingAdapters(Collection nodes, Collection links, + Map channelNodes) { + Map spcas = this.applicationContext + .getBeansOfType(SourcePollingChannelAdapter.class); for (Entry entry : spcas.entrySet()) { SourcePollingChannelAdapter adapter = entry.getValue(); MessageSourceNode sourceNode = this.nodeFactory.sourceNode(entry.getKey(), adapter); @@ -108,6 +118,12 @@ public class IntegrationGraphServer implements ApplicationContextAware, Applicat links.add(new LinkNode(sourceNode.getNodeId(), channelNode.getNodeId())); } } + } + + private void gateways(Collection nodes, Collection links, + Map channelNodes) { + Map gateways = this.applicationContext + .getBeansOfType(MessagingGatewaySupport.class); for (Entry entry : gateways.entrySet()) { MessagingGatewaySupport gateway = entry.getValue(); MessageGatewayNode gatewayNode = this.nodeFactory.gatewayNode(entry.getKey(), gateway); @@ -117,6 +133,12 @@ public class IntegrationGraphServer implements ApplicationContextAware, Applicat links.add(new LinkNode(gatewayNode.getNodeId(), channelInfo.getNodeId())); } } + } + + private void producers(Collection nodes, Collection links, + Map channelNodes) { + Map producers = this.applicationContext + .getBeansOfType(MessageProducerSupport.class); for (Entry entry : producers.entrySet()) { MessageProducerSupport producer = entry.getValue(); MessageProducerNode producerNode = this.nodeFactory.producerNode(entry.getKey(), producer); @@ -126,6 +148,11 @@ public class IntegrationGraphServer implements ApplicationContextAware, Applicat links.add(new LinkNode(producerNode.getNodeId(), channelNode.getNodeId())); } } + } + + private void consumers(Collection nodes, Collection links, + Map channelNodes) { + Map consumers = this.applicationContext.getBeansOfType(IntegrationConsumer.class); for (Entry entry : consumers.entrySet()) { IntegrationConsumer consumer = entry.getValue(); MessageHandlerNode handlerNode = this.nodeFactory.handlerNode(entry.getKey(), consumer); @@ -141,8 +168,6 @@ public class IntegrationGraphServer implements ApplicationContextAware, Applicat } } } - this.graph = new Graph(nodes, links); - return this.graph; } /** @@ -155,7 +180,7 @@ public class IntegrationGraphServer implements ApplicationContextAware, Applicat return buildGraph(); } - private final static class NodeFactory { + private static final class NodeFactory { private final AtomicInteger nodeId = new AtomicInteger();