Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve pom.xml changes in remote dev mode #12969

Merged
merged 1 commit into from
Oct 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -374,6 +375,11 @@ public Integer get() {
};
}

public static Supplier<Vertx> recoverFailedStart(VertxConfiguration config) {
return vertx = new VertxSupplier(config, Collections.emptyList());

}

static class VertxSupplier implements Supplier<Vertx> {
final VertxConfiguration config;
final VertxOptionsCustomizer customizer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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();
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -187,7 +187,14 @@ public static void startServerAfterFailedStart() {
if (hotReplacementHandler != null) {
router.route().order(Integer.MIN_VALUE).blockingHandler(hotReplacementHandler);
}
rootHandler = router;
Handler<HttpServerRequest> 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<Integer>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,6 +32,7 @@ public class RemoteSyncHandler implements Handler<HttpServerRequest> {
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<HttpServerRequest> next;
Expand Down Expand Up @@ -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<Promise<Object>>() {
@Override
public void run() {
handleRequest(event);
public void handle(Promise<Object> promise) {
try {
handleRequest(event);
} finally {
promise.complete();
}
}
});
}, null);
return;
}
next.handle(event);
Expand All @@ -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();
}
Expand All @@ -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<Promise<Object>>() {
@Override
public void run() {
public void handle(Promise<Object> promise) {
try {
Throwable problem = (Throwable) new ObjectInputStream(new ByteArrayInputStream(b.getBytes()))
.readObject();
Expand Down Expand Up @@ -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<Throwable>() {
@Override
Expand Down