INT-2347 Update Channel Mappings Atomically

Ensure consistent state if channel map is replaced
dynamically.

Backport to 2.0.x.
This commit is contained in:
Gary Russell
2012-01-03 11:15:20 -05:00
parent 42f95faa61
commit 52faf04469

View File

@@ -47,6 +47,7 @@ import org.springframework.util.StringUtils;
*
* @author Mark Fisher
* @author Oleg Zhurakousky
* @author Gary Russell
*/
@ManagedResource
public abstract class AbstractMessageRouter extends AbstractMessageHandler {
@@ -101,8 +102,14 @@ public abstract class AbstractMessageRouter extends AbstractMessageHandler {
* @param channelIdentifierMap
*/
public void setChannelIdentifierMap(Map<String, String> channelIdentifierMap) {
this.channelIdentifierMap.clear();
this.channelIdentifierMap.putAll(channelIdentifierMap);
Map<String, String> oldChannelIdentifierMap = this.channelIdentifierMap;
Map<String, String> newChannelIdentifierMap = new ConcurrentHashMap<String, String>();
newChannelIdentifierMap.putAll(channelIdentifierMap);
this.channelIdentifierMap = newChannelIdentifierMap;
if (logger.isDebugEnabled()) {
logger.debug("Channel mappings:" + oldChannelIdentifierMap
+ " replaced with:" + newChannelIdentifierMap);
}
}
@ManagedOperation