ARTEMIS-2957 ManagementContext is started twice
This commit is contained in:
parent
65c1f80dea
commit
0c8dd598b7
|
@ -109,7 +109,6 @@ public class Run extends LockAbstract {
|
||||||
|
|
||||||
server = BrokerFactory.createServer(broker.server, securityManager, activateCallback);
|
server = BrokerFactory.createServer(broker.server, securityManager, activateCallback);
|
||||||
|
|
||||||
managementContext.start();
|
|
||||||
server.createComponents();
|
server.createComponents();
|
||||||
AtomicBoolean serverActivationFailed = new AtomicBoolean(false);
|
AtomicBoolean serverActivationFailed = new AtomicBoolean(false);
|
||||||
server.getServer().registerActivationFailureListener(exception -> serverActivationFailed.set(true));
|
server.getServer().registerActivationFailureListener(exception -> serverActivationFailed.set(true));
|
||||||
|
|
|
@ -34,7 +34,7 @@ import org.apache.activemq.artemis.spi.core.security.ActiveMQSecurityManager;
|
||||||
public class FileBroker implements Broker {
|
public class FileBroker implements Broker {
|
||||||
|
|
||||||
private final String configurationUrl;
|
private final String configurationUrl;
|
||||||
private ActivateCallback activateCallback;
|
private final ActivateCallback activateCallback;
|
||||||
|
|
||||||
private boolean started;
|
private boolean started;
|
||||||
|
|
||||||
|
|
|
@ -17,18 +17,17 @@
|
||||||
package org.apache.activemq.artemis.core.server.management;
|
package org.apache.activemq.artemis.core.server.management;
|
||||||
|
|
||||||
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import javax.management.NotCompliantMBeanException;
|
||||||
|
|
||||||
import org.apache.activemq.artemis.core.config.JMXConnectorConfiguration;
|
import org.apache.activemq.artemis.core.config.JMXConnectorConfiguration;
|
||||||
import org.apache.activemq.artemis.core.persistence.StorageManager;
|
import org.apache.activemq.artemis.core.persistence.StorageManager;
|
||||||
import org.apache.activemq.artemis.core.server.ServiceComponent;
|
import org.apache.activemq.artemis.core.server.ServiceComponent;
|
||||||
import org.apache.activemq.artemis.core.server.management.impl.HawtioSecurityControlImpl;
|
import org.apache.activemq.artemis.core.server.management.impl.HawtioSecurityControlImpl;
|
||||||
|
|
||||||
import javax.management.NotCompliantMBeanException;
|
|
||||||
import org.apache.activemq.artemis.spi.core.security.ActiveMQSecurityManager;
|
import org.apache.activemq.artemis.spi.core.security.ActiveMQSecurityManager;
|
||||||
|
|
||||||
public class ManagementContext implements ServiceComponent {
|
public class ManagementContext implements ServiceComponent {
|
||||||
private AtomicBoolean isStarted = new AtomicBoolean(false);
|
|
||||||
|
private volatile boolean isStarted = false;
|
||||||
private JMXAccessControlList accessControlList;
|
private JMXAccessControlList accessControlList;
|
||||||
private JMXConnectorConfiguration jmxConnectorConfiguration;
|
private JMXConnectorConfiguration jmxConnectorConfiguration;
|
||||||
private ManagementConnector mBeanServer;
|
private ManagementConnector mBeanServer;
|
||||||
|
@ -37,24 +36,39 @@ public class ManagementContext implements ServiceComponent {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start() throws Exception {
|
public void start() throws Exception {
|
||||||
if (accessControlList != null) {
|
if (isStarted) {
|
||||||
//if we are configured then assume we want to use the guard so set the system property
|
return;
|
||||||
System.setProperty("javax.management.builder.initial", ArtemisMBeanServerBuilder.class.getCanonicalName());
|
|
||||||
guardHandler = new ArtemisMBeanServerGuard();
|
|
||||||
guardHandler.setJMXAccessControlList(accessControlList);
|
|
||||||
ArtemisMBeanServerBuilder.setGuard(guardHandler);
|
|
||||||
}
|
}
|
||||||
|
synchronized (this) {
|
||||||
|
if (isStarted) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
isStarted = true;
|
||||||
|
if (accessControlList != null) {
|
||||||
|
//if we are configured then assume we want to use the guard so set the system property
|
||||||
|
System.setProperty("javax.management.builder.initial", ArtemisMBeanServerBuilder.class.getCanonicalName());
|
||||||
|
guardHandler = new ArtemisMBeanServerGuard();
|
||||||
|
guardHandler.setJMXAccessControlList(accessControlList);
|
||||||
|
ArtemisMBeanServerBuilder.setGuard(guardHandler);
|
||||||
|
}
|
||||||
|
|
||||||
if (jmxConnectorConfiguration != null) {
|
if (jmxConnectorConfiguration != null) {
|
||||||
mBeanServer = new ManagementConnector(jmxConnectorConfiguration, securityManager);
|
mBeanServer = new ManagementConnector(jmxConnectorConfiguration, securityManager);
|
||||||
mBeanServer.start();
|
mBeanServer.start();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
isStarted.set(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stop() throws Exception {
|
public void stop() throws Exception {
|
||||||
if (isStarted.getAndSet(false)) {
|
if (!isStarted) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
synchronized (this) {
|
||||||
|
if (!isStarted) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
isStarted = false;
|
||||||
if (mBeanServer != null) {
|
if (mBeanServer != null) {
|
||||||
mBeanServer.stop();
|
mBeanServer.stop();
|
||||||
}
|
}
|
||||||
|
@ -70,7 +84,7 @@ public class ManagementContext implements ServiceComponent {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isStarted() {
|
public boolean isStarted() {
|
||||||
return isStarted.get();
|
return isStarted;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAccessControlList(JMXAccessControlList accessControlList) {
|
public void setAccessControlList(JMXAccessControlList accessControlList) {
|
||||||
|
|
Loading…
Reference in New Issue