avoid the possibility that 2 threads could attempt to add a destination at the same time causing it to be created twice and avoid issues such as duplicate registration in JMX

git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@434397 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
James Strachan 2006-08-24 14:01:30 +00:00
parent d4a50a7340
commit a420312a40
1 changed files with 25 additions and 17 deletions

View File

@ -77,24 +77,32 @@ abstract public class AbstractRegion implements Region {
public Destination addDestination(ConnectionContext context, ActiveMQDestination destination) throws Exception { public Destination addDestination(ConnectionContext context, ActiveMQDestination destination) throws Exception {
log.debug("Adding destination: "+destination); log.debug("Adding destination: "+destination);
Destination dest = createDestination(context, destination);
// intercept if there is a valid interceptor defined synchronized (destinationsMutex) {
DestinationInterceptor destinationInterceptor = broker.getDestinationInterceptor(); Destination dest = (Destination) destinations.get(destination);
if (destinationInterceptor != null) { if (dest != null) {
dest = destinationInterceptor.intercept(dest); log.warn("Attempt to add destination which is already created: " + destination);
} }
else {
dest = createDestination(context, destination);
dest.start(); // intercept if there is a valid interceptor defined
synchronized(destinationsMutex){ DestinationInterceptor destinationInterceptor = broker.getDestinationInterceptor();
destinations.put(destination,dest); if (destinationInterceptor != null) {
destinationMap.put(destination,dest); dest = destinationInterceptor.intercept(dest);
}
// Add all consumers that are interested in the destination. dest.start();
for (Iterator iter = subscriptions.values().iterator(); iter.hasNext();) {
Subscription sub = (Subscription) iter.next(); destinations.put(destination, dest);
if( sub.matches(destination) ) { destinationMap.put(destination, dest);
dest.addSubscription(context, sub);
// Add all consumers that are interested in the destination.
for (Iterator iter = subscriptions.values().iterator(); iter.hasNext();) {
Subscription sub = (Subscription) iter.next();
if (sub.matches(destination)) {
dest.addSubscription(context, sub);
}
} }
} }
return dest; return dest;