activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r434397 - /incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/AbstractRegion.java
Date Thu, 24 Aug 2006 14:01:32 GMT
Author: jstrachan
Date: Thu Aug 24 07:01:30 2006
New Revision: 434397

URL: http://svn.apache.org/viewvc?rev=434397&view=rev
Log:
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

Modified:
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/AbstractRegion.java

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/AbstractRegion.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/AbstractRegion.java?rev=434397&r1=434396&r2=434397&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/AbstractRegion.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/AbstractRegion.java
Thu Aug 24 07:01:30 2006
@@ -77,24 +77,32 @@
     
     public Destination addDestination(ConnectionContext context, ActiveMQDestination destination)
throws Exception {
         log.debug("Adding destination: "+destination);
-        Destination dest = createDestination(context, destination);
         
-        // intercept if there is a valid interceptor defined
-        DestinationInterceptor destinationInterceptor = broker.getDestinationInterceptor();
-        if (destinationInterceptor != null) {
-            dest = destinationInterceptor.intercept(dest);
-        }
-        
-        dest.start();
-        synchronized(destinationsMutex){
-            destinations.put(destination,dest);
-            destinationMap.put(destination,dest);
-            
-            // 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);
+        synchronized (destinationsMutex) {
+            Destination dest = (Destination) destinations.get(destination);
+            if (dest != null) {
+                log.warn("Attempt to add destination which is already created: " + destination);
+            }
+            else {
+                dest = createDestination(context, destination);
+
+                // intercept if there is a valid interceptor defined
+                DestinationInterceptor destinationInterceptor = broker.getDestinationInterceptor();
+                if (destinationInterceptor != null) {
+                    dest = destinationInterceptor.intercept(dest);
+                }
+
+                dest.start();
+
+                destinations.put(destination, dest);
+                destinationMap.put(destination, dest);
+
+                // 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;



Mime
View raw message