aboutsummaryrefslogtreecommitdiffstats
path: root/yolean
diff options
context:
space:
mode:
authorHåkon Hallingstad <hakon@verizonmedia.com>2019-01-27 19:54:20 +0100
committerHåkon Hallingstad <hakon@verizonmedia.com>2019-01-27 19:54:20 +0100
commit04221b18021faeb53754b4cec538307b62c9d558 (patch)
tree06727157e739d6406f2d3486c3710d6cc02984ee /yolean
parent8e700d0078e1015756a23781efc461913dc87419 (diff)
Terminate standalone container cleanly on SIGINT/control-C
Diffstat (limited to 'yolean')
-rw-r--r--yolean/src/main/java/com/yahoo/yolean/system/CatchSignals.java (renamed from yolean/src/main/java/com/yahoo/yolean/system/CatchSigTerm.java)14
-rw-r--r--yolean/src/test/java/com/yahoo/yolean/system/CatchSignalsTestCase.java (renamed from yolean/src/test/java/com/yahoo/yolean/system/CatchSigTermTestCase.java)4
2 files changed, 10 insertions, 8 deletions
diff --git a/yolean/src/main/java/com/yahoo/yolean/system/CatchSigTerm.java b/yolean/src/main/java/com/yahoo/yolean/system/CatchSignals.java
index ee87ab9c081..dce70fbbb5f 100644
--- a/yolean/src/main/java/com/yahoo/yolean/system/CatchSigTerm.java
+++ b/yolean/src/main/java/com/yahoo/yolean/system/CatchSignals.java
@@ -8,12 +8,12 @@ import java.lang.reflect.*;
import java.util.concurrent.atomic.AtomicBoolean;
-public class CatchSigTerm {
+public class CatchSignals {
/**
- * Sets up a signal handler for SIGTERM, where a given AtomicBoolean
- * gets a true value when the TERM signal is caught.
+ * Sets up a signal handler for SIGTERM and SIGINT, where a given AtomicBoolean
+ * gets a true value when the signal is caught.
*
- * Callers basically have two options for acting on the TERM signal:
+ * Callers basically have two options for acting on the signal:
*
* They may choose to synchronize and wait() on this variable,
* and they will be notified when it changes state to true. To avoid
@@ -26,7 +26,7 @@ public class CatchSigTerm {
* as its state becomes true, the signal has been received, and the
* application should exit as soon as possible.
*
- * @param signalCaught set to false initially, will be set to true when SIGTERM is caught.
+ * @param signalCaught set to false initially, will be set to true when SIGTERM or SIGINT is caught.
*/
@SuppressWarnings("rawtypes")
public static void setup(final AtomicBoolean signalCaught) {
@@ -44,15 +44,17 @@ public class CatchSigTerm {
return null;
}
};
- Object shandler = Proxy.newProxyInstance(CatchSigTerm.class.getClassLoader(),
+ Object shandler = Proxy.newProxyInstance(CatchSignals.class.getClassLoader(),
new Class[] { shc },
ihandler);
Constructor[] c = ssc.getDeclaredConstructors();
assert c.length == 1;
Object sigterm = c[0].newInstance("TERM");
+ Object sigint = c[0].newInstance("INT");
Method m = findMethod(ssc, "handle");
assert m != null; // "NoSuchMethodException"
m.invoke(null, sigterm, shandler);
+ m.invoke(null, sigint, shandler);
} catch (ClassNotFoundException | InvocationTargetException | InstantiationException | IllegalAccessException e) {
System.err.println("FAILED setting up signal catching: "+e);
}
diff --git a/yolean/src/test/java/com/yahoo/yolean/system/CatchSigTermTestCase.java b/yolean/src/test/java/com/yahoo/yolean/system/CatchSignalsTestCase.java
index 056db2d3592..e68ce334f31 100644
--- a/yolean/src/test/java/com/yahoo/yolean/system/CatchSigTermTestCase.java
+++ b/yolean/src/test/java/com/yahoo/yolean/system/CatchSignalsTestCase.java
@@ -8,11 +8,11 @@ import java.util.concurrent.atomic.AtomicBoolean;
/**
* @author arnej27959
*/
-public class CatchSigTermTestCase {
+public class CatchSignalsTestCase {
@Test
public void testThatSetupCompiles() {
- CatchSigTerm.setup(new AtomicBoolean(false));
+ CatchSignals.setup(new AtomicBoolean(false));
}
}