Propagate the exit code to Mojo
authorJaroslav Tulach <jaroslav.tulach@apidesign.org>
Wed, 27 Apr 2016 06:38:18 +0200
changeset 19485b127bc8163e
parent 1947 12a252145892
child 1949 72ef454e3987
Propagate the exit code to Mojo
launcher/fx/src/main/java/org/apidesign/bck2brwsr/launcher/BaseHTTPLauncher.java
     1.1 --- a/launcher/fx/src/main/java/org/apidesign/bck2brwsr/launcher/BaseHTTPLauncher.java	Wed Apr 27 06:14:49 2016 +0200
     1.2 +++ b/launcher/fx/src/main/java/org/apidesign/bck2brwsr/launcher/BaseHTTPLauncher.java	Wed Apr 27 06:38:18 2016 +0200
     1.3 @@ -88,6 +88,7 @@
     1.4      private CountDownLatch wait;
     1.5      private Thread flushing;
     1.6      private String rootPage;
     1.7 +    private int exitCode;
     1.8  
     1.9      public BaseHTTPLauncher(String cmd) {
    1.10          this.cmd = cmd;
    1.11 @@ -463,7 +464,11 @@
    1.12  
    1.13      @Override
    1.14      public void shutdown() throws IOException {
    1.15 +        shutdown(0);
    1.16 +    }
    1.17 +    private void shutdown(int exitCode) throws IOException {
    1.18          synchronized (this) {
    1.19 +            this.exitCode = exitCode;
    1.20              if (flushing != null) {
    1.21                  flushing.interrupt();
    1.22                  flushing = null;
    1.23 @@ -607,6 +612,9 @@
    1.24                  LOG.log(Level.FINE, null, ex);
    1.25              }
    1.26          }
    1.27 +        if (exitCode != 0) {
    1.28 +            throw new IOException("Browser closed with exit code " + exitCode);
    1.29 +        }
    1.30      }
    1.31  
    1.32      @Override
    1.33 @@ -902,7 +910,7 @@
    1.34          public void service(Request request, Response response) throws Exception {
    1.35              final String exit = request.getParameter("exit");
    1.36              if (exit != null) {
    1.37 -                int exitCode = -1;
    1.38 +                int exitCode;
    1.39                  try {
    1.40                      exitCode = Integer.parseInt(exit);
    1.41                  } catch (NumberFormatException ex) {
    1.42 @@ -910,8 +918,7 @@
    1.43                  }
    1.44                  if (exitCode != -1) {
    1.45                      LOG.info("Exit request received. Shutting down!");
    1.46 -                    shutdown();
    1.47 -                    System.exit(exitCode);
    1.48 +                    shutdown(exitCode);
    1.49                  }
    1.50              }
    1.51              if (request.getRequestURI().equals(vmResource)) {