diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/bus/DefaultMessageBus.java b/org.springframework.integration/src/main/java/org/springframework/integration/bus/DefaultMessageBus.java index c402ec5d6a..db60f40601 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/bus/DefaultMessageBus.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/bus/DefaultMessageBus.java @@ -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 channels = new ConcurrentHashMap(); 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()) { diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/channel/ChannelRegistry.java b/org.springframework.integration/src/main/java/org/springframework/integration/channel/ChannelRegistry.java index 48a9ffaf47..c355f12c6b 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/channel/ChannelRegistry.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/channel/ChannelRegistry.java @@ -28,8 +28,6 @@ public interface ChannelRegistry { void registerChannel(MessageChannel channel); - MessageChannel unregisterChannel(String name); - MessageChannel lookupChannel(String channelName); } diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/channel/ChannelRegistryAware.java b/org.springframework.integration/src/main/java/org/springframework/integration/channel/ChannelRegistryAware.java index 267538535b..1f5f2773d4 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/channel/ChannelRegistryAware.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/channel/ChannelRegistryAware.java @@ -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. diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/channel/DefaultChannelRegistry.java b/org.springframework.integration/src/main/java/org/springframework/integration/channel/DefaultChannelRegistry.java index 4d1993e41e..b0bff79794 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/channel/DefaultChannelRegistry.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/channel/DefaultChannelRegistry.java @@ -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; - } - } diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/channel/DefaultChannelRegistryTests.java b/org.springframework.integration/src/test/java/org/springframework/integration/channel/DefaultChannelRegistryTests.java index 4ecb5703fa..b6da5ad87c 100644 --- a/org.springframework.integration/src/test/java/org/springframework/integration/channel/DefaultChannelRegistryTests.java +++ b/org.springframework.integration/src/test/java/org/springframework/integration/channel/DefaultChannelRegistryTests.java @@ -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); - } - }