ARTEMIS-686 shutdown external components

This commit is contained in:
jbertram 2016-08-19 13:58:32 -05:00
parent d03f6c8671
commit 3fd9fbe2d0
5 changed files with 29 additions and 15 deletions

View File

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

View File

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

View File

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

View File

@ -395,4 +395,6 @@ public interface ActiveMQServer extends ActiveMQComponent {
void setHAPolicy(HAPolicy haPolicy);
void setMBeanServer(MBeanServer mBeanServer);
void addExternalComponent(ActiveMQComponent externalComponent);
}

View File

@ -303,6 +303,8 @@ public class ActiveMQServerImpl implements ActiveMQServer {
private ServiceRegistry serviceRegistry;
private Date startDate;
private final List<ActiveMQComponent> 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());
}