Removed the 'unregisterChannel' method from ChannelRegistry. DefaultMessageBus now implements ChannelRegistry directly (no longer delegates to DefaultChannelRegistry).

This commit is contained in:
Mark Fisher
2008-09-29 18:37:26 +00:00
parent f0d6a78c0c
commit 4954228395
5 changed files with 8 additions and 47 deletions

View File

@@ -20,6 +20,7 @@ import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy;
@@ -40,9 +41,7 @@ import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.context.event.SimpleApplicationEventMulticaster;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.integration.ConfigurationException;
import org.springframework.integration.channel.ChannelRegistry;
import org.springframework.integration.channel.ChannelRegistryAware;
import org.springframework.integration.channel.DefaultChannelRegistry;
import org.springframework.integration.channel.MessageChannel;
import org.springframework.integration.channel.MessagePublishingErrorHandler;
import org.springframework.integration.endpoint.MessageEndpoint;
@@ -67,7 +66,7 @@ public class DefaultMessageBus implements MessageBus, ApplicationContextAware, A
private final Log logger = LogFactory.getLog(this.getClass());
private final ChannelRegistry channelRegistry = new DefaultChannelRegistry();
private final Map<String, MessageChannel> channels = new ConcurrentHashMap<String, MessageChannel>();
private final MessageBusInterceptorsList interceptors = new MessageBusInterceptorsList();
@@ -185,7 +184,7 @@ public class DefaultMessageBus implements MessageBus, ApplicationContextAware, A
}
public MessageChannel lookupChannel(String channelName) {
MessageChannel channel = this.channelRegistry.lookupChannel(channelName);
MessageChannel channel = this.channels.get(channelName);
if (channel == null && this.applicationContext != null && this.applicationContext.containsBean(channelName)) {
Object bean = this.applicationContext.getBean(channelName);
if (bean instanceof MessageChannel) {
@@ -197,16 +196,14 @@ public class DefaultMessageBus implements MessageBus, ApplicationContextAware, A
}
public void registerChannel(MessageChannel channel) {
this.channelRegistry.registerChannel(channel);
Assert.notNull(channel, "'channel' must not be null");
Assert.notNull(channel.getName(), "channel name must not be null");
this.channels.put(channel.getName(), channel);
if (logger.isInfoEnabled()) {
logger.info("registered channel '" + channel.getName() + "'");
}
}
public MessageChannel unregisterChannel(String name) {
return this.channelRegistry.unregisterChannel(name);
}
public void registerEndpoint(MessageEndpoint endpoint) {
Assert.notNull(endpoint, "'endpoint' must not be null");
if (this.isRunning()) {

View File

@@ -28,8 +28,6 @@ public interface ChannelRegistry {
void registerChannel(MessageChannel channel);
MessageChannel unregisterChannel(String name);
MessageChannel lookupChannel(String channelName);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 the original author or authors.
* Copyright 2002-2008 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.

View File

@@ -41,8 +41,4 @@ public class DefaultChannelRegistry implements ChannelRegistry {
this.channels.put(channel.getName(), channel);
}
public MessageChannel unregisterChannel(String name) {
return (name != null) ? this.channels.remove(name) : null;
}
}

View File

@@ -39,40 +39,10 @@ public class DefaultChannelRegistryTests {
}
@Test
public void testLookupNeverRegisteredChannel() {
public void testLookupNonRegisteredChannel() {
DefaultChannelRegistry registry = new DefaultChannelRegistry();
MessageChannel noSuchChannel = registry.lookupChannel("noSuchChannel");
assertNull(noSuchChannel);
}
@Test
public void testLookupUnregisteredChannel() {
QueueChannel testChannel = new QueueChannel();
testChannel.setBeanName("testChannel");
DefaultChannelRegistry registry = new DefaultChannelRegistry();
registry.registerChannel(testChannel);
MessageChannel lookedUpChannel1 = registry.lookupChannel("testChannel");
assertNotNull(lookedUpChannel1);
assertSame(testChannel, lookedUpChannel1);
MessageChannel unregisteredChannel = registry.unregisterChannel("testChannel");
assertNotNull(unregisteredChannel);
assertSame(testChannel, unregisteredChannel);
MessageChannel lookedUpChannel2 = registry.lookupChannel("testChannel");
assertNull(lookedUpChannel2);
}
@Test
public void testUnregisteringChannelThatIsNotInRegistry() {
DefaultChannelRegistry registry = new DefaultChannelRegistry();
MessageChannel unregisteredChannel = registry.unregisterChannel("noSuchChannel");
assertNull(unregisteredChannel);
}
@Test
public void testUnregisteringNullDoesNotThrowException() {
DefaultChannelRegistry registry = new DefaultChannelRegistry();
MessageChannel unregisteredChannel = registry.unregisterChannel(null);
assertNull(unregisteredChannel);
}
}