From 4009ca25b3dab5bccb7d5716673acf6c4c8cd967 Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Mon, 2 May 2011 18:50:30 -0400 Subject: [PATCH] INT-1814 polishing --- .../channel/AbstractSubscribableChannel.java | 15 ++++++++------- .../integration/channel/P2pChannelTests.java | 5 ++++- 2 files changed, 12 insertions(+), 8 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 6c362983e6..3c81134025 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 @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009 the original author or authors. + * Copyright 2002-2011 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,22 +35,23 @@ import org.springframework.util.Assert; */ public abstract class AbstractSubscribableChannel extends AbstractMessageChannel implements SubscribableChannel { - private final AtomicInteger handlers = new AtomicInteger(); + private final AtomicInteger handlerCounter = new AtomicInteger(); public boolean subscribe(MessageHandler handler) { MessageDispatcher dispatcher = this.getRequiredDispatcher(); boolean added = dispatcher.addHandler(handler); - if (added){ - int counter = handlers.incrementAndGet(); - logger.info("Channel '" + this.getComponentName() + "' has " + counter + " subscriber(s). "); + if (added) { + int counter = handlerCounter.incrementAndGet(); + if (logger.isInfoEnabled()) { + logger.info("Channel '" + this.getComponentName() + "' has " + counter + " subscriber(s)."); + } } - return added; } public boolean unsubscribe(MessageHandler handle) { if (this.getRequiredDispatcher() instanceof UnicastingDispatcher){ - handlers.getAndDecrement(); + handlerCounter.getAndDecrement(); } return this.getRequiredDispatcher().removeHandler(handle); } 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 2155fc7964..89a744215c 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 @@ -18,6 +18,7 @@ package org.springframework.integration.channel; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import java.lang.reflect.Field; import java.util.concurrent.Executor; @@ -41,8 +42,8 @@ public class P2pChannelTests { final DirectChannel channel = new DirectChannel(); channel.setBeanName("directChannel"); - final Log logger = mock(Log.class); + when(logger.isInfoEnabled()).thenReturn(true); ReflectionUtils.doWithFields(AbstractMessageChannel.class, new FieldCallback() { public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException { @@ -64,6 +65,7 @@ public class P2pChannelTests { channel.setBeanName("executorChannel"); final Log logger = mock(Log.class); + when(logger.isInfoEnabled()).thenReturn(true); ReflectionUtils.doWithFields(AbstractMessageChannel.class, new FieldCallback() { public void doWith(Field field) throws IllegalArgumentException, @@ -85,6 +87,7 @@ public class P2pChannelTests { channel.setBeanName("pubSubChannel"); final Log logger = mock(Log.class); + when(logger.isInfoEnabled()).thenReturn(true); ReflectionUtils.doWithFields(AbstractMessageChannel.class, new FieldCallback() { public void doWith(Field field) throws IllegalArgumentException,