activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1382277 - /activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/ManagementContext.java
Date Sat, 08 Sep 2012 10:56:14 GMT
Author: davsclaus
Date: Sat Sep  8 10:56:14 2012
New Revision: 1382277

URL: http://svn.apache.org/viewvc?rev=1382277&view=rev
Log:
AMQ-3807: Support WebSphere JMX which regsiter mbeans using custom name. Thansk to Christian
Ohr for the patch.

Modified:
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/ManagementContext.java

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/ManagementContext.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/ManagementContext.java?rev=1382277&r1=1382276&r2=1382277&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/ManagementContext.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/ManagementContext.java
Sat Sep  8 10:56:14 2012
@@ -35,7 +35,7 @@ import java.rmi.registry.LocateRegistry;
 import java.rmi.registry.Registry;
 import java.rmi.server.RMIServerSocketFactory;
 import java.util.*;
-import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.atomic.AtomicBoolean;
 
 /**
@@ -68,7 +68,7 @@ public class ManagementContext implement
     private ObjectName namingServiceObjectName;
     private Registry registry;
     private ServerSocket registrySocket;
-    private final List<ObjectName> registeredMBeanNames = new CopyOnWriteArrayList<ObjectName>();
+    private final Map<ObjectName, ObjectName> registeredMBeanNames = new ConcurrentHashMap<ObjectName,
ObjectName>();
     private boolean allowRemoteAddressInMBeanNames = true;
     private String brokerName;
 
@@ -130,14 +130,19 @@ public class ManagementContext implement
     public void stop() throws Exception {
         if (started.compareAndSet(true, false)) {
             MBeanServer mbeanServer = getMBeanServer();
+
+            // unregister the mbeans we have registered
             if (mbeanServer != null) {
-                for (Iterator<ObjectName> iter = registeredMBeanNames.iterator(); iter.hasNext();)
{
-                    ObjectName name = iter.next();
-                    LOG.debug("Unregistering MBean {}", name);
-                    mbeanServer.unregisterMBean(name);
+                for (Map.Entry<ObjectName, ObjectName> entry : registeredMBeanNames.entrySet())
{
+                    ObjectName actualName = entry.getValue();
+                    if (actualName != null && beanServer.isRegistered(actualName))
{
+                        LOG.debug("Unregistering MBean {}", actualName);
+                        mbeanServer.unregisterMBean(actualName);
+                    }
                 }
             }
             registeredMBeanNames.clear();
+
             JMXConnectorServer server = connectorServer;
             connectorServer = null;
             if (server != null) {
@@ -347,11 +352,17 @@ public class ManagementContext implement
     
     public ObjectInstance registerMBean(Object bean, ObjectName name) throws Exception{
         ObjectInstance result = getMBeanServer().registerMBean(bean, name);
-        this.registeredMBeanNames.add(name);
+        this.registeredMBeanNames.put(name, result.getObjectName());
         return result;
     }
     
-    public Set<ObjectName>  queryNames(ObjectName name, QueryExp query) throws Exception{
+    public Set<ObjectName> queryNames(ObjectName name, QueryExp query) throws Exception{
+    	if (name != null) {
+    		ObjectName actualName = this.registeredMBeanNames.get(name);
+    		if (actualName != null) {
+    			return getMBeanServer().queryNames(actualName, query);
+    		}
+        }
         return getMBeanServer().queryNames(name, query);
     }
     
@@ -366,8 +377,10 @@ public class ManagementContext implement
      * @throws JMException
      */
     public void unregisterMBean(ObjectName name) throws JMException {
-        if (beanServer != null && beanServer.isRegistered(name) && this.registeredMBeanNames.remove(name))
{
-            beanServer.unregisterMBean(name);
+        ObjectName actualName = this.registeredMBeanNames.get(name);
+        if (beanServer != null && actualName != null && beanServer.isRegistered(actualName)
&& this.registeredMBeanNames.remove(name) != null) {
+            LOG.debug("Unregistering MBean {}", actualName);
+            beanServer.unregisterMBean(actualName);
         }
     }
 



Mime
View raw message