From 6b8ac54ee1bdc0efa40ec0a762e0a4fba8f00efc Mon Sep 17 00:00:00 2001 From: Stuart Douglas Date: Wed, 6 Mar 2019 09:22:57 +0100 Subject: [PATCH] Don't start Undertow eagerly in hot deployment mode --- .../devmode/UndertowHotReplacementSetup.java | 20 +------------- .../runtime/UndertowDeploymentTemplate.java | 27 ++++++++++++------- 2 files changed, 18 insertions(+), 29 deletions(-) diff --git a/extensions/undertow/deployment/src/main/java/io/quarkus/undertow/deployment/devmode/UndertowHotReplacementSetup.java b/extensions/undertow/deployment/src/main/java/io/quarkus/undertow/deployment/devmode/UndertowHotReplacementSetup.java index 9b26487a77a6f..94add88cf0b3e 100644 --- a/extensions/undertow/deployment/src/main/java/io/quarkus/undertow/deployment/devmode/UndertowHotReplacementSetup.java +++ b/extensions/undertow/deployment/src/main/java/io/quarkus/undertow/deployment/devmode/UndertowHotReplacementSetup.java @@ -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; @@ -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() { diff --git a/extensions/undertow/runtime/src/main/java/io/quarkus/undertow/runtime/UndertowDeploymentTemplate.java b/extensions/undertow/runtime/src/main/java/io/quarkus/undertow/runtime/UndertowDeploymentTemplate.java index 6e87fd9820ab8..9387eadd08a74 100644 --- a/extensions/undertow/runtime/src/main/java/io/quarkus/undertow/runtime/UndertowDeploymentTemplate.java +++ b/extensions/undertow/runtime/src/main/java/io/quarkus/undertow/runtime/UndertowDeploymentTemplate.java @@ -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 createDeployment(String name, Set knownFile, Set knownDirectories, @@ -255,16 +256,18 @@ public RuntimeValue startUndertow(ShutdownContext shutdown, Deployment List 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 @@ -298,6 +301,10 @@ 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. *

@@ -305,7 +312,7 @@ public void run() { * 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);