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.

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1379454 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Claus Ibsen 2012-08-31 14:01:39 +00:00
parent ee2069f85c
commit 3092051699
1 changed files with 23 additions and 12 deletions

View File

@ -114,8 +114,8 @@ public class ManagementContext implements Service {
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 implements Service {
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 implements Service {
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 implements Service {
}
}
beanServer = null;
if(registrySocket!=null) {
if (registrySocket!=null) {
try {
registrySocket.close();
} catch (IOException e) {
@ -170,6 +178,9 @@ public class ManagementContext implements Service {
registrySocket = null;
}
}
// clear reference to aid GC
registry = null;
}
/**
@ -475,9 +486,8 @@ public class ManagementContext implements Service {
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 implements Service {
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() {