You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2012/10/01 18:47:13 UTC
svn commit: r1392438 - in /openejb/trunk/openejb:
arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java
container/openejb-core/src/main/java/org/apache/openejb/config/RemoteServer.java
Author: rmannibucau
Date: Mon Oct 1 16:47:13 2012
New Revision: 1392438
URL: http://svn.apache.org/viewvc?rev=1392438&view=rev
Log:
TOMEE-441 tomee shutdown with arquillian remote adapter
Modified:
openejb/trunk/openejb/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/RemoteServer.java
Modified: openejb/trunk/openejb/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java?rev=1392438&r1=1392437&r2=1392438&view=diff
==============================================================================
--- openejb/trunk/openejb/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java (original)
+++ openejb/trunk/openejb/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java Mon Oct 1 16:47:13 2012
@@ -48,6 +48,7 @@ import javax.naming.NamingException;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
+import java.lang.Character;
import java.net.Socket;
import java.util.ArrayList;
import java.util.Collection;
@@ -201,7 +202,7 @@ public abstract class TomEEContainer<Con
try {
Socket socket = new Socket(configuration.getStopHost(), configuration.getStopPort());
OutputStream out = socket.getOutputStream();
- out.write(configuration.getStopCommand().getBytes());
+ out.write(configuration.getStopCommand().getBytes() + Character.toString((char) 0));
waitForShutdown(socket, 10);
} catch (Exception e) {
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=1392438&r1=1392437&r2=1392438&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 Mon Oct 1 16:47:13 2012
@@ -281,7 +281,7 @@ public class RemoteServer {
} else {
argsList.add(cmd);
}
-
+
args = argsList.toArray(new String[argsList.size()]);
}
@@ -421,21 +421,10 @@ public class RemoteServer {
System.out.println("[] STOP SERVER");
}
- String fcommand = command + Character.toString((char) 0); // SHUTDOWN + EOF
-
- Socket socket = null;
- try {
- socket= new Socket(host, shutdownPort);
- OutputStream out = socket.getOutputStream();
- out.write(fcommand.getBytes());
- } finally {
- if (socket != null) {
- socket.close();
- }
- }
+ shutdown();
if (server != null) {
- processKiller = new ProcessKillerThread(server);
+ processKiller = new ProcessKillerThread();
processKiller.start();
server.waitFor();
processKiller.interrupt();
@@ -454,6 +443,22 @@ public class RemoteServer {
}
}
+ private void shutdown() throws Exception {
+ String fcommand = command + Character.toString((char) 0); // SHUTDOWN + EOF
+
+ Socket socket = null;
+ try {
+ socket= new Socket(host, shutdownPort);
+ OutputStream out = socket.getOutputStream();
+ out.write(fcommand.getBytes());
+ out.flush();
+ } finally {
+ if (socket != null) {
+ socket.close();
+ }
+ }
+ }
+
private boolean connect() {
return connect(1);
}
@@ -491,26 +496,38 @@ public class RemoteServer {
return true;
}
- public static class ProcessKillerThread extends Thread {
- private final Process process;
-
- public ProcessKillerThread(final Process server) {
- process = server;
- }
+ public class ProcessKillerThread extends Thread {
+ private static final int MAX_TRIES = 10;
+ private static final int SLEEP_INC = 500;
@Override
public void run() {
+ long sleep = 0; // recall immediately shutdown (win issue)
+ int tries = MAX_TRIES;
try {
- Thread.sleep(5000); // TODO: configure it
- process.exitValue();
+ Thread.sleep(sleep);
+ sleep += SLEEP_INC;
+ if (server != null) {
+ server.exitValue();
+ }
} catch (IllegalThreadStateException itse) {
- // not yet terminated, kill
- System.err.println("Killing process " + process + " because after 5mn it is still running");
- process.destroy();
- try {
- process.waitFor();
- } catch (InterruptedException e) {
- // no-op
+ tries--;
+ if (tries == 0) {
+ if (server != null) {
+ // not yet terminated, kill
+ server.destroy();
+ try {
+ server.waitFor();
+ } catch (InterruptedException e) {
+ // no-op
+ }
+ }
+ } else { // under windows we sometimes need to send shutdown multiple times
+ try {
+ shutdown();
+ } catch (Exception e) {
+ // no-op
+ }
}
} catch (InterruptedException e) {
// no-op