activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1379454 - /activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/ManagementContext.java
Date Fri, 31 Aug 2012 14:01:39 GMT
Author: davsclaus
Date: Fri Aug 31 14:01:39 2012
New Revision: 1379454

URL: http://svn.apache.org/viewvc?rev=1379454&view=rev
Log:
AMQ-4008: Fixed issue with re-deploying AMQ broker in same JVM such as Apache Tomcat, with
the jmx connector not working on re-deployment. Now it does. Improved logging and better message
to end user about the JMX issue.

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=1379454&r1=1379453&r2=1379454&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
Fri Aug 31 14:01:39 2012
@@ -114,8 +114,8 @@ public class ManagementContext implement
                                 LOG.info("JMX consoles can connect to " + server.getAddress());
                             }
                         } catch (IOException e) {
-                            LOG.warn("Failed to start jmx connector: " + e.getMessage());
-                            LOG.debug("Reason for failed jms connector start", e);
+                            LOG.warn("Failed to start jmx connector: " + e.getMessage() +
". Will restart management to re-create jmx connector, trying to remedy this issue.");
+                            LOG.debug("Reason for failed jmx connector start", e);
                         } finally {
                             MDC.remove("activemq.broker");
                         }
@@ -133,9 +133,8 @@ public class ManagementContext implement
             if (mbeanServer != null) {
                 for (Iterator<ObjectName> iter = registeredMBeanNames.iterator(); iter.hasNext();)
{
                     ObjectName name = iter.next();
-                    
-                        mbeanServer.unregisterMBean(name);
-                    
+                    LOG.debug("Unregistering MBean {}", name);
+                    mbeanServer.unregisterMBean(name);
                 }
             }
             registeredMBeanNames.clear();
@@ -144,15 +143,24 @@ public class ManagementContext implement
             if (server != null) {
                 try {
                 	if (!connectorStarting.get()) {
-                		server.stop();
+                        LOG.debug("Stopping jmx connector");
+                        server.stop();
                 	}
                 } catch (IOException e) {
                     LOG.warn("Failed to stop jmx connector: " + e.getMessage());
                 }
+                // stop naming service mbean
                 try {
-                    getMBeanServer().invoke(namingServiceObjectName, "stop", null, null);
+                    if (getMBeanServer().isRegistered(namingServiceObjectName)) {
+                        LOG.debug("Stopping MBean {}", namingServiceObjectName);
+                        getMBeanServer().invoke(namingServiceObjectName, "stop", null, null);
+                        LOG.debug("Unregistering MBean {}", namingServiceObjectName);
+                        getMBeanServer().unregisterMBean(namingServiceObjectName);
+                    }
                 } catch (Throwable ignore) {
+                    LOG.warn("Error stopping and unregsitering mbean " + namingServiceObjectName
+ " due " + ignore.getMessage());
                 }
+                namingServiceObjectName = null;
             }
             if (locallyCreateMBeanServer && beanServer != null) {
                 // check to see if the factory knows about this server
@@ -162,7 +170,7 @@ public class ManagementContext implement
                 }
             }
             beanServer = null;
-            if(registrySocket!=null) {
+            if (registrySocket!=null) {
                 try {
                     registrySocket.close();
                 } catch (IOException e) {
@@ -170,6 +178,9 @@ public class ManagementContext implement
                 registrySocket = null;
             }
         }
+
+        // clear reference to aid GC
+        registry = null;
     }
 
     /**
@@ -475,9 +486,8 @@ public class ManagementContext implement
             mbeanServer.setAttribute(namingServiceObjectName, attr);
         } catch(ClassNotFoundException e) {
             LOG.debug("Probably not using JRE 1.4: " + e.getLocalizedMessage());
-        }
-        catch (Throwable e) {
-            LOG.debug("Failed to create local registry", e);
+        } catch (Throwable e) {
+            LOG.debug("Failed to create local registry. This exception will be ignored.",
e);
         }
         // Create the JMXConnectorServer
         String rmiServer = "";
@@ -489,7 +499,8 @@ public class ManagementContext implement
         String serviceURL = "service:jmx:rmi://" + rmiServer + "/jndi/rmi://" +getConnectorHost()+":"
+ connectorPort + connectorPath;
         JMXServiceURL url = new JMXServiceURL(serviceURL);
         connectorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, environment,
mbeanServer);
-        
+
+        LOG.debug("Created JMXConnectorServer {}", connectorServer);
     }
 
     public String getConnectorPath() {



Mime
View raw message