incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1587885 - in /sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/jarexec: JarExecutor.java ShutdownHookSingleProcessDestroyer.java
Date Wed, 16 Apr 2014 11:59:43 GMT
Author: bdelacretaz
Date: Wed Apr 16 11:59:43 2014
New Revision: 1587885

URL: http://svn.apache.org/r1587885
Log:
SLING-3503 - JarExecutor waits for process in shutdown hook if the jar.executor.wait.on.shutdown
property is true

Modified:
    sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/jarexec/JarExecutor.java
    sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/jarexec/ShutdownHookSingleProcessDestroyer.java

Modified: sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/jarexec/JarExecutor.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/jarexec/JarExecutor.java?rev=1587885&r1=1587884&r2=1587885&view=diff
==============================================================================
--- sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/jarexec/JarExecutor.java
(original)
+++ sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/jarexec/JarExecutor.java
Wed Apr 16 11:59:43 2014
@@ -56,6 +56,7 @@ public class JarExecutor {
     public static final String PROP_WORK_FOLDER = PROP_PREFIX + "work.folder";
     public static final String PROP_JAR_OPTIONS = PROP_PREFIX + "jar.options";
     public static final String PROP_EXIT_TIMEOUT_SECONDS = PROP_PREFIX + "exit.timeout.seconds";
+    public static final String PROP_WAIT_ONSHUTDOWN = PROP_PREFIX + "wait.on.shutdown";
 
     @SuppressWarnings("serial")
     public static class ExecutorException extends Exception {
@@ -166,8 +167,11 @@ public class JarExecutor {
 
         log.info("Executing " + cl);
         executor.setStreamHandler(new PumpStreamHandler());
-        executor.setProcessDestroyer(
-                new ShutdownHookSingleProcessDestroyer("java -jar " + jarToExecute.getName(),
exitTimeoutSeconds));
+        final ShutdownHookSingleProcessDestroyer pd = new ShutdownHookSingleProcessDestroyer("java
-jar " + jarToExecute.getName(), exitTimeoutSeconds);
+        final boolean waitOnShutdown = Boolean.valueOf(config.getProperty(PROP_WAIT_ONSHUTDOWN,
"false"));
+        log.info("Setting up ProcessDestroyer with waitOnShutdown=" + waitOnShutdown);
+        pd.setWaitOnShutdown(waitOnShutdown);
+        executor.setProcessDestroyer(pd);
         executor.execute(cl, h);
     }
 

Modified: sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/jarexec/ShutdownHookSingleProcessDestroyer.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/jarexec/ShutdownHookSingleProcessDestroyer.java?rev=1587885&r1=1587884&r2=1587885&view=diff
==============================================================================
--- sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/jarexec/ShutdownHookSingleProcessDestroyer.java
(original)
+++ sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/jarexec/ShutdownHookSingleProcessDestroyer.java
Wed Apr 16 11:59:43 2014
@@ -33,12 +33,21 @@ class ShutdownHookSingleProcessDestroyer
     private Process process;
     private final int timeoutSeconds;
     private final String processInfo;
+    private boolean waitOnShutdown = false;
     
-    ShutdownHookSingleProcessDestroyer(String processInfo, int timeoutSeconds) {
+    public ShutdownHookSingleProcessDestroyer(String processInfo, int timeoutSeconds) {
         this.processInfo = processInfo;
         this.timeoutSeconds = timeoutSeconds;
     }
     
+    public boolean getWaitOnShutdown() {
+        return waitOnShutdown;
+    }
+
+    public void setWaitOnShutdown(boolean waitOnShutdown) {
+        this.waitOnShutdown = waitOnShutdown;
+    }
+
     public synchronized boolean add(Process p) {
         if(process != null) {
             throw new IllegalStateException("Process already set: " + process);
@@ -63,9 +72,7 @@ class ShutdownHookSingleProcessDestroyer
     }
     
     public void run() {
-        // Do not wait for our process when running as a shutdown
-        // hook - might cause trouble
-        destroyProcess(false);
+        destroyProcess(waitOnShutdown);
     }
     
    public void destroyProcess(boolean waitForIt) {



Mime
View raw message