1.1 --- a/launcher/fx/src/main/java/org/apidesign/bck2brwsr/launcher/BaseHTTPLauncher.java Wed May 27 22:47:26 2015 +0200
1.2 +++ b/launcher/fx/src/main/java/org/apidesign/bck2brwsr/launcher/BaseHTTPLauncher.java Sat Dec 26 08:22:59 2015 +0100
1.3 @@ -21,6 +21,7 @@
1.4 import java.io.ByteArrayOutputStream;
1.5 import java.io.Closeable;
1.6 import java.io.File;
1.7 +import java.io.Flushable;
1.8 import java.io.IOException;
1.9 import java.io.InputStream;
1.10 import java.io.InterruptedIOException;
1.11 @@ -73,7 +74,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, Callable<HttpServer> {
1.16 +abstract class BaseHTTPLauncher extends Launcher implements Flushable, Closeable, Callable<HttpServer> {
1.17 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<ClassLoader>();
1.20 @@ -84,6 +85,7 @@
1.21 private Object[] brwsr;
1.22 private HttpServer server;
1.23 private CountDownLatch wait;
1.24 + private Thread flushing;
1.25
1.26 public BaseHTTPLauncher(String cmd) {
1.27 this.cmd = cmd;
1.28 @@ -418,6 +420,12 @@
1.29
1.30 @Override
1.31 public void shutdown() throws IOException {
1.32 + synchronized (this) {
1.33 + if (flushing != null) {
1.34 + flushing.interrupt();
1.35 + flushing = null;
1.36 + }
1.37 + }
1.38 methods.offer(END);
1.39 for (;;) {
1.40 int prev = methods.size();
1.41 @@ -547,6 +555,18 @@
1.42 }
1.43
1.44 @Override
1.45 + public synchronized void flush() throws IOException {
1.46 + flushing = Thread.currentThread();
1.47 + while (flushing == Thread.currentThread()) {
1.48 + try {
1.49 + wait();
1.50 + } catch (InterruptedException ex) {
1.51 + LOG.log(Level.FINE, null, ex);
1.52 + }
1.53 + }
1.54 + }
1.55 +
1.56 + @Override
1.57 public void close() throws IOException {
1.58 shutdown();
1.59 }
1.60 @@ -776,6 +796,10 @@
1.61
1.62 @Override
1.63 public void service(Request request, Response response) throws Exception {
1.64 + if ("true".equals(request.getParameter("exit"))) {
1.65 + LOG.info("Exit request received. Shutting down!");
1.66 + shutdown();
1.67 + }
1.68 if (request.getRequestURI().equals(vmResource)) {
1.69 response.setCharacterEncoding("UTF-8");
1.70 response.setContentType("text/javascript");