diff --git a/extensions/vertx-core/runtime/src/main/java/io/quarkus/vertx/core/runtime/VertxCoreRecorder.java b/extensions/vertx-core/runtime/src/main/java/io/quarkus/vertx/core/runtime/VertxCoreRecorder.java index db2d882dcfe36..307d79263aec4 100644 --- a/extensions/vertx-core/runtime/src/main/java/io/quarkus/vertx/core/runtime/VertxCoreRecorder.java +++ b/extensions/vertx-core/runtime/src/main/java/io/quarkus/vertx/core/runtime/VertxCoreRecorder.java @@ -9,6 +9,7 @@ import java.io.File; import java.util.ArrayList; +import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -374,6 +375,11 @@ public Integer get() { }; } + public static Supplier recoverFailedStart(VertxConfiguration config) { + return vertx = new VertxSupplier(config, Collections.emptyList()); + + } + static class VertxSupplier implements Supplier { final VertxConfiguration config; final VertxOptionsCustomizer customizer; diff --git a/extensions/vertx-http/deployment/src/main/java/io/quarkus/vertx/http/deployment/devmode/HttpRemoteDevClient.java b/extensions/vertx-http/deployment/src/main/java/io/quarkus/vertx/http/deployment/devmode/HttpRemoteDevClient.java index b8ef26edd92d7..f92719f89bf02 100644 --- a/extensions/vertx-http/deployment/src/main/java/io/quarkus/vertx/http/deployment/devmode/HttpRemoteDevClient.java +++ b/extensions/vertx-http/deployment/src/main/java/io/quarkus/vertx/http/deployment/devmode/HttpRemoteDevClient.java @@ -65,6 +65,7 @@ private class Session implements Closeable, Runnable { private final Thread httpThread; private final String url; private final URL devUrl; + private final URL probeUrl; int errorCount; private Session(RemoteDevState initialState, @@ -74,6 +75,7 @@ private Session(RemoteDevState initialState, this.initialConnectFunction = initialConnectFunction; this.changeRequestFunction = changeRequestFunction; devUrl = new URL(HttpRemoteDevClient.this.url + RemoteSyncHandler.DEV); + probeUrl = new URL(HttpRemoteDevClient.this.url + RemoteSyncHandler.PROBE); url = HttpRemoteDevClient.this.url; httpThread = new Thread(this, "Remote dev client thread"); httpThread.start(); @@ -248,7 +250,9 @@ private String waitForRestart(RemoteDevState initialState, } while (System.currentTimeMillis() < timeout) { try { - HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection(); + HttpURLConnection connection = (HttpURLConnection) probeUrl.openConnection(); + connection.setRequestMethod("POST"); + connection.addRequestProperty(HttpHeaders.CONTENT_TYPE.toString(), RemoteSyncHandler.APPLICATION_QUARKUS); IoUtil.readBytes(connection.getInputStream()); return doConnect(initialState, initialConnectFunction); } catch (IOException e) { diff --git a/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/VertxHttpRecorder.java b/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/VertxHttpRecorder.java index 928dfac9a71f4..7f859ea199a70 100644 --- a/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/VertxHttpRecorder.java +++ b/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/VertxHttpRecorder.java @@ -173,7 +173,7 @@ public static void startServerAfterFailedStart() { if (supplier == null) { VertxConfiguration vertxConfiguration = new VertxConfiguration(); ConfigInstantiator.handleObject(vertxConfiguration); - vertx = VertxCoreRecorder.initialize(vertxConfiguration, null); + vertx = VertxCoreRecorder.recoverFailedStart(vertxConfiguration).get(); } else { vertx = supplier.get(); } @@ -187,7 +187,14 @@ public static void startServerAfterFailedStart() { if (hotReplacementHandler != null) { router.route().order(Integer.MIN_VALUE).blockingHandler(hotReplacementHandler); } - rootHandler = router; + Handler root = router; + LiveReloadConfig liveReloadConfig = new LiveReloadConfig(); + ConfigInstantiator.handleObject(liveReloadConfig); + if (liveReloadConfig.password.isPresent() + && hotReplacementContext.getDevModeType() == DevModeType.REMOTE_SERVER_SIDE) { + root = remoteSyncHandler = new RemoteSyncHandler(liveReloadConfig.password.get(), root, hotReplacementContext); + } + rootHandler = root; //we can't really do doServerStart(vertx, buildConfig, config, LaunchMode.DEVELOPMENT, new Supplier() { diff --git a/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/devmode/RemoteSyncHandler.java b/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/devmode/RemoteSyncHandler.java index 28db2f20e4f6a..0162e7edca482 100644 --- a/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/devmode/RemoteSyncHandler.java +++ b/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/devmode/RemoteSyncHandler.java @@ -14,9 +14,10 @@ import io.netty.handler.codec.http.HttpHeaderNames; import io.quarkus.dev.spi.HotReplacementContext; import io.quarkus.dev.spi.RemoteDevState; -import io.quarkus.runtime.ExecutorRecorder; import io.quarkus.runtime.util.HashUtil; +import io.quarkus.vertx.core.runtime.VertxCoreRecorder; import io.vertx.core.Handler; +import io.vertx.core.Promise; import io.vertx.core.buffer.Buffer; import io.vertx.core.http.HttpMethod; import io.vertx.core.http.HttpServerRequest; @@ -31,6 +32,7 @@ public class RemoteSyncHandler implements Handler { public static final String QUARKUS_SESSION_COUNT = "X-Quarkus-Count"; public static final String CONNECT = "/connect"; public static final String DEV = "/dev"; + public static final String PROBE = "/probe"; //used to check that the server is back up after restart final String password; final Handler next; @@ -77,12 +79,16 @@ public void handle(HttpServerRequest event) { final String type = event.headers().get(HttpHeaderNames.CONTENT_TYPE); if (APPLICATION_QUARKUS.equals(type)) { currentSessionTimeout = time + 60000; - ExecutorRecorder.getCurrent().execute(new Runnable() { + VertxCoreRecorder.getVertx().get().executeBlocking(new Handler>() { @Override - public void run() { - handleRequest(event); + public void handle(Promise promise) { + try { + handleRequest(event); + } finally { + promise.complete(); + } } - }); + }, null); return; } next.handle(event); @@ -98,6 +104,8 @@ private void handleRequest(HttpServerRequest event) { handleDev(event); } else if (event.path().equals(CONNECT)) { handleConnect(event); + } else if (event.path().equals(PROBE)) { + event.response().end(); } else { event.response().setStatusCode(404).end(); } @@ -114,9 +122,9 @@ public void handle(Buffer b) { if (checkSession(event, b.getBytes())) { return; } - ExecutorRecorder.getCurrent().execute(new Runnable() { + VertxCoreRecorder.getVertx().get().executeBlocking(new Handler>() { @Override - public void run() { + public void handle(Promise promise) { try { Throwable problem = (Throwable) new ObjectInputStream(new ByteArrayInputStream(b.getBytes())) .readObject(); @@ -144,10 +152,11 @@ public void run() { } catch (Exception e) { log.error("Connect failed", e); event.response().setStatusCode(500).end(); + } finally { + promise.complete(); } } - }); - + }, null); } }).exceptionHandler(new Handler() { @Override