tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dblev...@apache.org
Subject svn commit: r1405582 - /openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/RemoteServer.java
Date Sun, 04 Nov 2012 16:33:03 GMT
Author: dblevins
Date: Sun Nov  4 16:33:02 2012
New Revision: 1405582

URL: http://svn.apache.org/viewvc?rev=1405582&view=rev
Log:
TOMEE-518 - TomEE shutdown in tools done via Tomcat stop command
Use simple process.waitFor to wait for shutdown when possible
Install shutdown hook to still clean up process if VM exists before stop is reached

Modified:
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/RemoteServer.java

Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/RemoteServer.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/RemoteServer.java?rev=1405582&r1=1405581&r2=1405582&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/RemoteServer.java
(original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/RemoteServer.java
Sun Nov  4 16:33:02 2012
@@ -301,9 +301,14 @@ public class RemoteServer {
 
                 // kill3UNIXDebug();
 
-                server = Runtime.getRuntime().exec(args);
+                final Process process = Runtime.getRuntime().exec(args);
+                Pipe.pipe(process);
 
-                Pipe.pipe(server);
+                if ("start".equals(cmd)) {
+                    server = process;
+                } else if ("stop".equals(cmd)) {
+                    server.waitFor();
+                }
 
             } catch (Exception e) {
                 throw (RuntimeException) new OpenEJBRuntimeException("Cannot start the server.
 Exception: "+e.getClass().getName()+": "+e.getMessage()).initCause(e);
@@ -428,7 +433,7 @@ public class RemoteServer {
     public void stop() {
         if (!serverHasAlreadyBeenStarted) {
             try {
-                forceStop();
+                shutdown();
             } catch (Exception e) {
                 e.printStackTrace(System.err);
             }
@@ -526,4 +531,30 @@ public class RemoteServer {
     public void setAdditionalClasspath(final String additionalClasspath) {
         this.additionalClasspath = additionalClasspath;
     }
+
+    public void killOnExit() {
+        if (!serverHasAlreadyBeenStarted && kill.contains(this.server)) return;
+        kill.add(this.server);
+    }
+
+    // Shutdown hook for recursive delete on tmp directories
+    static final List<Process> kill = new ArrayList<Process>();
+
+    static {
+        Runtime.getRuntime().addShutdownHook(new Thread() {
+            @Override
+            public void run() {
+                for (Process server : kill) {
+                    try {
+                        if (server != null) {
+                            server.destroy();
+                            server.waitFor();
+                        }
+                    } catch (Throwable e) {
+                        //Ignore
+                    }
+                }
+            }
+        });
+    }
 }



Mime
View raw message