ARTEMIS-2957 ManagementContext is started twice

This commit is contained in:
franz1981 2020-10-21 07:33:22 +02:00
parent 65c1f80dea
commit 0c8dd598b7
3 changed files with 31 additions and 18 deletions

View File

@ -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));

View File

@ -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;

View File

@ -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,6 +36,14 @@ public class ManagementContext implements ServiceComponent {
@Override @Override
public void start() throws Exception { public void start() throws Exception {
if (isStarted) {
return;
}
synchronized (this) {
if (isStarted) {
return;
}
isStarted = true;
if (accessControlList != null) { if (accessControlList != null) {
//if we are configured then assume we want to use the guard so set the system property //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()); System.setProperty("javax.management.builder.initial", ArtemisMBeanServerBuilder.class.getCanonicalName());
@ -49,12 +56,19 @@ public class ManagementContext implements ServiceComponent {
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) {