activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r434068 - /incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java
Date Wed, 23 Aug 2006 16:12:48 GMT
Author: jstrachan
Date: Wed Aug 23 09:12:47 2006
New Revision: 434068

URL: http://svn.apache.org/viewvc?rev=434068&view=rev
Log:
add the ability to remove network connectors dynamically

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/viewvc/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java?rev=434068&r1=434067&r2=434068&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
Wed Aug 23 09:12:47 2006
@@ -63,7 +63,11 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
+import javax.management.InstanceNotFoundException;
+import javax.management.JMException;
+import javax.management.MBeanRegistrationException;
 import javax.management.MBeanServer;
+import javax.management.MalformedObjectNameException;
 import javax.management.ObjectName;
 
 import java.io.File;
@@ -255,6 +259,18 @@
         return connector;
     }
     
+    /**
+     * Removes the given network connector without stopping it.
+     * The caller should call {@link NetworkConnector#stop()} to close the connector
+     */
+    public boolean removeNetworkConnector(NetworkConnector connector) {
+        boolean answer = networkConnectors.remove(connector);
+        if (answer) {
+            unregisterNetworkConnectorMBean(connector);
+        }
+        return answer;
+    }
+    
     public ProxyConnector addProxyConnector(ProxyConnector connector) throws Exception {
         URI uri = getVmConnectorURI();
         connector.setLocalUri(uri);
@@ -390,6 +406,7 @@
         
         for (Iterator iter = getNetworkConnectors().iterator(); iter.hasNext();) {
             NetworkConnector connector = (NetworkConnector) iter.next();
+            unregisterNetworkConnectorMBean(connector);
             stopper.stop(connector);
         }
 
@@ -945,9 +962,7 @@
         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()));
+                ObjectName objectName = createNetworkConnectorObjectName(connector);
                 mbeanServer.registerMBean(view, objectName);
                 registeredMBeanNames.add(objectName);
             }
@@ -957,6 +972,30 @@
         }
     }
 
+    protected ObjectName createNetworkConnectorObjectName(NetworkConnector connector) throws
MalformedObjectNameException {
+        return new ObjectName(managementContext.getJmxDomainName() + ":" + "BrokerName="
+                + JMXSupport.encodeObjectNamePart(getBrokerName()) + "," + "Type=NetworkConnector,"
+ "NetworkConnectorName="
+                + JMXSupport.encodeObjectNamePart(connector.getName()));
+    }
+
+    protected void unregisterNetworkConnectorMBean(NetworkConnector connector) {
+        if (isUseJmx()) {
+            MBeanServer mbeanServer = getManagementContext().getMBeanServer();
+            if (mbeanServer != null) {
+                try {
+                    ObjectName objectName = createNetworkConnectorObjectName(connector);
+                    if (registeredMBeanNames.contains(objectName)) {
+                        registeredMBeanNames.remove(objectName);
+                        mbeanServer.unregisterMBean(objectName);
+                    }
+                }
+                catch (Exception e) {
+                    log.error("Failed to unregister MBean: " + e, e);
+                }
+            }
+        }
+    }
+    
     protected void registerProxyConnectorMBean(ProxyConnector connector) throws IOException
{
         MBeanServer mbeanServer = getManagementContext().getMBeanServer();
         if (mbeanServer != null) {



Mime
View raw message