refactor the command line executable launcher used in the test harness for running...
authorJim Procter <jprocter@issues.jalview.org>
Mon, 17 Sep 2018 08:43:41 +0000 (09:43 +0100)
committerJim Procter <jprocter@issues.jalview.org>
Mon, 17 Sep 2018 08:43:41 +0000 (09:43 +0100)
src/jalview/bin/Jalview.java
test/jalview/bin/CommandLineOperations.java

index adf3773..789deb2 100755 (executable)
@@ -186,7 +186,18 @@ public class Jalview
    */
   public static void main(String[] args)
   {
-    instance = new Jalview();
+    float ONE_MB = 1048576f;
+    Runtime runtime = Runtime.getRuntime();
+    float maxMemory = runtime.maxMemory() / ONE_MB;
+    if (maxMemory < 1024 * 15)
+    {
+      System.exit();
+    }
+
+    if (System.ge)
+    {
+      instance = new Jalview();
+    }
     instance.doMain(args);
   }
 
index d586dae..18ea312 100644 (file)
@@ -21,6 +21,7 @@
 package jalview.bin;
 
 import jalview.gui.JvOptionPane;
+import jalview.ws.utils.Worker;
 
 import java.io.BufferedReader;
 import java.io.File;
@@ -57,62 +58,6 @@ public class CommandLineOperations
 
   private ArrayList<String> successfulCMDs = new ArrayList<>();
 
-  /***
-   * from
-   * http://stackoverflow.com/questions/808276/how-to-add-a-timeout-value-when
-   * -using-javas-runtime-exec
-   * 
-   * @author jimp
-   * 
-   */
-  private static class Worker extends Thread
-  {
-    private final Process process;
-
-    private BufferedReader outputReader;
-
-    private BufferedReader errorReader;
-
-    private Integer exit;
-
-    private Worker(Process process)
-    {
-      this.process = process;
-    }
-
-    @Override
-    public void run()
-    {
-      try
-      {
-        exit = process.waitFor();
-      } catch (InterruptedException ignore)
-      {
-        return;
-      }
-    }
-
-    public BufferedReader getOutputReader()
-    {
-      return outputReader;
-    }
-
-    public void setOutputReader(BufferedReader outputReader)
-    {
-      this.outputReader = outputReader;
-    }
-
-    public BufferedReader getErrorReader()
-    {
-      return errorReader;
-    }
-
-    public void setErrorReader(BufferedReader errorReader)
-    {
-      this.errorReader = errorReader;
-    }
-  }
-
   private Worker jalviewDesktopRunner(boolean withAwt, String cmd,
           int timeout)
   {
@@ -196,11 +141,10 @@ public class CommandLineOperations
         break;
       }
     }
-    if (worker != null && worker.exit == null)
+    if (worker != null && worker.getExitValue() == null)
     {
-      worker.interrupt();
-      Thread.currentThread().interrupt();
-      worker.process.destroy();
+      worker.destroyProcess();
+
     }
   }
 
@@ -226,11 +170,9 @@ public class CommandLineOperations
     FileAssert.assertFile(file, "Didn't create an output" + type
             + " file.[" + harg + "]");
     FileAssert.assertMinLength(new File(fileName), expectedMinFileSize);
-    if (worker != null && worker.exit == null)
+    if (worker != null && worker.getExitValue() == null)
     {
-      worker.interrupt();
-      Thread.currentThread().interrupt();
-      worker.process.destroy();
+      worker.destroyProcess();
       Assert.fail("Jalview did not exit after "
               + type
               + " generation (try running test again to verify - timeout at "