https://issues.apache.org/activemq/browse/AMQ-2970 - refactor to avoid duplicate getConnectionContext() method

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1026254 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Bosanac Dejan 2010-10-22 08:55:08 +00:00
parent 9e885efca2
commit df7cb7727b
4 changed files with 43 additions and 67 deletions

View File

@ -79,7 +79,6 @@ import org.apache.activemq.network.NetworkConnector;
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.TransportFactory;
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 Service {
* 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() {

View File

@ -26,7 +26,6 @@ import java.util.concurrent.atomic.AtomicInteger;
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.ConsumerId;
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 BrokerViewMBean {
}
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 BrokerViewMBean {
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 {

View File

@ -24,6 +24,7 @@ import org.apache.activemq.broker.ConnectionContext;
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 DestinationView implements QueueViewMBean {
}
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 DestinationView implements QueueViewMBean {
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 {

View File

@ -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;
}
}