ARTEMIS-1253 Fixing NetworkHealthCheck being shutdown after failures

This commit is contained in:
Clebert Suconic 2017-06-26 13:13:43 -04:00
parent 36110da9c8
commit f407d86f0f
6 changed files with 24 additions and 32 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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