diff --git a/activemq-core/src/main/java/org/apache/activemq/broker/Broker.java b/activemq-core/src/main/java/org/apache/activemq/broker/Broker.java index 85dd3c5f48..7bb1d459e5 100755 --- a/activemq-core/src/main/java/org/apache/activemq/broker/Broker.java +++ b/activemq-core/src/main/java/org/apache/activemq/broker/Broker.java @@ -238,4 +238,14 @@ public interface Broker extends Region, Service { * @return true if fault tolerant */ public boolean isFaultTolerantConfiguration(); + + /** + * @return the connection context used to make administration operations on startup or via JMX MBeans + */ + public abstract ConnectionContext getAdminConnectionContext(); + + /** + * Sets the default administration connection context used when configuring the broker on startup or via JMX + */ + public abstract void setAdminConnectionContext(ConnectionContext adminConnectionContext); } diff --git a/activemq-core/src/main/java/org/apache/activemq/broker/BrokerFilter.java b/activemq-core/src/main/java/org/apache/activemq/broker/BrokerFilter.java index 37ee137996..ff4ac91494 100755 --- a/activemq-core/src/main/java/org/apache/activemq/broker/BrokerFilter.java +++ b/activemq-core/src/main/java/org/apache/activemq/broker/BrokerFilter.java @@ -213,9 +213,16 @@ public class BrokerFilter implements Broker { } - public boolean isFaultTolerantConfiguration(){ return next.isFaultTolerantConfiguration(); } + public ConnectionContext getAdminConnectionContext() { + return next.getAdminConnectionContext(); + } + + public void setAdminConnectionContext(ConnectionContext adminConnectionContext) { + next.setAdminConnectionContext(adminConnectionContext); + } + } diff --git a/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java b/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java index b8c6963790..f548cde94f 100644 --- a/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java +++ b/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java @@ -1202,16 +1202,41 @@ public class BrokerService implements Service, Serializable { */ protected void startDestinations() throws Exception { if (destinations != null) { - ConnectionContext context = new ConnectionContext(); - context.setBroker(getBroker()); - + ConnectionContext adminConnectionContext = getAdminConnectionContext(); + for (int i = 0; i < destinations.length; i++) { ActiveMQDestination destination = destinations[i]; - getBroker().addDestination(context, destination); + getBroker().addDestination(adminConnectionContext, destination); } } } + + /** + * Returns the broker's administration connection context used for 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()); + return context; + } + + /** * Start all transport and network connections, proxies and bridges * @throws Exception diff --git a/activemq-core/src/main/java/org/apache/activemq/broker/EmptyBroker.java b/activemq-core/src/main/java/org/apache/activemq/broker/EmptyBroker.java index 2068cbf856..3883201c4c 100644 --- a/activemq-core/src/main/java/org/apache/activemq/broker/EmptyBroker.java +++ b/activemq-core/src/main/java/org/apache/activemq/broker/EmptyBroker.java @@ -42,18 +42,18 @@ import java.util.Set; * * @version $Revision$ */ -public class EmptyBroker implements Broker{ +public class EmptyBroker implements Broker { - public BrokerId getBrokerId(){ + public BrokerId getBrokerId() { return null; } - public String getBrokerName(){ + public String getBrokerName() { return null; } - - public Broker getAdaptor(Class type){ - if (type.isInstance(this)){ + + public Broker getAdaptor(Class type) { + if (type.isInstance(this)) { return this; } return null; @@ -67,152 +67,159 @@ public class EmptyBroker implements Broker{ return Collections.EMPTY_SET; } - public void addConnection(ConnectionContext context,ConnectionInfo info) throws Exception{ + public void addConnection(ConnectionContext context, ConnectionInfo info) throws Exception { } - public void removeConnection(ConnectionContext context,ConnectionInfo info,Throwable error) throws Exception{ + public void removeConnection(ConnectionContext context, ConnectionInfo info, Throwable error) throws Exception { } - public void addSession(ConnectionContext context,SessionInfo info) throws Exception{ + public void addSession(ConnectionContext context, SessionInfo info) throws Exception { } - public void removeSession(ConnectionContext context,SessionInfo info) throws Exception{ + public void removeSession(ConnectionContext context, SessionInfo info) throws Exception { } - public void addProducer(ConnectionContext context,ProducerInfo info) throws Exception{ + public void addProducer(ConnectionContext context, ProducerInfo info) throws Exception { } - public void removeProducer(ConnectionContext context,ProducerInfo info) throws Exception{ + public void removeProducer(ConnectionContext context, ProducerInfo info) throws Exception { } - public Connection[] getClients() throws Exception{ + public Connection[] getClients() throws Exception { return null; } - public ActiveMQDestination[] getDestinations() throws Exception{ + public ActiveMQDestination[] getDestinations() throws Exception { return null; } - public TransactionId[] getPreparedTransactions(ConnectionContext context) throws Exception{ + public TransactionId[] getPreparedTransactions(ConnectionContext context) throws Exception { return null; } - public void beginTransaction(ConnectionContext context,TransactionId xid) throws Exception{ + public void beginTransaction(ConnectionContext context, TransactionId xid) throws Exception { } - public int prepareTransaction(ConnectionContext context,TransactionId xid) throws Exception{ + public int prepareTransaction(ConnectionContext context, TransactionId xid) throws Exception { return 0; } - public void rollbackTransaction(ConnectionContext context,TransactionId xid) throws Exception{ + public void rollbackTransaction(ConnectionContext context, TransactionId xid) throws Exception { } - public void commitTransaction(ConnectionContext context,TransactionId xid,boolean onePhase) throws Exception{ + public void commitTransaction(ConnectionContext context, TransactionId xid, boolean onePhase) throws Exception { } - public void forgetTransaction(ConnectionContext context,TransactionId transactionId) throws Exception{ + public void forgetTransaction(ConnectionContext context, TransactionId transactionId) throws Exception { } - public Destination addDestination(ConnectionContext context,ActiveMQDestination destination) throws Exception{ + public Destination addDestination(ConnectionContext context, ActiveMQDestination destination) throws Exception { return null; } - public void removeDestination(ConnectionContext context,ActiveMQDestination destination,long timeout) throws Exception{ + public void removeDestination(ConnectionContext context, ActiveMQDestination destination, long timeout) throws Exception { } - public Subscription addConsumer(ConnectionContext context,ConsumerInfo info) throws Exception{ + public Subscription addConsumer(ConnectionContext context, ConsumerInfo info) throws Exception { return null; } - public void removeConsumer(ConnectionContext context,ConsumerInfo info) throws Exception{ + public void removeConsumer(ConnectionContext context, ConsumerInfo info) throws Exception { } - public void removeSubscription(ConnectionContext context,RemoveSubscriptionInfo info) throws Exception{ + public void removeSubscription(ConnectionContext context, RemoveSubscriptionInfo info) throws Exception { } - public void send(ConnectionContext context,Message message) throws Exception{ + public void send(ConnectionContext context, Message message) throws Exception { } - public void acknowledge(ConnectionContext context,MessageAck ack) throws Exception{ + public void acknowledge(ConnectionContext context, MessageAck ack) throws Exception { } - public void gc(){ + public void gc() { } - public void start() throws Exception{ + public void start() throws Exception { } - public void stop() throws Exception{ + public void stop() throws Exception { } - public void addBroker(Connection connection,BrokerInfo info){ - - } - - public void removeBroker(Connection connection,BrokerInfo info){ - + public void addBroker(Connection connection, BrokerInfo info) { + } - public BrokerInfo[] getPeerBrokerInfos(){ + public void removeBroker(Connection connection, BrokerInfo info) { + + } + + public BrokerInfo[] getPeerBrokerInfos() { return null; } - + /** * Notifiy the Broker that a dispatch has happened + * * @param messageDispatch */ - public void processDispatch(MessageDispatch messageDispatch){ - + public void processDispatch(MessageDispatch messageDispatch) { + } - - public void processDispatchNotification(MessageDispatchNotification messageDispatchNotification) throws Exception{ - + + public void processDispatchNotification(MessageDispatchNotification messageDispatchNotification) throws Exception { + } - - public boolean isSlaveBroker(){ + + public boolean isSlaveBroker() { return false; } - - public boolean isStopped(){ + + public boolean isStopped() { return false; } - - public Set getDurableDestinations(){ + + public Set getDurableDestinations() { return null; } - public void addDestinationInfo(ConnectionContext context,DestinationInfo info) throws Exception{ + public void addDestinationInfo(ConnectionContext context, DestinationInfo info) throws Exception { } - public void removeDestinationInfo(ConnectionContext context,DestinationInfo info) throws Exception{ + public void removeDestinationInfo(ConnectionContext context, DestinationInfo info) throws Exception { } - public boolean isFaultTolerantConfiguration(){ + public boolean isFaultTolerantConfiguration() { return false; } - - + + public ConnectionContext getAdminConnectionContext() { + return null; + } + + public void setAdminConnectionContext(ConnectionContext adminConnectionContext) { + } + } diff --git a/activemq-core/src/main/java/org/apache/activemq/broker/ErrorBroker.java b/activemq-core/src/main/java/org/apache/activemq/broker/ErrorBroker.java index dd688fe34d..5a1765cce3 100644 --- a/activemq-core/src/main/java/org/apache/activemq/broker/ErrorBroker.java +++ b/activemq-core/src/main/java/org/apache/activemq/broker/ErrorBroker.java @@ -38,7 +38,8 @@ import org.apache.activemq.command.SessionInfo; import org.apache.activemq.command.TransactionId; /** - * Implementation of the broker where all it's methods throw an BrokerStoppedException. + * Implementation of the broker where all it's methods throw an + * BrokerStoppedException. * * @version $Revision$ */ @@ -47,9 +48,9 @@ public class ErrorBroker implements Broker { private final String message; public ErrorBroker(String message) { - this.message=message; + this.message = message; } - + public Map getDestinationMap() { return Collections.EMPTY_MAP; } @@ -58,13 +59,13 @@ public class ErrorBroker implements Broker { return Collections.EMPTY_SET; } - public Broker getAdaptor(Class type){ - if (type.isInstance(this)){ + public Broker getAdaptor(Class type) { + if (type.isInstance(this)) { return this; } return null; } - + public BrokerId getBrokerId() { throw new BrokerStoppedException(this.message); } @@ -72,7 +73,7 @@ public class ErrorBroker implements Broker { public String getBrokerName() { throw new BrokerStoppedException(this.message); } - + public void addConnection(ConnectionContext context, ConnectionInfo info) throws Exception { throw new BrokerStoppedException(this.message); } @@ -169,52 +170,57 @@ public class ErrorBroker implements Broker { throw new BrokerStoppedException(this.message); } - public void addBroker(Connection connection,BrokerInfo info){ + public void addBroker(Connection connection, BrokerInfo info) { throw new BrokerStoppedException(this.message); - + } - - public void removeBroker(Connection connection,BrokerInfo info){ + + public void removeBroker(Connection connection, BrokerInfo info) { throw new BrokerStoppedException(this.message); } - public BrokerInfo[] getPeerBrokerInfos(){ + public BrokerInfo[] getPeerBrokerInfos() { throw new BrokerStoppedException(this.message); } - - public void processDispatch(MessageDispatch messageDispatch){ + + public void processDispatch(MessageDispatch messageDispatch) { throw new BrokerStoppedException(this.message); } - - public void processDispatchNotification(MessageDispatchNotification messageDispatchNotification) throws Exception{ + + public void processDispatchNotification(MessageDispatchNotification messageDispatchNotification) throws Exception { throw new BrokerStoppedException(this.message); } - - public boolean isSlaveBroker(){ + + public boolean isSlaveBroker() { throw new BrokerStoppedException(this.message); } - - public boolean isStopped(){ + + public boolean isStopped() { return true; } - - public Set getDurableDestinations(){ + + public Set getDurableDestinations() { throw new BrokerStoppedException(this.message); } - public void addDestinationInfo(ConnectionContext context,DestinationInfo info) throws Exception{ + public void addDestinationInfo(ConnectionContext context, DestinationInfo info) throws Exception { throw new BrokerStoppedException(this.message); - } - public void removeDestinationInfo(ConnectionContext context,DestinationInfo info) throws Exception{ + public void removeDestinationInfo(ConnectionContext context, DestinationInfo info) throws Exception { throw new BrokerStoppedException(this.message); - } - public boolean isFaultTolerantConfiguration(){ + public boolean isFaultTolerantConfiguration() { throw new BrokerStoppedException(this.message); } - - + + public ConnectionContext getAdminConnectionContext() { + throw new BrokerStoppedException(this.message); + } + + public void setAdminConnectionContext(ConnectionContext adminConnectionContext) { + throw new BrokerStoppedException(this.message); + } + } diff --git a/activemq-core/src/main/java/org/apache/activemq/broker/MutableBrokerFilter.java b/activemq-core/src/main/java/org/apache/activemq/broker/MutableBrokerFilter.java index f219f2aa85..4d6f67e454 100644 --- a/activemq-core/src/main/java/org/apache/activemq/broker/MutableBrokerFilter.java +++ b/activemq-core/src/main/java/org/apache/activemq/broker/MutableBrokerFilter.java @@ -229,4 +229,12 @@ public class MutableBrokerFilter implements Broker { return getNext().isFaultTolerantConfiguration(); } + public ConnectionContext getAdminConnectionContext() { + return getNext().getAdminConnectionContext(); + } + + public void setAdminConnectionContext(ConnectionContext adminConnectionContext) { + getNext().setAdminConnectionContext(adminConnectionContext); + } + } diff --git a/activemq-core/src/main/java/org/apache/activemq/broker/jmx/BrokerView.java b/activemq-core/src/main/java/org/apache/activemq/broker/jmx/BrokerView.java index 0e903f96bc..732cb115ec 100755 --- a/activemq-core/src/main/java/org/apache/activemq/broker/jmx/BrokerView.java +++ b/activemq-core/src/main/java/org/apache/activemq/broker/jmx/BrokerView.java @@ -180,9 +180,7 @@ public class BrokerView implements BrokerViewMBean { } static public ConnectionContext getConnectionContext(Broker broker) { - ConnectionContext context = new ConnectionContext(); - context.setBroker(broker); - return context; + return broker.getAdminConnectionContext(); } } diff --git a/activemq-core/src/main/java/org/apache/activemq/broker/region/RegionBroker.java b/activemq-core/src/main/java/org/apache/activemq/broker/region/RegionBroker.java index de729841e4..e5efac6ca9 100755 --- a/activemq-core/src/main/java/org/apache/activemq/broker/region/RegionBroker.java +++ b/activemq-core/src/main/java/org/apache/activemq/broker/region/RegionBroker.java @@ -85,6 +85,7 @@ public class RegionBroker implements Broker { private Map clientIdSet = new HashMap(); // we will synchronize access protected PersistenceAdapter adaptor; private final DestinationInterceptor destinationInterceptor; + private ConnectionContext adminConnectionContext; public RegionBroker(BrokerService brokerService,TaskRunnerFactory taskRunnerFactory, UsageManager memoryManager, PersistenceAdapter adapter, DestinationInterceptor destinationInterceptor) throws IOException { this.brokerService = brokerService; @@ -533,5 +534,11 @@ public class RegionBroker implements Broker { return destinationInterceptor; } - + public ConnectionContext getAdminConnectionContext() { + return adminConnectionContext; + } + + public void setAdminConnectionContext(ConnectionContext adminConnectionContext) { + this.adminConnectionContext = adminConnectionContext; + } }