Commit b91e03b9 authored by Brian Clozel's avatar Brian Clozel

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
parent 49c99810
...@@ -22,7 +22,6 @@ import java.util.concurrent.atomic.AtomicReference; ...@@ -22,7 +22,6 @@ import java.util.concurrent.atomic.AtomicReference;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import reactor.core.Loopback;
import reactor.ipc.netty.NettyContext; import reactor.ipc.netty.NettyContext;
import reactor.ipc.netty.http.server.HttpServer; import reactor.ipc.netty.http.server.HttpServer;
...@@ -39,11 +38,11 @@ import org.springframework.http.server.reactive.ReactorHttpHandlerAdapter; ...@@ -39,11 +38,11 @@ import org.springframework.http.server.reactive.ReactorHttpHandlerAdapter;
* @author Madhura Bhave * @author Madhura Bhave
* @since 2.0.0 * @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 final Log logger = LogFactory.getLog(NettyWebServer.class);
private static CountDownLatch latch = new CountDownLatch(1); private CountDownLatch latch;
private final ReactorHttpHandlerAdapter handlerAdapter; private final ReactorHttpHandlerAdapter handlerAdapter;
...@@ -57,19 +56,10 @@ public class NettyWebServer implements WebServer, Loopback { ...@@ -57,19 +56,10 @@ public class NettyWebServer implements WebServer, Loopback {
this.handlerAdapter = handlerAdapter; this.handlerAdapter = handlerAdapter;
} }
@Override
public Object connectedInput() {
return this.reactorServer;
}
@Override
public Object connectedOutput() {
return this.reactorServer;
}
@Override @Override
public void start() throws WebServerException { public void start() throws WebServerException {
if (this.nettyContext.get() == null) { if (this.nettyContext.get() == null) {
this.latch = new CountDownLatch(1);
try { try {
this.nettyContext this.nettyContext
.set(this.reactorServer.newHandler(this.handlerAdapter).block()); .set(this.reactorServer.newHandler(this.handlerAdapter).block());
...@@ -102,7 +92,7 @@ public class NettyWebServer implements WebServer, Loopback { ...@@ -102,7 +92,7 @@ public class NettyWebServer implements WebServer, Loopback {
@Override @Override
public void run() { public void run() {
try { try {
NettyWebServer.latch.await(); NettyWebServer.this.latch.await();
} }
catch (InterruptedException e) { catch (InterruptedException e) {
} }
...@@ -120,7 +110,7 @@ public class NettyWebServer implements WebServer, Loopback { ...@@ -120,7 +110,7 @@ public class NettyWebServer implements WebServer, Loopback {
if (context != null) { if (context != null) {
context.dispose(); context.dispose();
} }
latch.countDown(); this.latch.countDown();
} }
@Override @Override
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment