From f407d86f0fd8d8472600364caf88e1711c0e4e0b Mon Sep 17 00:00:00 2001 From: Clebert Suconic Date: Mon, 26 Jun 2017 13:13:43 -0400 Subject: [PATCH] ARTEMIS-1253 Fixing NetworkHealthCheck being shutdown after failures --- .../activemq/artemis/cli/commands/Run.java | 4 ++-- .../artemis/integration/FileBroker.java | 12 ++++------ .../artemis/core/server/ServiceComponent.java | 2 +- .../core/server/impl/ActiveMQServerImpl.java | 22 ++++++++----------- .../core/server/impl/EmbeddedServerTest.java | 12 ++++++---- .../artemis/component/WebServerComponent.java | 4 ---- 6 files changed, 24 insertions(+), 32 deletions(-) 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 e48a1f40d1..229bd5b3ad 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 @@ -122,7 +122,7 @@ public class Run extends LockAbstract { if (file.exists()) { try { try { - server.exit(); + server.stop(true); } catch (Exception e) { e.printStackTrace(); } @@ -143,7 +143,7 @@ public class Run extends LockAbstract { @Override public void run() { try { - server.exit(); + server.stop(true); } catch (Exception e) { e.printStackTrace(); } 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 af2286fc63..744a0e6c3b 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 @@ -124,23 +124,19 @@ public class FileBroker implements Broker { @Override public void stop() throws Exception { - stop(false); - } - - @Override - public void exit() throws Exception { stop(true); } - private void stop(boolean isShutdown) throws Exception { + @Override + public void stop(boolean isShutdown) throws Exception { if (!started) { return; } ActiveMQComponent[] mqComponents = new ActiveMQComponent[components.size()]; components.values().toArray(mqComponents); for (int i = mqComponents.length - 1; i >= 0; i--) { - if (mqComponents[i] instanceof ServiceComponent && isShutdown) { - ((ServiceComponent) mqComponents[i]).exit(); + if (mqComponents[i] instanceof ServiceComponent) { + ((ServiceComponent) mqComponents[i]).stop(isShutdown); } else { mqComponents[i].stop(); } diff --git a/artemis-commons/src/main/java/org/apache/activemq/artemis/core/server/ServiceComponent.java b/artemis-commons/src/main/java/org/apache/activemq/artemis/core/server/ServiceComponent.java index 6c347dd327..8ef15775fe 100644 --- a/artemis-commons/src/main/java/org/apache/activemq/artemis/core/server/ServiceComponent.java +++ b/artemis-commons/src/main/java/org/apache/activemq/artemis/core/server/ServiceComponent.java @@ -22,5 +22,5 @@ package org.apache.activemq.artemis.core.server; public interface ServiceComponent extends ActiveMQComponent { //called by shutdown hooks before exit the VM - void exit() throws Exception; + void stop(boolean shutdown) throws Exception; } 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 6ab95ee931..ba7bed05cb 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 @@ -340,7 +340,7 @@ public class ActiveMQServerImpl implements ActiveMQServer { @Override public void stop() throws Exception { - internalStop(false); + ActiveMQServerImpl.this.stop(false); } @Override @@ -679,20 +679,16 @@ public class ActiveMQServerImpl implements ActiveMQServer { } @Override - public void exit() throws Exception { - internalStop(true); + public void stop() throws Exception { + stop(true); } @Override - public final void stop() throws Exception { - internalStop(false); - } - - private void internalStop(boolean isExit) throws Exception { + public void stop(boolean isShutdown) throws Exception { try { - stop(false, isExit); + stop(false, isShutdown); } finally { - networkHealthCheck.stop(); + if (isShutdown) networkHealthCheck.stop(); } } @@ -866,7 +862,7 @@ public class ActiveMQServerImpl implements ActiveMQServer { * * @param criticalIOError whether we have encountered an IO error with the journal etc */ - void stop(boolean failoverOnServerShutdown, final boolean criticalIOError, boolean restarting, boolean isExit) { + void stop(boolean failoverOnServerShutdown, final boolean criticalIOError, boolean restarting, boolean isShutdown) { synchronized (this) { if (state == SERVER_STATE.STOPPED || state == SERVER_STATE.STOPPING) { @@ -1055,8 +1051,8 @@ public class ActiveMQServerImpl implements ActiveMQServer { for (ActiveMQComponent externalComponent : externalComponents) { try { - if (isExit && externalComponent instanceof ServiceComponent) { - ((ServiceComponent)externalComponent).exit(); + if (externalComponent instanceof ServiceComponent) { + ((ServiceComponent)externalComponent).stop(isShutdown); } else { externalComponent.stop(); } diff --git a/artemis-server/src/test/java/org/apache/activemq/artemis/core/server/impl/EmbeddedServerTest.java b/artemis-server/src/test/java/org/apache/activemq/artemis/core/server/impl/EmbeddedServerTest.java index e47440dcbe..31b2626ce6 100644 --- a/artemis-server/src/test/java/org/apache/activemq/artemis/core/server/impl/EmbeddedServerTest.java +++ b/artemis-server/src/test/java/org/apache/activemq/artemis/core/server/impl/EmbeddedServerTest.java @@ -81,7 +81,7 @@ public class EmbeddedServerTest { server.addExternalComponent(normalComponent); server.addExternalComponent(serviceComponent); - server.stop(); + server.stop(false); assertTrue(normalComponent.stopCalled); assertTrue(serviceComponent.stopCalled); @@ -91,7 +91,7 @@ public class EmbeddedServerTest { serviceComponent.resetFlags(); server.start(); - server.exit(); + server.stop(); assertTrue(normalComponent.stopCalled); assertFalse(serviceComponent.stopCalled); @@ -129,8 +129,12 @@ public class EmbeddedServerTest { volatile boolean exitCalled; @Override - public void exit() throws Exception { - exitCalled = true; + public void stop(boolean isShutdown) throws Exception { + if (isShutdown) { + exitCalled = true; + } else { + stop(); + } } @Override diff --git a/artemis-web/src/main/java/org/apache/activemq/artemis/component/WebServerComponent.java b/artemis-web/src/main/java/org/apache/activemq/artemis/component/WebServerComponent.java index 6dce708dc8..5ac42df4ae 100644 --- a/artemis-web/src/main/java/org/apache/activemq/artemis/component/WebServerComponent.java +++ b/artemis-web/src/main/java/org/apache/activemq/artemis/component/WebServerComponent.java @@ -191,10 +191,6 @@ public class WebServerComponent implements ExternalComponent { } @Override - public void exit() throws Exception { - stop(true); - } - public void stop(boolean isShutdown) throws Exception { if (isShutdown) { internalStop();