https://issues.apache.org/activemq/browse/AMQ-2525 - Prevent broker deadlock if jmxconnector start hangs

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@888367 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Bosanac Dejan 2009-12-08 12:22:24 +00:00
parent df52a09063
commit c9ca34a27a
1 changed files with 11 additions and 3 deletions

View File

@ -70,6 +70,7 @@ public class ManagementContext implements Service {
private int rmiServerPort; private int rmiServerPort;
private String connectorPath = "/jmxrmi"; private String connectorPath = "/jmxrmi";
private AtomicBoolean started = new AtomicBoolean(false); private AtomicBoolean started = new AtomicBoolean(false);
private AtomicBoolean connectorStarting = new AtomicBoolean(false);
private JMXConnectorServer connectorServer; private JMXConnectorServer connectorServer;
private ObjectName namingServiceObjectName; private ObjectName namingServiceObjectName;
private Registry registry; private Registry registry;
@ -98,7 +99,12 @@ public class ManagementContext implements Service {
JMXConnectorServer server = connectorServer; JMXConnectorServer server = connectorServer;
if (started.get() && server != null) { if (started.get() && server != null) {
LOG.debug("Starting JMXConnectorServer..."); LOG.debug("Starting JMXConnectorServer...");
server.start(); connectorStarting.set(true);
try {
server.start();
} finally {
connectorStarting.set(false);
}
LOG.info("JMX consoles can connect to " + server.getAddress()); LOG.info("JMX consoles can connect to " + server.getAddress());
} }
} catch (IOException e) { } catch (IOException e) {
@ -129,7 +135,9 @@ public class ManagementContext implements Service {
connectorServer = null; connectorServer = null;
if (server != null) { if (server != null) {
try { try {
server.stop(); if (!connectorStarting.get()) {
server.stop();
}
} catch (IOException e) { } catch (IOException e) {
LOG.warn("Failed to stop jmx connector: " + e.getMessage()); LOG.warn("Failed to stop jmx connector: " + e.getMessage());
} }
@ -217,7 +225,7 @@ public class ManagementContext implements Service {
} }
public boolean isConnectorStarted() { public boolean isConnectorStarted() {
return connectorServer != null && connectorServer.isActive(); return connectorStarting.get() || (connectorServer != null && connectorServer.isActive());
} }
/** /**