Skip to content

Commit

Permalink
Merge pull request #10551 from stuartwdouglas/remote-dev-improvements
Browse files Browse the repository at this point in the history
Remote dev mode improvements
  • Loading branch information
stuartwdouglas authored Jul 8, 2020
2 parents 0307360 + 7b5b6ab commit 3bcc8d9
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ private String doConnect(RemoteDevState initialState, Function<Set<String>, Map<
//this file needs to be sent last
//if it is modified it will trigger a reload
//and we need the rest of the app to be present
byte[] lastFile = data.remove(QuarkusEntryPoint.QUARKUS_APPLICATION_DAT);
byte[] lastFile = data.remove(QuarkusEntryPoint.LIB_DEPLOYMENT_DEPLOYMENT_CLASS_PATH_DAT);
if (lastFile != null) {
data.put(QuarkusEntryPoint.QUARKUS_APPLICATION_DAT, lastFile);
data.put(QuarkusEntryPoint.LIB_DEPLOYMENT_DEPLOYMENT_CLASS_PATH_DAT, lastFile);
}

for (Map.Entry<String, byte[]> entry : data.entrySet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public class VertxHttpRecorder {

private static volatile Handler<RoutingContext> hotReplacementHandler;
private static volatile HotReplacementContext hotReplacementContext;
private static volatile RemoteSyncHandler remoteSyncHandler;

private static volatile Runnable closeTask;

Expand All @@ -123,7 +124,14 @@ public void handle(HttpServerRequest httpServerRequest) {
//as the underlying handler has not had a chance to install a read handler yet
//and data that arrives while the blocking task is being processed will be lost
httpServerRequest.pause();
rootHandler.handle(httpServerRequest);
Handler<HttpServerRequest> rh = VertxHttpRecorder.rootHandler;
if (rh != null) {
rh.handle(httpServerRequest);
} else {
//very rare race condition, that can happen when dev mode is shutting down
httpServerRequest.resume();
httpServerRequest.response().setStatusCode(503).end();
}
}
};

Expand Down Expand Up @@ -374,7 +382,7 @@ public void handle(RoutingContext event) {
});
}
if (launchMode == LaunchMode.DEVELOPMENT && liveReloadConfig.password.isPresent()) {
root = new RemoteSyncHandler(liveReloadConfig.password.get(), root, hotReplacementContext);
root = remoteSyncHandler = new RemoteSyncHandler(liveReloadConfig.password.get(), root, hotReplacementContext);
}
rootHandler = root;
}
Expand Down Expand Up @@ -457,6 +465,10 @@ public void handle(AsyncResult<Void> event) {
}
}
closeTask = null;
if (remoteSyncHandler != null) {
remoteSyncHandler.close();
remoteSyncHandler = null;
}
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.Base64;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.RejectedExecutionException;

import org.jboss.logging.Logger;

Expand Down Expand Up @@ -142,6 +143,10 @@ public void run() {
}
event.response().end();
}
} catch (RejectedExecutionException e) {
//everything is shut down
//likely in the middle of a restart
event.connection().close();
} catch (Exception e) {
log.error("Connect failed", e);
event.response().setStatusCode(500).end();
Expand Down Expand Up @@ -234,4 +239,10 @@ private boolean checkSession(HttpServerRequest event) {
}
return false;
}

public void close() {
synchronized (RemoteSyncHandler.class) {
RemoteSyncHandler.class.notifyAll();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class DevModeMediator {

static void doDevMode(Path appRoot) throws IOException, ClassNotFoundException, IllegalAccessException,
InvocationTargetException, NoSuchMethodException {
Path deploymentClassPath = appRoot.resolve("lib/deployment/deployment-class-path.dat");
Path deploymentClassPath = appRoot.resolve(QuarkusEntryPoint.LIB_DEPLOYMENT_DEPLOYMENT_CLASS_PATH_DAT);
Closeable closeable = doStart(appRoot, deploymentClassPath);
Timer timer = new Timer("Classpath Change Timer", false);
timer.schedule(new ChangeDetector(appRoot, deploymentClassPath, closeable), 1000, 1000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
public class QuarkusEntryPoint {

public static final String QUARKUS_APPLICATION_DAT = "quarkus/quarkus-application.dat";
public static final String LIB_DEPLOYMENT_DEPLOYMENT_CLASS_PATH_DAT = "lib/deployment/deployment-class-path.dat";

public static void main(String... args) throws Throwable {
System.setProperty("java.util.logging.manager", org.jboss.logmanager.LogManager.class.getName());
Expand Down Expand Up @@ -52,7 +53,7 @@ private static void doRun(Object args) throws IOException, ClassNotFoundExceptio
private static void doReaugment(Path appRoot) throws IOException, ClassNotFoundException, IllegalAccessException,
InvocationTargetException, NoSuchMethodException {
try (ObjectInputStream in = new ObjectInputStream(
Files.newInputStream(appRoot.resolve("lib/deployment/deployment-class-path.dat")))) {
Files.newInputStream(appRoot.resolve(LIB_DEPLOYMENT_DEPLOYMENT_CLASS_PATH_DAT)))) {
List<String> paths = (List<String>) in.readObject();
//yuck, should use runner class loader
URLClassLoader loader = new URLClassLoader(paths.stream().map((s) -> {
Expand Down

0 comments on commit 3bcc8d9

Please sign in to comment.