From aa5119711bc7ecd2cb1f1d7a9a0bdd843d7130b4 Mon Sep 17 00:00:00 2001 From: Oleg Zhurakousky Date: Wed, 2 Mar 2011 14:11:35 -0500 Subject: [PATCH] INT-1815 added logging for all SubscribableChannels as well as EventDrovenConsumer handler when it subscribes to a Channel --- .../channel/AbstractSubscribableChannel.java | 11 ++++------- .../integration/endpoint/EventDrivenConsumer.java | 13 +++++++++++++ .../integration/channel/P2pChannelTests.java | 9 +++------ 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/spring-integration-core/src/main/java/org/springframework/integration/channel/AbstractSubscribableChannel.java b/spring-integration-core/src/main/java/org/springframework/integration/channel/AbstractSubscribableChannel.java index 93f5bd41a7..6c362983e6 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/channel/AbstractSubscribableChannel.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/channel/AbstractSubscribableChannel.java @@ -39,16 +39,13 @@ public abstract class AbstractSubscribableChannel extends AbstractMessageChannel public boolean subscribe(MessageHandler handler) { MessageDispatcher dispatcher = this.getRequiredDispatcher(); - if (dispatcher instanceof UnicastingDispatcher){ + boolean added = dispatcher.addHandler(handler); + if (added){ int counter = handlers.incrementAndGet(); - if (counter > 1){ - String message = "Point-to-Point channel '" + this.getComponentName() + "' has more then 1 subscriber - (" + counter + "). " + - "If load balancing strategy is provided, messages will be dispatched following its rules."; - this.logger.info(message); - } + logger.info("Channel '" + this.getComponentName() + "' has " + counter + " subscriber(s). "); } - return dispatcher.addHandler(handler); + return added; } public boolean unsubscribe(MessageHandler handle) { diff --git a/spring-integration-core/src/main/java/org/springframework/integration/endpoint/EventDrivenConsumer.java b/spring-integration-core/src/main/java/org/springframework/integration/endpoint/EventDrivenConsumer.java index 191561de6a..30b0ee2076 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/endpoint/EventDrivenConsumer.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/endpoint/EventDrivenConsumer.java @@ -16,9 +16,12 @@ package org.springframework.integration.endpoint; +import org.springframework.integration.channel.AbstractSubscribableChannel; +import org.springframework.integration.context.IntegrationObjectSupport; import org.springframework.integration.core.MessageHandler; import org.springframework.integration.core.SubscribableChannel; import org.springframework.util.Assert; +import org.springframework.util.StringUtils; /** * Message Endpoint that connects any {@link MessageHandler} implementation to a {@link SubscribableChannel}. @@ -44,6 +47,16 @@ public class EventDrivenConsumer extends AbstractEndpoint { @Override protected void doStart() { + if (this.handler instanceof IntegrationObjectSupport){ + String channelName = ((AbstractSubscribableChannel)this.inputChannel).getComponentName(); + String componentType = ((IntegrationObjectSupport)this.handler).getComponentType(); + componentType = StringUtils.hasText(componentType) ? componentType : ""; + String componentName = ((IntegrationObjectSupport)this).getComponentName(); + componentName = (StringUtils.hasText(componentName) && componentName.contains("#")) ? "" : ":" + componentName; + + logger.info("Adding {" + componentType + componentName + "} as a subscriber to the '" + channelName + "' channel"); + } + this.inputChannel.subscribe(this.handler); } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/channel/P2pChannelTests.java b/spring-integration-core/src/test/java/org/springframework/integration/channel/P2pChannelTests.java index 623514864c..2155fc7964 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/channel/P2pChannelTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/channel/P2pChannelTests.java @@ -54,9 +54,8 @@ public class P2pChannelTests { }); channel.subscribe(mock(MessageHandler.class)); - verify(logger, times(0)).info(Mockito.anyString()); channel.subscribe(mock(MessageHandler.class)); - verify(logger, times(1)).info(Mockito.anyString()); + verify(logger, times(2)).info(Mockito.anyString()); } @Test @@ -76,9 +75,8 @@ public class P2pChannelTests { } }); channel.subscribe(mock(MessageHandler.class)); - verify(logger, times(0)).info(Mockito.anyString()); channel.subscribe(mock(MessageHandler.class)); - verify(logger, times(1)).info(Mockito.anyString()); + verify(logger, times(2)).info(Mockito.anyString()); } @Test @@ -98,8 +96,7 @@ public class P2pChannelTests { } }); channel.subscribe(mock(MessageHandler.class)); - verify(logger, times(0)).info(Mockito.anyString()); channel.subscribe(mock(MessageHandler.class)); - verify(logger, times(0)).info(Mockito.anyString()); + verify(logger, times(2)).info(Mockito.anyString()); } }