From b91e03b91cd560703e9137b1dd07a5521b8919e1 Mon Sep 17 00:00:00 2001 From: Brian Clozel Date: Mon, 10 Apr 2017 12:23:54 +0200 Subject: [PATCH] Fix devtools support in NettyWebServer This commit improves the lifecycle of the `NettyWebServer` and allows multiple restarts when using devtools. Previously, the lifecycle was tailored for a single start/stop cycle. Fixes gh-8771 --- .../web/embedded/netty/NettyWebServer.java | 20 +++++-------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/spring-boot/src/main/java/org/springframework/boot/web/embedded/netty/NettyWebServer.java b/spring-boot/src/main/java/org/springframework/boot/web/embedded/netty/NettyWebServer.java index 052527155c..c67a5dd35d 100644 --- a/spring-boot/src/main/java/org/springframework/boot/web/embedded/netty/NettyWebServer.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/embedded/netty/NettyWebServer.java @@ -22,7 +22,6 @@ import java.util.concurrent.atomic.AtomicReference; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import reactor.core.Loopback; import reactor.ipc.netty.NettyContext; import reactor.ipc.netty.http.server.HttpServer; @@ -39,11 +38,11 @@ import org.springframework.http.server.reactive.ReactorHttpHandlerAdapter; * @author Madhura Bhave * @since 2.0.0 */ -public class NettyWebServer implements WebServer, Loopback { +public class NettyWebServer implements WebServer { private static final Log logger = LogFactory.getLog(NettyWebServer.class); - private static CountDownLatch latch = new CountDownLatch(1); + private CountDownLatch latch; private final ReactorHttpHandlerAdapter handlerAdapter; @@ -57,19 +56,10 @@ public class NettyWebServer implements WebServer, Loopback { this.handlerAdapter = handlerAdapter; } - @Override - public Object connectedInput() { - return this.reactorServer; - } - - @Override - public Object connectedOutput() { - return this.reactorServer; - } - @Override public void start() throws WebServerException { if (this.nettyContext.get() == null) { + this.latch = new CountDownLatch(1); try { this.nettyContext .set(this.reactorServer.newHandler(this.handlerAdapter).block()); @@ -102,7 +92,7 @@ public class NettyWebServer implements WebServer, Loopback { @Override public void run() { try { - NettyWebServer.latch.await(); + NettyWebServer.this.latch.await(); } catch (InterruptedException e) { } @@ -120,7 +110,7 @@ public class NettyWebServer implements WebServer, Loopback { if (context != null) { context.dispose(); } - latch.countDown(); + this.latch.countDown(); } @Override