From 5750ca5ff5fcf01ed69d6d3624ef46150193a22d Mon Sep 17 00:00:00 2001 From: Gary Russell Date: Tue, 3 Jan 2012 10:50:54 -0500 Subject: [PATCH] INT-2347 Update Channel Mappings Atomically Ensure consistent state if channel map is replaced dynamically. --- .../router/AbstractMappingMessageRouter.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/spring-integration-core/src/main/java/org/springframework/integration/router/AbstractMappingMessageRouter.java b/spring-integration-core/src/main/java/org/springframework/integration/router/AbstractMappingMessageRouter.java index 2cd65f807c..72f496b8b6 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/router/AbstractMappingMessageRouter.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/router/AbstractMappingMessageRouter.java @@ -42,11 +42,12 @@ import org.springframework.util.StringUtils; * @author Mark Fisher * @author Oleg Zhurakousky * @author Gunnar Hillert + * @author Gary Russell * @since 2.1 */ public abstract class AbstractMappingMessageRouter extends AbstractMessageRouter { - private final Map channelMappings = new ConcurrentHashMap(); + private volatile Map channelMappings = new ConcurrentHashMap(); private volatile ChannelResolver channelResolver; @@ -62,8 +63,14 @@ public abstract class AbstractMappingMessageRouter extends AbstractMessageRouter * Channel names will be resolved by the {@link ChannelResolver}. */ public void setChannelMappings(Map channelMappings) { - this.channelMappings.clear(); - this.channelMappings.putAll(channelMappings); + Map oldChannelMappings = this.channelMappings; + Map newChannelMappings = new ConcurrentHashMap(); + newChannelMappings.putAll(channelMappings); + this.channelMappings = newChannelMappings; + if (logger.isDebugEnabled()) { + logger.debug("Channel mappings:" + oldChannelMappings + + " replaced with:" + newChannelMappings); + } } /**