mirror of https://github.com/apache/activemq.git
https://issues.apache.org/jira/browse/AMQ-6065 - allow ioexception handler to flip the systemExitOnShutdown broker attribute before calling stop, i.e: exit on store io errors
This commit is contained in:
parent
0a12bcb928
commit
2aa172f905
|
@ -47,6 +47,7 @@ import org.slf4j.LoggerFactory;
|
||||||
private String sqlExceptionMessage = ""; // match all
|
private String sqlExceptionMessage = ""; // match all
|
||||||
private long resumeCheckSleepPeriod = 5*1000;
|
private long resumeCheckSleepPeriod = 5*1000;
|
||||||
private final AtomicBoolean handlingException = new AtomicBoolean(false);
|
private final AtomicBoolean handlingException = new AtomicBoolean(false);
|
||||||
|
private boolean systemExitOnShutdown = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(IOException exception) {
|
public void handle(IOException exception) {
|
||||||
|
@ -170,6 +171,7 @@ import org.slf4j.LoggerFactory;
|
||||||
if( broker.isRestartAllowed() ) {
|
if( broker.isRestartAllowed() ) {
|
||||||
broker.requestRestart();
|
broker.requestRestart();
|
||||||
}
|
}
|
||||||
|
broker.setSystemExitOnShutdown(isSystemExitOnShutdown());
|
||||||
broker.stop();
|
broker.stop();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOG.warn("Failure occurred while stopping broker", e);
|
LOG.warn("Failure occurred while stopping broker", e);
|
||||||
|
@ -242,4 +244,12 @@ import org.slf4j.LoggerFactory;
|
||||||
public void setResumeCheckSleepPeriod(long resumeCheckSleepPeriod) {
|
public void setResumeCheckSleepPeriod(long resumeCheckSleepPeriod) {
|
||||||
this.resumeCheckSleepPeriod = resumeCheckSleepPeriod;
|
this.resumeCheckSleepPeriod = resumeCheckSleepPeriod;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setSystemExitOnShutdown(boolean systemExitOnShutdown) {
|
||||||
|
this.systemExitOnShutdown = systemExitOnShutdown;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSystemExitOnShutdown() {
|
||||||
|
return systemExitOnShutdown;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,67 @@
|
||||||
|
/**
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.apache.activemq.util;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
import org.apache.activemq.broker.BrokerService;
|
||||||
|
import org.apache.activemq.broker.SuppressReplyException;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
public class DefaultIOExceptionHandlerTest {
|
||||||
|
|
||||||
|
DefaultIOExceptionHandler underTest = new DefaultIOExceptionHandler();
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHandleWithShutdownOnExit() throws Exception {
|
||||||
|
doTest(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHandleWithOutShutdownOnExit() throws Exception {
|
||||||
|
doTest(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void doTest(boolean exitPlease) throws Exception {
|
||||||
|
final CountDownLatch stopCalled = new CountDownLatch(1);
|
||||||
|
final AtomicBoolean shutdownOnExitSet = new AtomicBoolean(false);
|
||||||
|
|
||||||
|
underTest.setSystemExitOnShutdown(exitPlease);
|
||||||
|
underTest.setBrokerService(new BrokerService() {
|
||||||
|
@Override
|
||||||
|
public void stop() throws Exception {
|
||||||
|
shutdownOnExitSet.set(isSystemExitOnShutdown());
|
||||||
|
stopCalled.countDown();
|
||||||
|
super.stop();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
underTest.handle(new IOException("cause stop"));
|
||||||
|
fail("Expect suppress reply exception");
|
||||||
|
} catch (SuppressReplyException expected) {}
|
||||||
|
|
||||||
|
assertTrue("stop called on time", stopCalled.await(10, TimeUnit.SECONDS));
|
||||||
|
assertEquals("exit on shutdown set", exitPlease, shutdownOnExitSet.get());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue