diff options
-rw-r--r-- | container-core/pom.xml | 1 | ||||
-rw-r--r-- | container-di/pom.xml | 1 | ||||
-rw-r--r-- | container-disc/pom.xml | 1 | ||||
-rw-r--r-- | jdisc_core/pom.xml | 9 | ||||
-rw-r--r-- | jdisc_core/src/main/java/com/yahoo/jdisc/core/StandaloneMain.java | 2 | ||||
-rw-r--r-- | standalone-container/pom.xml | 3 | ||||
-rw-r--r-- | yolean/src/main/java/com/yahoo/yolean/system/CatchSigTerm.java | 69 | ||||
-rw-r--r-- | yolean/src/main/java/com/yahoo/yolean/system/package-info.java | 5 | ||||
-rw-r--r-- | yolean/src/test/java/com/yahoo/yolean/system/CatchSigTermTestCase.java | 19 |
9 files changed, 97 insertions, 13 deletions
diff --git a/container-core/pom.xml b/container-core/pom.xml index 650c5e87074..e9b2d18628d 100644 --- a/container-core/pom.xml +++ b/container-core/pom.xml @@ -144,7 +144,6 @@ <groupId>com.yahoo.vespa</groupId> <artifactId>vespajlib</artifactId> <version>${project.version}</version> - <scope>provided</scope> <exclusions> <exclusion> <groupId>log4j</groupId> diff --git a/container-di/pom.xml b/container-di/pom.xml index 0cab901ab9f..f78cae8f434 100644 --- a/container-di/pom.xml +++ b/container-di/pom.xml @@ -73,7 +73,6 @@ <groupId>com.yahoo.vespa</groupId> <artifactId>vespajlib</artifactId> <version>${project.version}</version> - <scope>provided</scope> <exclusions> <exclusion> <groupId>log4j</groupId> diff --git a/container-disc/pom.xml b/container-disc/pom.xml index b94b626da73..f320eb371bb 100644 --- a/container-disc/pom.xml +++ b/container-disc/pom.xml @@ -94,7 +94,6 @@ <groupId>com.yahoo.vespa</groupId> <artifactId>vespajlib</artifactId> <version>${project.version}</version> - <scope>provided</scope> </dependency> <dependency> <groupId>com.yahoo.vespa</groupId> diff --git a/jdisc_core/pom.xml b/jdisc_core/pom.xml index 7bd1a54d330..315a46a65c4 100644 --- a/jdisc_core/pom.xml +++ b/jdisc_core/pom.xml @@ -121,13 +121,7 @@ <scope>compile</scope> </dependency> <dependency> - <groupId>com.yahoo.vespa</groupId> - <artifactId>vespajlib</artifactId> - <version>${project.version}</version> - <scope>compile</scope> - </dependency> - <dependency> - <!-- Used for export-package parsing. Ideally, that should have been a separate artifact. --> + <!-- This seems odd. Used for export-package parsing. Lazy stuff. Should be separated out. --> <groupId>com.yahoo.vespa</groupId> <artifactId>bundle-plugin</artifactId> <version>${project.version}</version> @@ -212,7 +206,6 @@ <argument>${project.build.directory}/dependency/log4j-over-slf4j.jar</argument> <argument>${project.build.directory}/dependency/config-lib.jar</argument> <argument>${project.build.directory}/dependency/yolean.jar</argument> - <argument>${project.build.directory}/dependency/vespajlib.jar</argument> </arguments> </configuration> </execution> 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 552d423f8cb..84e91a52e3a 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 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.jdisc.core; -import com.yahoo.system.CatchSigTerm; +import com.yahoo.yolean.system.CatchSigTerm; import java.util.Arrays; import java.util.concurrent.atomic.AtomicBoolean; diff --git a/standalone-container/pom.xml b/standalone-container/pom.xml index b211d196160..eb5665760c4 100644 --- a/standalone-container/pom.xml +++ b/standalone-container/pom.xml @@ -85,7 +85,8 @@ config-bundle-jar-with-dependencies.jar, config-model-api-jar-with-dependencies.jar, config-model-jar-with-dependencies.jar, - container-disc-jar-with-dependencies.jar + container-disc-jar-with-dependencies.jar, + vespajlib.jar </discPreInstallBundle> <bundleActivator>com.yahoo.container.standalone.StandaloneContainerActivator</bundleActivator> <jdiscPrivilegedActivator>true</jdiscPrivilegedActivator> diff --git a/yolean/src/main/java/com/yahoo/yolean/system/CatchSigTerm.java b/yolean/src/main/java/com/yahoo/yolean/system/CatchSigTerm.java new file mode 100644 index 00000000000..204dcaacf28 --- /dev/null +++ b/yolean/src/main/java/com/yahoo/yolean/system/CatchSigTerm.java @@ -0,0 +1,69 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.yolean.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); + } + } + + 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/yolean/src/main/java/com/yahoo/yolean/system/package-info.java b/yolean/src/main/java/com/yahoo/yolean/system/package-info.java new file mode 100644 index 00000000000..e727474ec52 --- /dev/null +++ b/yolean/src/main/java/com/yahoo/yolean/system/package-info.java @@ -0,0 +1,5 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +@ExportPackage +package com.yahoo.yolean.system; + +import com.yahoo.osgi.annotation.ExportPackage; diff --git a/yolean/src/test/java/com/yahoo/yolean/system/CatchSigTermTestCase.java b/yolean/src/test/java/com/yahoo/yolean/system/CatchSigTermTestCase.java new file mode 100644 index 00000000000..d2ad84948e1 --- /dev/null +++ b/yolean/src/test/java/com/yahoo/yolean/system/CatchSigTermTestCase.java @@ -0,0 +1,19 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.yolean.system; + +import com.yahoo.yolean.system.CatchSigTerm; +import java.util.concurrent.atomic.AtomicBoolean; + +/** + * @author arnej27959 + */ +public class CatchSigTermTestCase extends junit.framework.TestCase { + + public CatchSigTermTestCase(String name) { + super(name); + } + + public void testThatSetupCompiles() { + CatchSigTerm.setup(new AtomicBoolean(false)); + } +} |