Both HTTP launchers now provide a way to get to the HttpServer (after casting to Callable)
authorJaroslav Tulach <jaroslav.tulach@apidesign.org>
Sun, 05 May 2013 18:16:43 +0200
changeset 1076892dcb178737
parent 1071 2894b9a9dbfc
child 1077 e16926bd6ea1
Both HTTP launchers now provide a way to get to the HttpServer (after casting to Callable)
launcher/fx/src/main/java/org/apidesign/bck2brwsr/launcher/BaseHTTPLauncher.java
launcher/http/src/main/java/org/apidesign/bck2brwsr/launcher/Bck2BrwsrLauncher.java
     1.1 --- a/launcher/fx/src/main/java/org/apidesign/bck2brwsr/launcher/BaseHTTPLauncher.java	Tue Apr 30 16:40:16 2013 +0200
     1.2 +++ b/launcher/fx/src/main/java/org/apidesign/bck2brwsr/launcher/BaseHTTPLauncher.java	Sun May 05 18:16:43 2013 +0200
     1.3 @@ -35,6 +35,7 @@
     1.4  import java.util.List;
     1.5  import java.util.Set;
     1.6  import java.util.concurrent.BlockingQueue;
     1.7 +import java.util.concurrent.Callable;
     1.8  import java.util.concurrent.CountDownLatch;
     1.9  import java.util.concurrent.LinkedBlockingQueue;
    1.10  import java.util.concurrent.TimeUnit;
    1.11 @@ -55,7 +56,7 @@
    1.12   * Supports execution in native browser as well as Java's internal 
    1.13   * execution engine.
    1.14   */
    1.15 -abstract class BaseHTTPLauncher extends Launcher implements Closeable {
    1.16 +abstract class BaseHTTPLauncher extends Launcher implements Closeable, Callable<HttpServer> {
    1.17      private static final Logger LOG = Logger.getLogger(BaseHTTPLauncher.class.getName());
    1.18      private static final InvocationContext END = new InvocationContext(null, null, null);
    1.19      private final Set<ClassLoader> loaders = new LinkedHashSet<>();
    1.20 @@ -106,6 +107,7 @@
    1.21          String prefix = startpage.substring(0, last);
    1.22          String simpleName = startpage.substring(last);
    1.23          s.getServerConfiguration().addHttpHandler(new SubTree(resources, prefix), "/");
    1.24 +        server = s;
    1.25          try {
    1.26              launchServerAndBrwsr(s, simpleName);
    1.27          } catch (URISyntaxException | InterruptedException ex) {
    1.28 @@ -422,6 +424,11 @@
    1.29      }
    1.30  
    1.31      @Override
    1.32 +    public HttpServer call() throws Exception {
    1.33 +        return server;
    1.34 +    }
    1.35 +    
    1.36 +    @Override
    1.37      public void close() throws IOException {
    1.38          shutdown();
    1.39      }
     2.1 --- a/launcher/http/src/main/java/org/apidesign/bck2brwsr/launcher/Bck2BrwsrLauncher.java	Tue Apr 30 16:40:16 2013 +0200
     2.2 +++ b/launcher/http/src/main/java/org/apidesign/bck2brwsr/launcher/Bck2BrwsrLauncher.java	Sun May 05 18:16:43 2013 +0200
     2.3 @@ -35,6 +35,7 @@
     2.4  import java.util.List;
     2.5  import java.util.Set;
     2.6  import java.util.concurrent.BlockingQueue;
     2.7 +import java.util.concurrent.Callable;
     2.8  import java.util.concurrent.CountDownLatch;
     2.9  import java.util.concurrent.LinkedBlockingQueue;
    2.10  import java.util.concurrent.TimeUnit;
    2.11 @@ -56,7 +57,7 @@
    2.12   * Supports execution in native browser as well as Java's internal 
    2.13   * execution engine.
    2.14   */
    2.15 -final class Bck2BrwsrLauncher extends Launcher implements Closeable {
    2.16 +final class Bck2BrwsrLauncher extends Launcher implements Closeable, Callable<HttpServer> {
    2.17      private static final Logger LOG = Logger.getLogger(Bck2BrwsrLauncher.class.getName());
    2.18      private static final InvocationContext END = new InvocationContext(null, null, null);
    2.19      private final Set<ClassLoader> loaders = new LinkedHashSet<>();
    2.20 @@ -103,6 +104,7 @@
    2.21          String prefix = startpage.substring(0, last);
    2.22          String simpleName = startpage.substring(last);
    2.23          s.getServerConfiguration().addHttpHandler(new SubTree(resources, prefix), "/");
    2.24 +        server = s;
    2.25          try {
    2.26              launchServerAndBrwsr(s, simpleName);
    2.27          } catch (URISyntaxException | InterruptedException ex) {
    2.28 @@ -443,6 +445,11 @@
    2.29      }
    2.30  
    2.31      @Override
    2.32 +    public HttpServer call() throws Exception {
    2.33 +        return server;
    2.34 +    }
    2.35 +    
    2.36 +    @Override
    2.37      public void close() throws IOException {
    2.38          shutdown();
    2.39      }