Author: dejanb
Date: Fri Oct 22 08:55:08 2010
New Revision: 1026254

URL: http://svn.apache.org/viewvc?rev=1026254&view=rev
Log:
https://issues.apache.org/activemq/browse/AMQ-2970 - refactor to avoid 
duplicate getConnectionContext() method

Modified:
    
activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java
    
activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/BrokerView.java
    
activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/QueueView.java
    
activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/BrokerSupport.java

Modified: 
activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java
URL: 
http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java?rev=1026254&r1=1026253&r2=1026254&view=diff
==============================================================================
--- 
activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java
 (original)
+++ 
activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java
 Fri Oct 22 08:55:08 2010
@@ -79,7 +79,6 @@ import org.apache.activemq.network.Netwo
 import org.apache.activemq.network.jms.JmsConnector;
 import org.apache.activemq.proxy.ProxyConnector;
 import org.apache.activemq.security.MessageAuthorizationPolicy;
-import org.apache.activemq.security.SecurityContext;
 import org.apache.activemq.selector.SelectorParser;
 import org.apache.activemq.store.PersistenceAdapter;
 import org.apache.activemq.store.PersistenceAdapterFactory;
@@ -92,13 +91,7 @@ import org.apache.activemq.transport.Tra
 import org.apache.activemq.transport.TransportServer;
 import org.apache.activemq.transport.vm.VMTransportFactory;
 import org.apache.activemq.usage.SystemUsage;
-import org.apache.activemq.util.DefaultIOExceptionHandler;
-import org.apache.activemq.util.IOExceptionHandler;
-import org.apache.activemq.util.IOExceptionSupport;
-import org.apache.activemq.util.IOHelper;
-import org.apache.activemq.util.JMXSupport;
-import org.apache.activemq.util.ServiceStopper;
-import org.apache.activemq.util.URISupport;
+import org.apache.activemq.util.*;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 /**
@@ -2017,25 +2010,7 @@ public class BrokerService implements Se
      * configuring the broker at startup
      */
     public ConnectionContext getAdminConnectionContext() throws Exception {
-        ConnectionContext adminConnectionContext = 
getBroker().getAdminConnectionContext();
-        if (adminConnectionContext == null) {
-            adminConnectionContext = createAdminConnectionContext();
-            getBroker().setAdminConnectionContext(adminConnectionContext);
-        }
-        return adminConnectionContext;
-    }
-
-    /**
-     * Factory method to create the new administration connection context
-     * object. Note this method is here rather than inside a default broker
-     * implementation to ensure that the broker reference inside it is the 
outer
-     * most interceptor
-     */
-    protected ConnectionContext createAdminConnectionContext() throws 
Exception {
-        ConnectionContext context = new ConnectionContext();
-        context.setBroker(getBroker());
-        context.setSecurityContext(SecurityContext.BROKER_SECURITY_CONTEXT);
-        return context;
+        return BrokerSupport.getConnectionContext(getBroker());
     }
 
     protected void waitForSlave() {

Modified: 
activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/BrokerView.java
URL: 
http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/BrokerView.java?rev=1026254&r1=1026253&r2=1026254&view=diff
==============================================================================
--- 
activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/BrokerView.java
 (original)
+++ 
activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/BrokerView.java
 Fri Oct 22 08:55:08 2010
@@ -26,7 +26,6 @@ import java.util.concurrent.atomic.Atomi
 import javax.management.ObjectName;
 
 import org.apache.activemq.ActiveMQConnectionMetaData;
-import org.apache.activemq.broker.Broker;
 import org.apache.activemq.broker.BrokerService;
 import org.apache.activemq.broker.ConnectionContext;
 import org.apache.activemq.broker.TransportConnector;
@@ -37,7 +36,7 @@ import org.apache.activemq.command.Consu
 import org.apache.activemq.command.ConsumerInfo;
 import org.apache.activemq.command.RemoveSubscriptionInfo;
 import org.apache.activemq.network.NetworkConnector;
-import org.apache.activemq.security.SecurityContext;
+import org.apache.activemq.util.BrokerSupport;
 
 /**
  * @version $Revision$
@@ -243,20 +242,20 @@ public class BrokerView implements Broke
     }
 
     public void addTopic(String name) throws Exception {
-        
broker.getContextBroker().addDestination(getConnectionContext(broker.getContextBroker()),
 new ActiveMQTopic(name),true);
+        
broker.getContextBroker().addDestination(BrokerSupport.getConnectionContext(broker.getContextBroker()),
 new ActiveMQTopic(name),true);
     }
 
     public void addQueue(String name) throws Exception {
-        
broker.getContextBroker().addDestination(getConnectionContext(broker.getContextBroker()),
 new ActiveMQQueue(name),true);
+        
broker.getContextBroker().addDestination(BrokerSupport.getConnectionContext(broker.getContextBroker()),
 new ActiveMQQueue(name),true);
     }
 
     public void removeTopic(String name) throws Exception {
-        
broker.getContextBroker().removeDestination(getConnectionContext(broker.getContextBroker()),
 new ActiveMQTopic(name),
+        
broker.getContextBroker().removeDestination(BrokerSupport.getConnectionContext(broker.getContextBroker()),
 new ActiveMQTopic(name),
                                  1000);
     }
 
     public void removeQueue(String name) throws Exception {
-        
broker.getContextBroker().removeDestination(getConnectionContext(broker.getContextBroker()),
 new ActiveMQQueue(name),
+        
broker.getContextBroker().removeDestination(BrokerSupport.getConnectionContext(broker.getContextBroker()),
 new ActiveMQQueue(name),
                                  1000);
     }
 
@@ -292,32 +291,6 @@ public class BrokerView implements Broke
         broker.removeSubscription(context, info);
     }
 
-    /**
-     * Returns the broker's administration connection context used for
-     * configuring the broker at startup
-     */
-    public static ConnectionContext getConnectionContext(Broker broker) {
-        ConnectionContext adminConnectionContext = 
broker.getAdminConnectionContext();
-        if (adminConnectionContext == null) {
-            adminConnectionContext = createAdminConnectionContext(broker);
-            broker.setAdminConnectionContext(adminConnectionContext);
-        }
-        return adminConnectionContext;
-    }
-
-    /**
-     * Factory method to create the new administration connection context
-     * object. Note this method is here rather than inside a default broker
-     * implementation to ensure that the broker reference inside it is the 
outer
-     * most interceptor
-     */
-    protected static ConnectionContext createAdminConnectionContext(Broker 
broker) {
-        ConnectionContext context = new ConnectionContext();
-        context.setBroker(broker);
-        context.setSecurityContext(SecurityContext.BROKER_SECURITY_CONTEXT);
-        return context;
-    }
-    
     //  doc comment inherited from BrokerViewMBean
     public void reloadLog4jProperties() throws Throwable {
 

Modified: 
activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/QueueView.java
URL: 
http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/QueueView.java?rev=1026254&r1=1026253&r2=1026254&view=diff
==============================================================================
--- 
activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/QueueView.java
 (original)
+++ 
activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/QueueView.java
 Fri Oct 22 08:55:08 2010
@@ -24,6 +24,7 @@ import org.apache.activemq.broker.Connec
 import org.apache.activemq.broker.region.Queue;
 import org.apache.activemq.command.ActiveMQDestination;
 import org.apache.activemq.command.Message;
+import org.apache.activemq.util.BrokerSupport;
 
 /**
  * Provides a JMX Management view of a Queue.
@@ -58,37 +59,37 @@ public class QueueView extends Destinati
     }
 
     public boolean copyMessageTo(String messageId, String destinationName) 
throws Exception {
-        ConnectionContext context = 
BrokerView.getConnectionContext(broker.getContextBroker());
+        ConnectionContext context = 
BrokerSupport.getConnectionContext(broker.getContextBroker());
         ActiveMQDestination toDestination = 
ActiveMQDestination.createDestination(destinationName, 
ActiveMQDestination.QUEUE_TYPE);
         return ((Queue)destination).copyMessageTo(context, messageId, 
toDestination);
     }
 
     public int copyMatchingMessagesTo(String selector, String destinationName) 
throws Exception {
-        ConnectionContext context = 
BrokerView.getConnectionContext(broker.getContextBroker());
+        ConnectionContext context = 
BrokerSupport.getConnectionContext(broker.getContextBroker());
         ActiveMQDestination toDestination = 
ActiveMQDestination.createDestination(destinationName, 
ActiveMQDestination.QUEUE_TYPE);
         return ((Queue)destination).copyMatchingMessagesTo(context, selector, 
toDestination);
     }
 
     public int copyMatchingMessagesTo(String selector, String destinationName, 
int maximumMessages) throws Exception {
-        ConnectionContext context = 
BrokerView.getConnectionContext(broker.getContextBroker());
+        ConnectionContext context = 
BrokerSupport.getConnectionContext(broker.getContextBroker());
         ActiveMQDestination toDestination = 
ActiveMQDestination.createDestination(destinationName, 
ActiveMQDestination.QUEUE_TYPE);
         return ((Queue)destination).copyMatchingMessagesTo(context, selector, 
toDestination, maximumMessages);
     }
 
     public boolean moveMessageTo(String messageId, String destinationName) 
throws Exception {
-        ConnectionContext context = 
BrokerView.getConnectionContext(broker.getContextBroker());
+        ConnectionContext context = 
BrokerSupport.getConnectionContext(broker.getContextBroker());
         ActiveMQDestination toDestination = 
ActiveMQDestination.createDestination(destinationName, 
ActiveMQDestination.QUEUE_TYPE);
         return ((Queue)destination).moveMessageTo(context, messageId, 
toDestination);
     }
 
     public int moveMatchingMessagesTo(String selector, String destinationName) 
throws Exception {
-        ConnectionContext context = 
BrokerView.getConnectionContext(broker.getContextBroker());
+        ConnectionContext context = 
BrokerSupport.getConnectionContext(broker.getContextBroker());
         ActiveMQDestination toDestination = 
ActiveMQDestination.createDestination(destinationName, 
ActiveMQDestination.QUEUE_TYPE);
         return ((Queue)destination).moveMatchingMessagesTo(context, selector, 
toDestination);
     }
 
     public int moveMatchingMessagesTo(String selector, String destinationName, 
int maximumMessages) throws Exception {
-        ConnectionContext context = 
BrokerView.getConnectionContext(broker.getContextBroker());
+        ConnectionContext context = 
BrokerSupport.getConnectionContext(broker.getContextBroker());
         ActiveMQDestination toDestination = 
ActiveMQDestination.createDestination(destinationName, 
ActiveMQDestination.QUEUE_TYPE);
         return ((Queue)destination).moveMatchingMessagesTo(context, selector, 
toDestination, maximumMessages);
     }
@@ -104,7 +105,7 @@ public class QueueView extends Destinati
             rc.getMessage().setRedeliveryCounter(0);
             ActiveMQDestination originalDestination = 
rc.getOriginalDestination();
             if (originalDestination != null) {
-                ConnectionContext context = 
BrokerView.getConnectionContext(broker.getContextBroker());
+                ConnectionContext context = 
BrokerSupport.getConnectionContext(broker.getContextBroker());
                 return queue.moveMessageTo(context, rc, originalDestination);
             }
             else {

Modified: 
activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/BrokerSupport.java
URL: 
http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/BrokerSupport.java?rev=1026254&r1=1026253&r2=1026254&view=diff
==============================================================================
--- 
activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/BrokerSupport.java
 (original)
+++ 
activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/BrokerSupport.java
 Fri Oct 22 08:55:08 2010
@@ -16,15 +16,17 @@
  */
 package org.apache.activemq.util;
 
+import org.apache.activemq.broker.Broker;
 import org.apache.activemq.broker.ConnectionContext;
 import org.apache.activemq.broker.ProducerBrokerExchange;
 import org.apache.activemq.command.ActiveMQDestination;
 import org.apache.activemq.command.Message;
 import org.apache.activemq.command.ProducerInfo;
+import org.apache.activemq.security.SecurityContext;
 import org.apache.activemq.state.ProducerState;
 
 /**
- * Utility class for re-sending messages
+ * Utility class for broker operations
  *
  */
 public final class BrokerSupport {
@@ -68,4 +70,29 @@ public final class BrokerSupport {
         }
     }
 
+    /**
+     * Returns the broker's administration connection context used for
+     * configuring the broker at startup
+     */
+    public static ConnectionContext getConnectionContext(Broker broker) {
+        ConnectionContext adminConnectionContext = 
broker.getAdminConnectionContext();
+        if (adminConnectionContext == null) {
+            adminConnectionContext = createAdminConnectionContext(broker);
+            broker.setAdminConnectionContext(adminConnectionContext);
+        }
+        return adminConnectionContext;
+    }
+
+    /**
+     * Factory method to create the new administration connection context
+     * object. Note this method is here rather than inside a default broker
+     * implementation to ensure that the broker reference inside it is the 
outer
+     * most interceptor
+     */
+    protected static ConnectionContext createAdminConnectionContext(Broker 
broker) {
+        ConnectionContext context = new ConnectionContext();
+        context.setBroker(broker);
+        context.setSecurityContext(SecurityContext.BROKER_SECURITY_CONTEXT);
+        return context;
+    }
 }


Reply via email to