activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r396892 - /incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java
Date Tue, 25 Apr 2006 14:06:57 GMT
Author: jstrachan
Date: Tue Apr 25 07:06:52 2006
New Revision: 396892

URL: http://svn.apache.org/viewcvs?rev=396892&view=rev
Log:
added a helper method to make it easier to work with the admin view together with fixed some
NPEs I was getting when redeploying ActiveMQ when using mvn jetty6:run

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

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java?rev=396892&r1=396891&r2=396892&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java
Tue Apr 25 07:06:52 2006
@@ -35,7 +35,6 @@
 import org.apache.activemq.advisory.AdvisoryBroker;
 import org.apache.activemq.broker.ft.MasterConnector;
 import org.apache.activemq.broker.jmx.BrokerView;
-import org.apache.activemq.broker.jmx.BrokerViewMBean;
 import org.apache.activemq.broker.jmx.ConnectorView;
 import org.apache.activemq.broker.jmx.ConnectorViewMBean;
 import org.apache.activemq.broker.jmx.FTConnectorView;
@@ -96,6 +95,7 @@
     private String brokerName = "localhost";
     private File dataDirectory;
     private Broker broker;
+    private BrokerView adminView;
     private ManagementContext managementContext;
     private ObjectName brokerObjectName;
     private TaskRunnerFactory taskRunnerFactory;
@@ -121,7 +121,6 @@
     private AtomicBoolean started = new AtomicBoolean(false);
     private BrokerPlugin[] plugins;
     private boolean keepDurableSubsActive=true;
-
     private BrokerId brokerId;
 
     /**
@@ -426,13 +425,15 @@
 
         if (isUseJmx()) {
             MBeanServer mbeanServer = getManagementContext().getMBeanServer();
-            for (Iterator iter = registeredMBeanNames.iterator(); iter.hasNext();) {
-                ObjectName name = (ObjectName) iter.next();
-                try {
-                    mbeanServer.unregisterMBean(name);
-                }
-                catch (Exception e) {
-                    stopper.onException(mbeanServer, e);
+            if (mbeanServer != null) {
+                for (Iterator iter = registeredMBeanNames.iterator(); iter.hasNext();) {
+                    ObjectName name = (ObjectName) iter.next();
+                    try {
+                        mbeanServer.unregisterMBean(name);
+                    }
+                    catch (Exception e) {
+                        stopper.onException(mbeanServer, e);
+                    }
                 }
             }
             stopper.stop(getManagementContext());
@@ -445,6 +446,10 @@
 
     // Properties
     // -------------------------------------------------------------------------
+    
+    /**
+     * Returns the message broker
+     */
     public Broker getBroker() throws Exception {
         if (broker == null) {
             log.info("ActiveMQ " + ActiveMQConnectionMetaData.PROVIDER_VERSION + " JMS Message
Broker ("
@@ -455,6 +460,24 @@
         return broker;
     }
 
+    
+    /**
+     * Returns the administration view of the broker; used to create and destroy resources
such as queues and topics.
+     * 
+     * Note this method returns null if JMX is disabled.
+     */
+    public BrokerView getAdminView() throws Exception {
+        if (adminView == null) {
+            // force lazy creation
+            getBroker();
+        }
+        return adminView;
+    }
+
+    public void setAdminView(BrokerView adminView) {
+        this.adminView = adminView;
+    }
+
     public String getBrokerName() {
         return brokerName;
     }
@@ -774,84 +797,82 @@
 
     protected void registerConnectorMBean(TransportConnector connector, ObjectName objectName)
throws IOException, URISyntaxException {
         MBeanServer mbeanServer = getManagementContext().getMBeanServer();
-        ConnectorViewMBean view = new ConnectorView(connector);
-        try {
-            mbeanServer.registerMBean(view, objectName);
-            registeredMBeanNames.add(objectName);
-        }
-        catch (Throwable e) {
-            throw IOExceptionSupport.create("Broker could not be registered in JMX: " + e.getMessage(),
e);
+        if (mbeanServer != null) {
+            ConnectorViewMBean view = new ConnectorView(connector);
+            try {
+                mbeanServer.registerMBean(view, objectName);
+                registeredMBeanNames.add(objectName);
+            }
+            catch (Throwable e) {
+                throw IOExceptionSupport.create("Broker could not be registered in JMX: "
+ e.getMessage(), e);
+            }
         }
     }
 
     protected void registerNetworkConnectorMBean(NetworkConnector connector) throws IOException
{
         MBeanServer mbeanServer = getManagementContext().getMBeanServer();
-        NetworkConnectorViewMBean view = new NetworkConnectorView(connector);
-        try {
-        	ObjectName objectName = new ObjectName(
-            		managementContext.getJmxDomainName()+":"+
-            		"BrokerName="+JMXSupport.encodeObjectNamePart(getBrokerName())+","+
-            		"Type=NetworkConnector,"+
-                    "NetworkConnectorName="+JMXSupport.encodeObjectNamePart(connector.getName())
-            		);
-            mbeanServer.registerMBean(view, objectName);
-            registeredMBeanNames.add(objectName);
-        }
-        catch (Throwable e) {
-            throw IOExceptionSupport.create("Broker could not be registered in JMX: " + e.getMessage(),
e);
+        if (mbeanServer != null) {
+            NetworkConnectorViewMBean view = new NetworkConnectorView(connector);
+            try {
+                ObjectName objectName = new ObjectName(managementContext.getJmxDomainName()
+ ":" + "BrokerName="
+                        + JMXSupport.encodeObjectNamePart(getBrokerName()) + "," + "Type=NetworkConnector,"
+ "NetworkConnectorName="
+                        + JMXSupport.encodeObjectNamePart(connector.getName()));
+                mbeanServer.registerMBean(view, objectName);
+                registeredMBeanNames.add(objectName);
+            }
+            catch (Throwable e) {
+                throw IOExceptionSupport.create("Broker could not be registered in JMX: "
+ e.getMessage(), e);
+            }
         }
     }
 
     protected void registerProxyConnectorMBean(ProxyConnector connector) throws IOException
{
         MBeanServer mbeanServer = getManagementContext().getMBeanServer();
-        ProxyConnectorView view = new ProxyConnectorView(connector);
-        try {
-        	ObjectName objectName = new ObjectName(
-            		managementContext.getJmxDomainName()+":"+
-            		"BrokerName="+JMXSupport.encodeObjectNamePart(getBrokerName())+","+
-            		"Type=ProxyConnector,"+
-                    "ProxyConnectorName="+JMXSupport.encodeObjectNamePart(connector.getName())
-            		);
-            mbeanServer.registerMBean(view, objectName);
-            registeredMBeanNames.add(objectName);
-        }
-        catch (Throwable e) {
-            throw IOExceptionSupport.create("Broker could not be registered in JMX: " + e.getMessage(),
e);
+        if (mbeanServer != null) {
+            ProxyConnectorView view = new ProxyConnectorView(connector);
+            try {
+                ObjectName objectName = new ObjectName(managementContext.getJmxDomainName()
+ ":" + "BrokerName="
+                        + JMXSupport.encodeObjectNamePart(getBrokerName()) + "," + "Type=ProxyConnector,"
+ "ProxyConnectorName="
+                        + JMXSupport.encodeObjectNamePart(connector.getName()));
+                mbeanServer.registerMBean(view, objectName);
+                registeredMBeanNames.add(objectName);
+            }
+            catch (Throwable e) {
+                throw IOExceptionSupport.create("Broker could not be registered in JMX: "
+ e.getMessage(), e);
+            }
         }
     }
-    
+
     protected void registerFTConnectorMBean(MasterConnector connector) throws IOException
{
         MBeanServer mbeanServer = getManagementContext().getMBeanServer();
-        FTConnectorView view = new FTConnectorView(connector);
-        try {
-        	ObjectName objectName = new ObjectName(
-            		managementContext.getJmxDomainName()+":"+
-            		"BrokerName="+JMXSupport.encodeObjectNamePart(getBrokerName())+","+
-            		"Type=MasterConnector"
-            		);
-            mbeanServer.registerMBean(view, objectName);
-            registeredMBeanNames.add(objectName);
-        }
-        catch (Throwable e) {
-            throw IOExceptionSupport.create("Broker could not be registered in JMX: " + e.getMessage(),
e);
+        if (mbeanServer != null) {
+            FTConnectorView view = new FTConnectorView(connector);
+            try {
+                ObjectName objectName = new ObjectName(managementContext.getJmxDomainName()
+ ":" + "BrokerName="
+                        + JMXSupport.encodeObjectNamePart(getBrokerName()) + "," + "Type=MasterConnector");
+                mbeanServer.registerMBean(view, objectName);
+                registeredMBeanNames.add(objectName);
+            }
+            catch (Throwable e) {
+                throw IOExceptionSupport.create("Broker could not be registered in JMX: "
+ e.getMessage(), e);
+            }
         }
     }
-    
+
     protected void registerJmsConnectorMBean(JmsConnector connector) throws IOException {
         MBeanServer mbeanServer = getManagementContext().getMBeanServer();
-        JmsConnectorView view = new JmsConnectorView(connector);
-        try {
-        	ObjectName objectName = new ObjectName(
-            		managementContext.getJmxDomainName()+":"+
-            		"BrokerName="+JMXSupport.encodeObjectNamePart(getBrokerName())+","+
-            		"Type=JmsConnector,"+
-                    "JmsConnectorName="+JMXSupport.encodeObjectNamePart(connector.getName())
-            		);
-            mbeanServer.registerMBean(view, objectName);
-            registeredMBeanNames.add(objectName);
-        }
-        catch (Throwable e) {
-            throw IOExceptionSupport.create("Broker could not be registered in JMX: " + e.getMessage(),
e);
+        if (mbeanServer != null) {
+            JmsConnectorView view = new JmsConnectorView(connector);
+            try {
+                ObjectName objectName = new ObjectName(managementContext.getJmxDomainName()
+ ":" + "BrokerName="
+                        + JMXSupport.encodeObjectNamePart(getBrokerName()) + "," + "Type=JmsConnector,"
+ "JmsConnectorName="
+                        + JMXSupport.encodeObjectNamePart(connector.getName()));
+                mbeanServer.registerMBean(view, objectName);
+                registeredMBeanNames.add(objectName);
+            }
+            catch (Throwable e) {
+                throw IOExceptionSupport.create("Broker could not be registered in JMX: "
+ e.getMessage(), e);
+            }
         }
     }
     
@@ -882,11 +903,13 @@
         if (isUseJmx()) {
             ManagedRegionBroker managedBroker = (ManagedRegionBroker) regionBroker;
             managedBroker.setContextBroker(broker);
-            BrokerViewMBean view = new BrokerView(this, managedBroker);
+            adminView = new BrokerView(this, managedBroker);
             MBeanServer mbeanServer = getManagementContext().getMBeanServer();
-            ObjectName objectName = getBrokerObjectName();
-            mbeanServer.registerMBean(view, objectName);
-            registeredMBeanNames.add(objectName);
+            if (mbeanServer != null) {
+                ObjectName objectName = getBrokerObjectName();
+                mbeanServer.registerMBean(adminView, objectName);
+                registeredMBeanNames.add(objectName);
+            }
         }
         
 
@@ -908,8 +931,8 @@
 		RegionBroker regionBroker = null;
         if (isUseJmx()) {
             MBeanServer mbeanServer = getManagementContext().getMBeanServer();
-            regionBroker = new ManagedRegionBroker(this,mbeanServer, getBrokerObjectName(),
-                    getTaskRunnerFactory(), getMemoryManager(), getPersistenceAdapter());
+            regionBroker = new ManagedRegionBroker(this, mbeanServer, getBrokerObjectName(),
getTaskRunnerFactory(), getMemoryManager(),
+                    getPersistenceAdapter());
         }
         else {
 			regionBroker = new RegionBroker(this,getTaskRunnerFactory(), getMemoryManager(), getPersistenceAdapter());
@@ -1068,7 +1091,7 @@
                 JmsConnector connector = (JmsConnector) iter.next();
                 connector.start();
             }
-            }
+        }
     }
 
     protected void startTransportConnector(TransportConnector connector) throws Exception
{



Mime
View raw message