INT-1814 polishing
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user