diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Run.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Run.java index 3a0c6c97fb..359a564909 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Run.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Run.java @@ -17,7 +17,6 @@ package org.apache.activemq.artemis.cli.commands; import java.io.File; -import java.util.ArrayList; import java.util.Timer; import java.util.TimerTask; @@ -27,7 +26,6 @@ import org.apache.activemq.artemis.cli.Artemis; import org.apache.activemq.artemis.cli.commands.tools.LockAbstract; import org.apache.activemq.artemis.components.ExternalComponent; import org.apache.activemq.artemis.core.config.impl.FileConfiguration; -import org.apache.activemq.artemis.core.server.ActiveMQComponent; import org.apache.activemq.artemis.dto.BrokerDTO; import org.apache.activemq.artemis.dto.ComponentDTO; import org.apache.activemq.artemis.factory.BrokerFactory; @@ -59,8 +57,6 @@ public class Run extends LockAbstract { private Broker server; - private ArrayList components = new ArrayList<>(); - @Override public Object execute(ActionContext context) throws Exception { super.execute(context); @@ -90,7 +86,7 @@ public class Run extends LockAbstract { ExternalComponent component = (ExternalComponent) clazz.newInstance(); component.configure(componentDTO, getBrokerInstance(), getBrokerHome()); component.start(); - components.add(component); + server.getServer().addExternalComponent(component); } return null; } @@ -102,13 +98,6 @@ public class Run extends LockAbstract { fileConfiguration.getLargeMessagesLocation().mkdirs(); } - private void stopServerAndComponenets() throws Exception { - for (ActiveMQComponent component : components) { - component.stop(); - } - server.stop(); - } - /** * Add a simple shutdown hook to stop the server. * @@ -146,7 +135,7 @@ public class Run extends LockAbstract { if (file.exists()) { try { try { - stopServerAndComponenets(); + server.stop(); } catch (Exception e) { e.printStackTrace(); @@ -169,7 +158,7 @@ public class Run extends LockAbstract { @Override public void run() { try { - stopServerAndComponenets(); + server.stop(); } catch (Exception e) { e.printStackTrace(); diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/integration/Broker.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/integration/Broker.java index 306675fa7b..494101ec16 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/integration/Broker.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/integration/Broker.java @@ -17,10 +17,11 @@ package org.apache.activemq.artemis.integration; import org.apache.activemq.artemis.core.server.ActiveMQComponent; +import org.apache.activemq.artemis.core.server.ActiveMQServer; /** * A Broker os a set of ActiveMQComponents that create a Server, for instance core and jms. */ public interface Broker extends ActiveMQComponent { - + ActiveMQServer getServer(); } diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/integration/FileBroker.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/integration/FileBroker.java index 8ae5729ebe..b120cc7b7d 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/integration/FileBroker.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/integration/FileBroker.java @@ -19,6 +19,7 @@ package org.apache.activemq.artemis.integration; import org.apache.activemq.artemis.core.config.FileDeploymentManager; import org.apache.activemq.artemis.core.config.impl.FileConfiguration; import org.apache.activemq.artemis.core.server.ActiveMQComponent; +import org.apache.activemq.artemis.core.server.ActiveMQServer; import org.apache.activemq.artemis.dto.ServerDTO; import org.apache.activemq.artemis.integration.bootstrap.ActiveMQBootstrapLogger; import org.apache.activemq.artemis.jms.server.config.impl.FileJMSConfiguration; @@ -103,4 +104,9 @@ public class FileBroker implements Broker { activeMQComponents.add(components.get("core")); return activeMQComponents; } + + @Override + public ActiveMQServer getServer() { + return (ActiveMQServer) components.get("core"); + } } diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQServer.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQServer.java index b777ced839..0842c0d824 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQServer.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQServer.java @@ -395,4 +395,6 @@ public interface ActiveMQServer extends ActiveMQComponent { void setHAPolicy(HAPolicy haPolicy); void setMBeanServer(MBeanServer mBeanServer); + + void addExternalComponent(ActiveMQComponent externalComponent); } diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java index 0d25271cd5..25511b0ba9 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java @@ -303,6 +303,8 @@ public class ActiveMQServerImpl implements ActiveMQServer { private ServiceRegistry serviceRegistry; private Date startDate; + + private final List externalComponents = new ArrayList<>(); // Constructors // --------------------------------------------------------------------------------- @@ -555,6 +557,11 @@ public class ActiveMQServerImpl implements ActiveMQServer { this.mbeanServer = mbeanServer; } + @Override + public void addExternalComponent(ActiveMQComponent externalComponent) { + externalComponents.add(externalComponent); + } + public ExecutorService getThreadPool() { return threadPool; } @@ -936,6 +943,15 @@ public class ActiveMQServerImpl implements ActiveMQServer { scaledDownNodeIDs.clear(); + for (ActiveMQComponent externalComponent : externalComponents) { + try { + externalComponent.stop(); + } + catch (Exception e) { + ActiveMQServerLogger.LOGGER.errorStoppingComponent(e, externalComponent.getClass().getName()); + } + } + if (identity != null) { ActiveMQServerLogger.LOGGER.serverStopped("identity=" + identity + ",version=" + getVersion().getFullVersion(), tempNodeID, getUptime()); }