|
|
@ -16,9 +16,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
package org.springframework.boot.web.embedded.netty;
|
|
|
|
package org.springframework.boot.web.embedded.netty;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.net.BindException;
|
|
|
|
import java.util.concurrent.CountDownLatch;
|
|
|
|
import java.util.concurrent.CountDownLatch;
|
|
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
import reactor.core.Loopback;
|
|
|
|
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;
|
|
|
@ -33,10 +36,13 @@ import org.springframework.http.server.reactive.ReactorHttpHandlerAdapter;
|
|
|
|
* directly.
|
|
|
|
* directly.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @author Brian Clozel
|
|
|
|
* @author Brian Clozel
|
|
|
|
|
|
|
|
* @author Madhura Bhave
|
|
|
|
* @since 2.0.0
|
|
|
|
* @since 2.0.0
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public class NettyWebServer implements WebServer, Loopback {
|
|
|
|
public class NettyWebServer implements WebServer, Loopback {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final Log logger = LogFactory.getLog(NettyWebServer.class);
|
|
|
|
|
|
|
|
|
|
|
|
private static CountDownLatch latch = new CountDownLatch(1);
|
|
|
|
private static CountDownLatch latch = new CountDownLatch(1);
|
|
|
|
|
|
|
|
|
|
|
|
private final ReactorHttpHandlerAdapter handlerAdapter;
|
|
|
|
private final ReactorHttpHandlerAdapter handlerAdapter;
|
|
|
@ -64,12 +70,32 @@ public class NettyWebServer implements WebServer, Loopback {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void start() throws WebServerException {
|
|
|
|
public void start() throws WebServerException {
|
|
|
|
if (this.nettyContext.get() == null) {
|
|
|
|
if (this.nettyContext.get() == null) {
|
|
|
|
this.nettyContext
|
|
|
|
try {
|
|
|
|
.set(this.reactorServer.newHandler(this.handlerAdapter).block());
|
|
|
|
this.nettyContext
|
|
|
|
|
|
|
|
.set(this.reactorServer.newHandler(this.handlerAdapter).block());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (Exception ex) {
|
|
|
|
|
|
|
|
if (findBindException(ex) != null) {
|
|
|
|
|
|
|
|
// throw new PortInUseException();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new WebServerException("Unable to start Netty", ex);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
NettyWebServer.logger.info("Netty started on port(s): " + getPort());
|
|
|
|
startDaemonAwaitThread();
|
|
|
|
startDaemonAwaitThread();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private BindException findBindException(Exception ex) {
|
|
|
|
|
|
|
|
Throwable candidate = ex;
|
|
|
|
|
|
|
|
while (candidate != null) {
|
|
|
|
|
|
|
|
if (candidate instanceof BindException) {
|
|
|
|
|
|
|
|
return (BindException) candidate;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
candidate = candidate.getCause();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void startDaemonAwaitThread() {
|
|
|
|
private void startDaemonAwaitThread() {
|
|
|
|
Thread awaitThread = new Thread("server") {
|
|
|
|
Thread awaitThread = new Thread("server") {
|
|
|
|
|
|
|
|
|
|
|
|