diff options
-rw-r--r-- | config-proxy/src/main/java/com/yahoo/vespa/config/proxy/ProxyServer.java | 15 | ||||
-rw-r--r-- | jdisc_core/src/main/java/com/yahoo/jdisc/core/StandaloneMain.java | 8 | ||||
-rw-r--r-- | logserver/pom.xml | 5 | ||||
-rw-r--r-- | logserver/src/main/java/com/yahoo/logserver/Server.java | 8 | ||||
-rw-r--r-- | vespajlib/src/main/java/com/yahoo/system/CatchSigTerm.java | 70 | ||||
-rw-r--r-- | vespajlib/src/test/java/com/yahoo/system/CatchSigTermTestCase.java | 18 | ||||
-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 |
8 files changed, 31 insertions, 111 deletions
diff --git a/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/ProxyServer.java b/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/ProxyServer.java index 6274ec77e01..16d1cb6855b 100644 --- a/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/ProxyServer.java +++ b/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/ProxyServer.java @@ -4,17 +4,18 @@ package com.yahoo.vespa.config.proxy; import com.yahoo.concurrent.DaemonThreadFactory; import com.yahoo.config.subscription.ConfigSourceSet; import com.yahoo.jrt.Spec; - import com.yahoo.jrt.Supervisor; import com.yahoo.jrt.Transport; import com.yahoo.log.LogLevel; import com.yahoo.log.LogSetup; import com.yahoo.log.event.Event; -import com.yahoo.system.CatchSigTerm; -import com.yahoo.vespa.config.*; +import com.yahoo.vespa.config.JRTConnectionPool; +import com.yahoo.vespa.config.RawConfig; +import com.yahoo.vespa.config.TimingValues; import com.yahoo.vespa.config.protocol.JRTServerConfigRequest; import com.yahoo.vespa.filedistribution.FileDistributionRpcServer; import com.yahoo.vespa.filedistribution.FileDownloader; +import com.yahoo.yolean.system.CatchSignals; import java.util.List; import java.util.concurrent.Executors; @@ -175,8 +176,8 @@ public class ProxyServer implements Runnable { return new RpcConfigSourceClient(configSource, clientUpdater, memoryCache, timingValues, delayedResponses); } - private void setupSigTermHandler() { - CatchSigTerm.setup(signalCaught); // catch termination signal + private void setupSignalHandler() { + CatchSignals.setup(signalCaught); // catch termination and interrupt signals } private void waitForShutdown() { @@ -215,8 +216,8 @@ public class ProxyServer implements Runnable { DelayedResponses delayedResponses = new DelayedResponses(statistics); ProxyServer proxyServer = new ProxyServer(new Spec(null, port), delayedResponses, configSources, statistics, defaultTimingValues(), true, new MemoryCache(), null); - // catch termination signal - proxyServer.setupSigTermHandler(); + // catch termination and interrupt signal + proxyServer.setupSignalHandler(); Thread proxyserverThread = new Thread(proxyServer); proxyserverThread.setName("configproxy"); proxyserverThread.start(); diff --git a/jdisc_core/src/main/java/com/yahoo/jdisc/core/StandaloneMain.java b/jdisc_core/src/main/java/com/yahoo/jdisc/core/StandaloneMain.java index 1291418083b..770c59dec35 100644 --- a/jdisc_core/src/main/java/com/yahoo/jdisc/core/StandaloneMain.java +++ b/jdisc_core/src/main/java/com/yahoo/jdisc/core/StandaloneMain.java @@ -1,7 +1,7 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.jdisc.core; -import com.yahoo.yolean.system.CatchSigTerm; +import com.yahoo.yolean.system.CatchSignals; import java.util.Arrays; import java.util.concurrent.atomic.AtomicBoolean; @@ -41,7 +41,7 @@ public class StandaloneMain { System.out.println("debug\tInitializing application without privileges."); loader.init(bundleLocation, false); loader.start(); - setupSigTermHandler(); + setupSignalHandlers(); waitForShutdown(); System.out.println("debug\tTrying to shutdown in a controlled manner."); log.log(Level.INFO, "JDisc shutting down"); @@ -59,8 +59,8 @@ public class StandaloneMain { } private final AtomicBoolean signalCaught = new AtomicBoolean(false); - private void setupSigTermHandler() { - CatchSigTerm.setup(signalCaught); // catch termination signal + private void setupSignalHandlers() { + CatchSignals.setup(signalCaught); } private void waitForShutdown() { synchronized (signalCaught) { diff --git a/logserver/pom.xml b/logserver/pom.xml index be2d8ba4cee..1045b93185e 100644 --- a/logserver/pom.xml +++ b/logserver/pom.xml @@ -26,6 +26,11 @@ </dependency> <dependency> <groupId>com.yahoo.vespa</groupId> + <artifactId>yolean</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>com.yahoo.vespa</groupId> <artifactId>vespalog</artifactId> <version>${project.version}</version> </dependency> diff --git a/logserver/src/main/java/com/yahoo/logserver/Server.java b/logserver/src/main/java/com/yahoo/logserver/Server.java index 36b1c3e31a0..d0df5bf2972 100644 --- a/logserver/src/main/java/com/yahoo/logserver/Server.java +++ b/logserver/src/main/java/com/yahoo/logserver/Server.java @@ -10,7 +10,7 @@ import com.yahoo.logserver.handlers.HandlerThread; import com.yahoo.logserver.handlers.LogHandler; import com.yahoo.logserver.net.LogConnectionFactory; import com.yahoo.logserver.net.control.Levels; -import com.yahoo.system.CatchSigTerm; +import com.yahoo.yolean.system.CatchSignals; import java.io.IOException; import java.util.HashMap; @@ -150,8 +150,8 @@ public class Server implements Runnable { } } - private void setupSigTermHandler() { - CatchSigTerm.setup(signalCaught); // catch termination signal + private void setupSignalHandler() { + CatchSignals.setup(signalCaught); // catch termination and interrupt signals } private void waitForShutdown() { @@ -191,7 +191,7 @@ public class Server implements Runnable { String portString = System.getProperty(APPNAME + ".listenport", LISTEN_PORT); Server server = Server.getInstance(); - server.setupSigTermHandler(); + server.setupSignalHandler(); server.initialize(Integer.parseInt(portString)); Thread t = new Thread(server, "logserver main"); diff --git a/vespajlib/src/main/java/com/yahoo/system/CatchSigTerm.java b/vespajlib/src/main/java/com/yahoo/system/CatchSigTerm.java deleted file mode 100644 index e1f037f5d98..00000000000 --- a/vespajlib/src/main/java/com/yahoo/system/CatchSigTerm.java +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.system; - -import java.lang.reflect.*; - -// import sun.misc.Signal; -// import sun.misc.SignalHandler; - -import java.util.concurrent.atomic.AtomicBoolean; - -public class CatchSigTerm { - /** - * Sets up a signal handler for SIGTERM, where a given AtomicBoolean - * gets a true value when the TERM signal is caught. - * - * Callers basically have two options for acting on the TERM signal: - * - * They may choose to synchronize and wait() on this variable, - * and they will be notified when it changes state to true. To avoid - * problems with spurious wakeups, use a while loop and wait() - * again if the state is still false. As soon as the caller has been - * woken up and the state is true, the application should exit as - * soon as possible. - * - * They may also choose to poll the state of this variable. As soon - * 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. - */ - @SuppressWarnings("rawtypes") - public static void setup(final AtomicBoolean signalCaught) { - signalCaught.set(false); - try { - Class shc = Class.forName("sun.misc.SignalHandler"); - Class ssc = Class.forName("sun.misc.Signal"); - - InvocationHandler ihandler = new InvocationHandler() { - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { - synchronized (signalCaught) { - signalCaught.set(true); - signalCaught.notifyAll(); - } - return null; - } - }; - Object shandler = Proxy.newProxyInstance(CatchSigTerm.class.getClassLoader(), - new Class[] { shc }, - ihandler); - Constructor[] c = ssc.getDeclaredConstructors(); - assert c.length == 1; - Object sigterm = c[0].newInstance("TERM"); - Method m = findMethod(ssc, "handle"); - assert m != null; // "NoSuchMethodException" - m.invoke(null, sigterm, shandler); - } catch (ClassNotFoundException | InvocationTargetException | InstantiationException | IllegalAccessException e) { - System.err.println("FAILED setting up signal catching: "+e); - } - } - - @SuppressWarnings("rawtypes") - private static Method findMethod(Class c, String name) { - for (Method m : c.getDeclaredMethods()) { - if (m.getName().equals(name)) { - return m; - } - } - return null; - } -} diff --git a/vespajlib/src/test/java/com/yahoo/system/CatchSigTermTestCase.java b/vespajlib/src/test/java/com/yahoo/system/CatchSigTermTestCase.java deleted file mode 100644 index 9b370d4ce10..00000000000 --- a/vespajlib/src/test/java/com/yahoo/system/CatchSigTermTestCase.java +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.system; - -import org.junit.Test; - -import java.util.concurrent.atomic.AtomicBoolean; - -/** - * @author arnej27959 - */ -public class CatchSigTermTestCase { - - @Test - public void testThatSetupCompiles() { - CatchSigTerm.setup(new AtomicBoolean(false)); - } - -} 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)); } } |