incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1232484 - in /sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools: jarexec/JarExecutor.java serversetup/StartRunnableJarPhase.java
Date Tue, 17 Jan 2012 17:07:17 GMT
Author: bdelacretaz
Date: Tue Jan 17 17:07:17 2012
New Revision: 1232484

URL: http://svn.apache.org/viewvc?rev=1232484&view=rev
Log:
SLING-2368 - provide a SetupPhase that kills the started process

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/serversetup/StartRunnableJarPhase.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=1232484&r1=1232483&r2=1232484&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
Tue Jan 17 17:07:17 2012
@@ -41,6 +41,7 @@ public class JarExecutor {
     private final String javaExecutable;
     private final int serverPort;
     private final Properties config;
+    private Executor executor;
     
     private final Logger log = LoggerFactory.getLogger(getClass());
 
@@ -132,7 +133,7 @@ public class JarExecutor {
         };
         
         final String vmOptions = config.getProperty(PROP_VM_OPTIONS);
-        final Executor e = new DefaultExecutor();
+        executor = new DefaultExecutor();
         final CommandLine cl = new CommandLine(javaExecutable);
         if (vmOptions != null && vmOptions.length() > 0) {
             cl.addArguments(vmOptions);
@@ -157,17 +158,31 @@ public class JarExecutor {
                         + workFolder.getAbsolutePath());
             }
             log.info("Setting working directory for executable jar: {}", workFolder.getAbsolutePath());
-            e.setWorkingDirectory(workFolder);
+            executor.setWorkingDirectory(workFolder);
         }
 
         log.info("Executing " + cl);
-        e.setStreamHandler(new PumpStreamHandler());
-        e.setProcessDestroyer(getProcessDestroyer());
-        e.execute(cl, h);
+        executor.setStreamHandler(new PumpStreamHandler());
+        executor.setProcessDestroyer(getProcessDestroyer());
+        executor.execute(cl, h);
     }
     
     /** Can be overridden to return a custom ProcessDestroyer */
     protected ProcessDestroyer getProcessDestroyer() {
         return new ShutdownHookProcessDestroyer();
     }
+    
+    /** Stop the process that we started, if any */
+    public void stop() {
+        if(executor == null) {
+            throw new IllegalStateException("Process not started, no Executor set");
+        }
+        final Object d = executor.getProcessDestroyer();
+        if(d instanceof Runnable) {
+            ((Runnable)d).run();
+            log.info("Process destroyed");
+        } else {
+            throw new IllegalStateException(d + " is not a Runnable, cannot destroy process");
+        }
+    }
 }

Modified: sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/serversetup/StartRunnableJarPhase.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/serversetup/StartRunnableJarPhase.java?rev=1232484&r1=1232483&r2=1232484&view=diff
==============================================================================
--- sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/serversetup/StartRunnableJarPhase.java
(original)
+++ sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/serversetup/StartRunnableJarPhase.java
Tue Jan 17 17:07:17 2012
@@ -87,4 +87,27 @@ public class StartRunnableJarPhase imple
     public String getId() {
         return id;
     }
+    
+    /** Return a SetupPhase that kills the process started by this phase */
+    public SetupPhase getKillPhase(final String id) {
+        return new SetupPhase() {
+            public void run(ServerSetup owner) throws Exception {
+                executor.stop();
+            }
+
+            public boolean isStartupPhase() {
+                // This is not a shutdown phase, it's meant to
+                // use during startup to forcibly kill an instance
+                return true;
+            }
+
+            public String getDescription() {
+                return "Kill the process started by " + StartRunnableJarPhase.this.getDescription();
+            }
+
+            public String getId() {
+                return id;
+            }
+        };
+    }
 }



Mime
View raw message