Skip to content

Commit

Permalink
Don't start Undertow eagerly in hot deployment mode
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartwdouglas committed Mar 6, 2019
1 parent f9673b4 commit 6b8ac54
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
package io.quarkus.undertow.deployment.devmode;

import java.util.OptionalInt;

import javax.servlet.ServletException;

import io.quarkus.deployment.QuarkusConfig;
import io.quarkus.deployment.devmode.HotReplacementContext;
import io.quarkus.deployment.devmode.HotReplacementSetup;
import io.quarkus.runtime.LaunchMode;
import io.quarkus.undertow.runtime.HttpConfig;
import io.quarkus.undertow.runtime.UndertowDeploymentTemplate;
import io.undertow.server.HandlerWrapper;
import io.undertow.server.HttpHandler;
Expand All @@ -25,18 +18,7 @@ public class UndertowHotReplacementSetup implements HotReplacementSetup {
public void setupHotDeployment(HotReplacementContext context) {
this.context = context;
HandlerWrapper wrapper = createHandlerWrapper();
//TODO: we need to get these values from the config in runtime mode
HttpConfig config = new HttpConfig();
config.port = QuarkusConfig.getInt("quarkus.http.port", "8080");
config.host = QuarkusConfig.getString("quarkus.http.host", "localhost", true);
config.ioThreads = OptionalInt.empty();
config.workerThreads = OptionalInt.empty();

try {
UndertowDeploymentTemplate.startUndertowEagerly(config, wrapper, LaunchMode.DEVELOPMENT);
} catch (ServletException e) {
throw new RuntimeException(e);
}
UndertowDeploymentTemplate.setHotDeployment(wrapper);
}

private HandlerWrapper createHandlerWrapper() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public void handleRequest(HttpServerExchange exchange) throws Exception {
private static final String RESOURCES_PROP = "quarkus.undertow.resources";

private static volatile Undertow undertow;
private static volatile HandlerWrapper hotDeploymentWrapper;
private static volatile HttpHandler currentRoot = ResponseCodeHandler.HANDLE_404;

public RuntimeValue<DeploymentInfo> createDeployment(String name, Set<String> knownFile, Set<String> knownDirectories,
Expand Down Expand Up @@ -255,16 +256,18 @@ public RuntimeValue<Undertow> startUndertow(ShutdownContext shutdown, Deployment
List<HandlerWrapper> wrappers, LaunchMode launchMode) throws ServletException {

if (undertow == null) {
startUndertowEagerly(config, null, launchMode);
doServerStart(config, launchMode);

//in development mode undertow is started eagerly
shutdown.addShutdownTask(new Runnable() {
@Override
public void run() {
undertow.stop();
undertow = null;
}
});
if (launchMode != LaunchMode.DEVELOPMENT) {
//in development mode undertow should not be shut down
shutdown.addShutdownTask(new Runnable() {
@Override
public void run() {
undertow.stop();
undertow = null;
}
});
}
}
shutdown.addShutdownTask(new Runnable() {
@Override
Expand Down Expand Up @@ -298,14 +301,18 @@ public void run() {
return new RuntimeValue<>(undertow);
}

public static void setHotDeployment(HandlerWrapper handlerWrapper) {
hotDeploymentWrapper = handlerWrapper;
}

/**
* Used for quarkus:run, where we want undertow to start very early in the process.
* <p>
* This enables recovery from errors on boot. In a normal boot undertow is one of the last things start, so there would
* be no chance to use hot deployment to fix the error. In development mode we start Undertow early, so any error
* on boot can be corrected via the hot deployment handler
*/
public static void startUndertowEagerly(HttpConfig config, HandlerWrapper hotDeploymentWrapper, LaunchMode launchMode)
private static void doServerStart(HttpConfig config, LaunchMode launchMode)
throws ServletException {
if (undertow == null) {
int port = config.determinePort(launchMode);
Expand Down

0 comments on commit 6b8ac54

Please sign in to comment.