You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomee.apache.org by Romain Manni-Bucau <rm...@gmail.com> on 2014/07/22 12:09:38 UTC

Fwd: svn commit: r1612520 - in /tomee/tomee/branches/tomee-1.7.x: container/openejb-core/src/main/java/org/apache/openejb/config/RemoteServer.java tck/ tck/tck-common/src/main/java/org/apache/openejb/tck/impl/ContainersImplTomEE.java

ProcessBuilder inheritIO is awesome but java 7 only so shouldn't be in 1.7
branch no?


Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau


---------- Forwarded message ----------
From: <an...@apache.org>
Date: 2014-07-22 11:40 GMT+02:00
Subject: svn commit: r1612520 - in /tomee/tomee/branches/tomee-1.7.x:
container/openejb-core/src/main/java/org/apache/openejb/config/RemoteServer.java
tck/
tck/tck-common/src/main/java/org/apache/openejb/tck/impl/ContainersImplTomEE.java
To: commits@tomee.apache.org


Author: andygumbrecht
Date: Tue Jul 22 09:40:25 2014
New Revision: 1612520

URL: http://svn.apache.org/r1612520
Log:
RemoteServer - Use ProcessBuilder
ContainersImplTomEE - Finals & format

Modified:

tomee/tomee/branches/tomee-1.7.x/container/openejb-core/src/main/java/org/apache/openejb/config/RemoteServer.java
    tomee/tomee/branches/tomee-1.7.x/tck/   (props changed)

tomee/tomee/branches/tomee-1.7.x/tck/tck-common/src/main/java/org/apache/openejb/tck/impl/ContainersImplTomEE.java

Modified:
tomee/tomee/branches/tomee-1.7.x/container/openejb-core/src/main/java/org/apache/openejb/config/RemoteServer.java
URL:
http://svn.apache.org/viewvc/tomee/tomee/branches/tomee-1.7.x/container/openejb-core/src/main/java/org/apache/openejb/config/RemoteServer.java?rev=1612520&r1=1612519&r2=1612520&view=diff
==============================================================================
---
tomee/tomee/branches/tomee-1.7.x/container/openejb-core/src/main/java/org/apache/openejb/config/RemoteServer.java
(original)
+++
tomee/tomee/branches/tomee-1.7.x/container/openejb-core/src/main/java/org/apache/openejb/config/RemoteServer.java
Tue Jul 22 09:40:25 2014
@@ -34,6 +34,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
+import java.util.concurrent.atomic.AtomicReference;

 /**
  * NOTE: don't add inner classes or anonymous one or dependency without
updating ExecMojo
@@ -64,7 +65,7 @@ public class RemoteServer {
     private boolean serverHasAlreadyBeenStarted = true;

     private Properties properties;
-    private Process server;
+    private final AtomicReference<Process> server = new
AtomicReference<Process>();
     private final int tries;
     private final boolean verbose;
     private final int portShutdown;
@@ -128,27 +129,14 @@ public class RemoteServer {

         stop();

-        if (server != null) {
-            final Process sp = server;
-            final Thread t = new Thread(new Runnable() {
-                @Override
-                public void run() {
-                    try {
-                        sp.waitFor();
-                    } catch (final InterruptedException e) {
-                        // no-op
-                    }
-                }
-            }, "RemoteServer-destroy");
-
-            t.start();
+        final Process p = server.get();
+        if (p != null) {
             try {
-                t.join(15000);
-            } catch (final InterruptedException e) {
-                //Ignore
-            } finally {
-                server.destroy();
+                p.waitFor();
+            } catch (final Throwable t) {
+                t.printStackTrace(System.err);
             }
+
         }
     }

@@ -340,14 +328,19 @@ public class RemoteServer {
                 }

                 // kill3UNIXDebug();
+                final ProcessBuilder pb = new
ProcessBuilder(args).inheritIO().directory(home.getAbsoluteFile());
+                Process p = pb.start();

-                final Process process = Runtime.getRuntime().exec(args);
-                Pipe.pipeOut(process); // why would we need to redirect
System.in to the process, TomEE doesn't use it
+                //Process p = Runtime.getRuntime().exec(args);
+                //Pipe.pipeOut(p); // why would we need to redirect
System.in to the process, TomEE doesn't use it

                 if (START.equals(cmd)) {
-                    server = process;
-                } else if (STOP.equals(cmd) && server != null) {
-                    server.waitFor();
+                    server.set(p);
+                } else if (STOP.equals(cmd)) {
+                    p.waitFor();
+                    p = server.get();
+                    if (p != null)
+                        p.waitFor();
                 }

             } catch (final Exception e) {
@@ -378,9 +371,9 @@ public class RemoteServer {
         }

         try {
-            final Field f = server.getClass().getDeclaredField("pid");
+            final Field f =
server.get().getClass().getDeclaredField("pid");
             f.setAccessible(true);
-            final int pid = (Integer) f.get(server);
+            final int pid = (Integer) f.get(server.get());
             Pipe.pipe(Runtime.getRuntime().exec("kill -3 " + pid));
         } catch (final Exception e1) {
             e1.printStackTrace();
@@ -428,7 +421,7 @@ public class RemoteServer {
     }

     public Process getServer() {
-        return server;
+        return server.get();
     }

     private void addIfSet(final List<String> argsList, final String key) {
@@ -553,10 +546,10 @@ public class RemoteServer {
     }

     public void killOnExit() {
-        if (!serverHasAlreadyBeenStarted && kill.contains(this.server)) {
+        if (!serverHasAlreadyBeenStarted &&
kill.contains(this.server.get())) {
             return;
         }
-        kill.add(this.server);
+        kill.add(this.server.get());
     }

     // Shutdown hook for recursive delete on tmp directories

Propchange: tomee/tomee/branches/tomee-1.7.x/tck/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Tue Jul 22 09:40:25 2014
@@ -7,3 +7,4 @@
 .settings
 out
 target
+.idea

Modified:
tomee/tomee/branches/tomee-1.7.x/tck/tck-common/src/main/java/org/apache/openejb/tck/impl/ContainersImplTomEE.java
URL:
http://svn.apache.org/viewvc/tomee/tomee/branches/tomee-1.7.x/tck/tck-common/src/main/java/org/apache/openejb/tck/impl/ContainersImplTomEE.java?rev=1612520&r1=1612519&r2=1612520&view=diff
==============================================================================
---
tomee/tomee/branches/tomee-1.7.x/tck/tck-common/src/main/java/org/apache/openejb/tck/impl/ContainersImplTomEE.java
(original)
+++
tomee/tomee/branches/tomee-1.7.x/tck/tck-common/src/main/java/org/apache/openejb/tck/impl/ContainersImplTomEE.java
Tue Jul 22 09:40:25 2014
@@ -44,31 +44,33 @@ public class ContainersImplTomEE extends
     private Exception exception;
     private AppInfo appInfo;
     private File currentFile = null;
-    private int port = Integer.getInteger("server.http.port", 8080);
+    private final int port = Integer.getInteger("server.http.port", 8080);

     private Deployer lookup() {
         final Options options = new Options(System.getProperties());
         final Properties props = new Properties();
         props.put(Context.INITIAL_CONTEXT_FACTORY,
RemoteInitialContextFactory.class.getName());
-        props.put(Context.PROVIDER_URL, options.get(Context.PROVIDER_URL,"
http://localhost:" + port + "/tomee/ejb"));
+        props.put(Context.PROVIDER_URL, options.get(Context.PROVIDER_URL, "
http://localhost:" + port + "/tomee/ejb"));

         final String deployerJndi =
System.getProperty("openejb.deployer.jndiname",
"openejb/DeployerBusinessRemote");

         try {
-            InitialContext context = new InitialContext(props);
+            final InitialContext context = new InitialContext(props);
             return (Deployer) context.lookup(deployerJndi);
-        } catch (Exception e) {
+        } catch (final Exception e) {
             throw new OpenEJBTCKRuntimeException(e);
         }
     }
+
     public ContainersImplTomEE() {
         System.out.println("ContainersImpl=" +
ContainersImplTomEE.class.getName());
         System.out.println("Initialized ContainersImplTomEE " + (++count));
         server = new RemoteServer();
         server.setPortStartup(this.port);
     }
+
     @Override
-    public boolean deploy(InputStream archive, String name) throws
IOException {
+    public boolean deploy(final InputStream archive, final String name)
throws IOException {
         exception = null;
         appInfo = null;

@@ -82,7 +84,7 @@ public class ContainersImplTomEE extends
                 deployer = lookup();
             }
             appInfo = deployer.deploy(currentFile.getAbsolutePath());
-        } catch (Exception ex) {
+        } catch (final Exception ex) {
             Exception e = ex;
             if (e.getCause() instanceof ValidationException) {
                 e = (Exception) e.getCause();
@@ -108,14 +110,14 @@ public class ContainersImplTomEE extends
     public DeploymentException getDeploymentException() {
         try {
             return (DeploymentException) exception;
-        } catch (Exception e) {
+        } catch (final Exception e) {
             System.out.println("BADCAST");
             return new DeploymentException("", exception);
         }
     }

     @Override
-    public void undeploy(String name) throws IOException {
+    public void undeploy(final String name) throws IOException {
         if (appInfo == null) {
             if (!(exception instanceof DeploymentException)) {
                 System.out.println("Nothing to undeploy" + name);
@@ -126,19 +128,19 @@ public class ContainersImplTomEE extends
         System.out.println("Undeploying " + name);
         try {
             deployer.undeploy(appInfo.path);
-        } catch (Exception e) {
+        } catch (final Exception e) {
             e.printStackTrace();
             throw new OpenEJBTCKRuntimeException(e);
         }

-        File toDelete;
+        final File toDelete;
         if (currentFile != null && (toDelete =
currentFile.getParentFile()).exists()) {
             System.out.println("deleting " + toDelete.getAbsolutePath());
             delete(toDelete);
         }
     }

-    protected File getFile(String name) {
+    protected File getFile(final String name) {
         final File dir = new File(tmpDir, Math.random() + "");
         if (!dir.exists() && !dir.mkdir()) {
             throw new RuntimeException("Failed to create directory: " +
dir);
@@ -152,6 +154,7 @@ public class ContainersImplTomEE extends
         System.out.println("Setup called");

 server.start(Arrays.asList("-Dopenejb.classloader.forced-load=org.apache.openejb.tck"),
"start", true);
     }
+
     @Override
     public void cleanup() throws IOException {
         System.out.println("Cleanup called");

Re: svn commit: r1612520 - in /tomee/tomee/branches/tomee-1.7.x: container/openejb-core/src/main/java/org/apache/openejb/config/RemoteServer.java tck/ tck/tck-common/src/main/java/org/apache/openejb/tck/impl/ContainersImplTomEE.java

Posted by Romain Manni-Bucau <rm...@gmail.com>.
opps sorry, didnt see you fixed it later



Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau


2014-07-22 12:09 GMT+02:00 Romain Manni-Bucau <rm...@gmail.com>:

> ProcessBuilder inheritIO is awesome but java 7 only so shouldn't be in 1.7
> branch no?
>
>
> Romain Manni-Bucau
> Twitter: @rmannibucau
> Blog: http://rmannibucau.wordpress.com/
> LinkedIn: http://fr.linkedin.com/in/rmannibucau
> Github: https://github.com/rmannibucau
>
>
> ---------- Forwarded message ----------
> From: <an...@apache.org>
> Date: 2014-07-22 11:40 GMT+02:00
> Subject: svn commit: r1612520 - in /tomee/tomee/branches/tomee-1.7.x:
> container/openejb-core/src/main/java/org/apache/openejb/config/RemoteServer.java
> tck/
> tck/tck-common/src/main/java/org/apache/openejb/tck/impl/ContainersImplTomEE.java
> To: commits@tomee.apache.org
>
>
> Author: andygumbrecht
> Date: Tue Jul 22 09:40:25 2014
> New Revision: 1612520
>
> URL: http://svn.apache.org/r1612520
> Log:
> RemoteServer - Use ProcessBuilder
> ContainersImplTomEE - Finals & format
>
> Modified:
>
> tomee/tomee/branches/tomee-1.7.x/container/openejb-core/src/main/java/org/apache/openejb/config/RemoteServer.java
>     tomee/tomee/branches/tomee-1.7.x/tck/   (props changed)
>
> tomee/tomee/branches/tomee-1.7.x/tck/tck-common/src/main/java/org/apache/openejb/tck/impl/ContainersImplTomEE.java
>
> Modified:
> tomee/tomee/branches/tomee-1.7.x/container/openejb-core/src/main/java/org/apache/openejb/config/RemoteServer.java
> URL:
> http://svn.apache.org/viewvc/tomee/tomee/branches/tomee-1.7.x/container/openejb-core/src/main/java/org/apache/openejb/config/RemoteServer.java?rev=1612520&r1=1612519&r2=1612520&view=diff
>
> ==============================================================================
> ---
> tomee/tomee/branches/tomee-1.7.x/container/openejb-core/src/main/java/org/apache/openejb/config/RemoteServer.java
> (original)
> +++
> tomee/tomee/branches/tomee-1.7.x/container/openejb-core/src/main/java/org/apache/openejb/config/RemoteServer.java
> Tue Jul 22 09:40:25 2014
> @@ -34,6 +34,7 @@ import java.util.HashMap;
>  import java.util.List;
>  import java.util.Map;
>  import java.util.Properties;
> +import java.util.concurrent.atomic.AtomicReference;
>
>  /**
>   * NOTE: don't add inner classes or anonymous one or dependency without
> updating ExecMojo
> @@ -64,7 +65,7 @@ public class RemoteServer {
>      private boolean serverHasAlreadyBeenStarted = true;
>
>      private Properties properties;
> -    private Process server;
> +    private final AtomicReference<Process> server = new
> AtomicReference<Process>();
>      private final int tries;
>      private final boolean verbose;
>      private final int portShutdown;
> @@ -128,27 +129,14 @@ public class RemoteServer {
>
>          stop();
>
> -        if (server != null) {
> -            final Process sp = server;
> -            final Thread t = new Thread(new Runnable() {
> -                @Override
> -                public void run() {
> -                    try {
> -                        sp.waitFor();
> -                    } catch (final InterruptedException e) {
> -                        // no-op
> -                    }
> -                }
> -            }, "RemoteServer-destroy");
> -
> -            t.start();
> +        final Process p = server.get();
> +        if (p != null) {
>              try {
> -                t.join(15000);
> -            } catch (final InterruptedException e) {
> -                //Ignore
> -            } finally {
> -                server.destroy();
> +                p.waitFor();
> +            } catch (final Throwable t) {
> +                t.printStackTrace(System.err);
>              }
> +
>          }
>      }
>
> @@ -340,14 +328,19 @@ public class RemoteServer {
>                  }
>
>                  // kill3UNIXDebug();
> +                final ProcessBuilder pb = new
> ProcessBuilder(args).inheritIO().directory(home.getAbsoluteFile());
> +                Process p = pb.start();
>
> -                final Process process = Runtime.getRuntime().exec(args);
> -                Pipe.pipeOut(process); // why would we need to redirect
> System.in to the process, TomEE doesn't use it
> +                //Process p = Runtime.getRuntime().exec(args);
> +                //Pipe.pipeOut(p); // why would we need to redirect
> System.in to the process, TomEE doesn't use it
>
>                  if (START.equals(cmd)) {
> -                    server = process;
> -                } else if (STOP.equals(cmd) && server != null) {
> -                    server.waitFor();
> +                    server.set(p);
> +                } else if (STOP.equals(cmd)) {
> +                    p.waitFor();
> +                    p = server.get();
> +                    if (p != null)
> +                        p.waitFor();
>                  }
>
>              } catch (final Exception e) {
> @@ -378,9 +371,9 @@ public class RemoteServer {
>          }
>
>          try {
> -            final Field f = server.getClass().getDeclaredField("pid");
> +            final Field f =
> server.get().getClass().getDeclaredField("pid");
>              f.setAccessible(true);
> -            final int pid = (Integer) f.get(server);
> +            final int pid = (Integer) f.get(server.get());
>              Pipe.pipe(Runtime.getRuntime().exec("kill -3 " + pid));
>          } catch (final Exception e1) {
>              e1.printStackTrace();
> @@ -428,7 +421,7 @@ public class RemoteServer {
>      }
>
>      public Process getServer() {
> -        return server;
> +        return server.get();
>      }
>
>      private void addIfSet(final List<String> argsList, final String key) {
> @@ -553,10 +546,10 @@ public class RemoteServer {
>      }
>
>      public void killOnExit() {
> -        if (!serverHasAlreadyBeenStarted && kill.contains(this.server)) {
> +        if (!serverHasAlreadyBeenStarted &&
> kill.contains(this.server.get())) {
>              return;
>          }
> -        kill.add(this.server);
> +        kill.add(this.server.get());
>      }
>
>      // Shutdown hook for recursive delete on tmp directories
>
> Propchange: tomee/tomee/branches/tomee-1.7.x/tck/
>
> ------------------------------------------------------------------------------
> --- svn:ignore (original)
> +++ svn:ignore Tue Jul 22 09:40:25 2014
> @@ -7,3 +7,4 @@
>  .settings
>  out
>  target
> +.idea
>
> Modified:
> tomee/tomee/branches/tomee-1.7.x/tck/tck-common/src/main/java/org/apache/openejb/tck/impl/ContainersImplTomEE.java
> URL:
> http://svn.apache.org/viewvc/tomee/tomee/branches/tomee-1.7.x/tck/tck-common/src/main/java/org/apache/openejb/tck/impl/ContainersImplTomEE.java?rev=1612520&r1=1612519&r2=1612520&view=diff
>
> ==============================================================================
> ---
> tomee/tomee/branches/tomee-1.7.x/tck/tck-common/src/main/java/org/apache/openejb/tck/impl/ContainersImplTomEE.java
> (original)
> +++
> tomee/tomee/branches/tomee-1.7.x/tck/tck-common/src/main/java/org/apache/openejb/tck/impl/ContainersImplTomEE.java
> Tue Jul 22 09:40:25 2014
> @@ -44,31 +44,33 @@ public class ContainersImplTomEE extends
>      private Exception exception;
>      private AppInfo appInfo;
>      private File currentFile = null;
> -    private int port = Integer.getInteger("server.http.port", 8080);
> +    private final int port = Integer.getInteger("server.http.port", 8080);
>
>      private Deployer lookup() {
>          final Options options = new Options(System.getProperties());
>          final Properties props = new Properties();
>          props.put(Context.INITIAL_CONTEXT_FACTORY,
> RemoteInitialContextFactory.class.getName());
> -        props.put(Context.PROVIDER_URL, options.get(Context.PROVIDER_URL,"
> http://localhost:" + port + "/tomee/ejb"));
> +        props.put(Context.PROVIDER_URL, options.get(Context.PROVIDER_URL,
> "http://localhost:" + port + "/tomee/ejb"));
>
>          final String deployerJndi =
> System.getProperty("openejb.deployer.jndiname",
> "openejb/DeployerBusinessRemote");
>
>          try {
> -            InitialContext context = new InitialContext(props);
> +            final InitialContext context = new InitialContext(props);
>              return (Deployer) context.lookup(deployerJndi);
> -        } catch (Exception e) {
> +        } catch (final Exception e) {
>              throw new OpenEJBTCKRuntimeException(e);
>          }
>      }
> +
>      public ContainersImplTomEE() {
>          System.out.println("ContainersImpl=" +
> ContainersImplTomEE.class.getName());
>          System.out.println("Initialized ContainersImplTomEE " +
> (++count));
>          server = new RemoteServer();
>          server.setPortStartup(this.port);
>      }
> +
>      @Override
> -    public boolean deploy(InputStream archive, String name) throws
> IOException {
> +    public boolean deploy(final InputStream archive, final String name)
> throws IOException {
>          exception = null;
>          appInfo = null;
>
> @@ -82,7 +84,7 @@ public class ContainersImplTomEE extends
>                  deployer = lookup();
>              }
>              appInfo = deployer.deploy(currentFile.getAbsolutePath());
> -        } catch (Exception ex) {
> +        } catch (final Exception ex) {
>              Exception e = ex;
>              if (e.getCause() instanceof ValidationException) {
>                  e = (Exception) e.getCause();
> @@ -108,14 +110,14 @@ public class ContainersImplTomEE extends
>      public DeploymentException getDeploymentException() {
>          try {
>              return (DeploymentException) exception;
> -        } catch (Exception e) {
> +        } catch (final Exception e) {
>              System.out.println("BADCAST");
>              return new DeploymentException("", exception);
>          }
>      }
>
>      @Override
> -    public void undeploy(String name) throws IOException {
> +    public void undeploy(final String name) throws IOException {
>          if (appInfo == null) {
>              if (!(exception instanceof DeploymentException)) {
>                  System.out.println("Nothing to undeploy" + name);
> @@ -126,19 +128,19 @@ public class ContainersImplTomEE extends
>          System.out.println("Undeploying " + name);
>          try {
>              deployer.undeploy(appInfo.path);
> -        } catch (Exception e) {
> +        } catch (final Exception e) {
>              e.printStackTrace();
>              throw new OpenEJBTCKRuntimeException(e);
>          }
>
> -        File toDelete;
> +        final File toDelete;
>          if (currentFile != null && (toDelete =
> currentFile.getParentFile()).exists()) {
>              System.out.println("deleting " + toDelete.getAbsolutePath());
>              delete(toDelete);
>          }
>      }
>
> -    protected File getFile(String name) {
> +    protected File getFile(final String name) {
>          final File dir = new File(tmpDir, Math.random() + "");
>          if (!dir.exists() && !dir.mkdir()) {
>              throw new RuntimeException("Failed to create directory: " +
> dir);
> @@ -152,6 +154,7 @@ public class ContainersImplTomEE extends
>          System.out.println("Setup called");
>
>  server.start(Arrays.asList("-Dopenejb.classloader.forced-load=org.apache.openejb.tck"),
> "start", true);
>      }
> +
>      @Override
>      public void cleanup() throws IOException {
>          System.out.println("Cleanup called");
>
>
>
>