Skip to content

Commit

Permalink
Fail deployment when unable to create the vertx httpServer
Browse files Browse the repository at this point in the history
Fixes: #4124
  • Loading branch information
geoand committed Sep 20, 2019
1 parent 89db6fc commit 0963fc4
Showing 1 changed file with 30 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -375,24 +375,15 @@ public WebDeploymentVerticle(int port, int httpsPort, String host, HttpServerOpt
@Override
public void start(Future<Void> startFuture) throws Exception {
final AtomicInteger remainingCount = new AtomicInteger(httpsOptions != null ? 2 : 1);
final HttpServerStartHandler httpServerStartHandler = new HttpServerStartHandler(startFuture, httpOptions,
remainingCount);
httpServer = vertx.createHttpServer(httpOptions);
httpServer.requestHandler(router);
httpServer.listen(port, host, event -> {
// Port may be random, so set the actual port
httpOptions.setPort(event.result().actualPort());
if (remainingCount.decrementAndGet() == 0) {
startFuture.complete();
}
});
httpServer.listen(port, host, httpServerStartHandler);
if (httpsOptions != null) {
httpsServer = vertx.createHttpServer(httpsOptions);
httpsServer.requestHandler(router);
httpsServer.listen(httpsPort, host, event -> {
httpsOptions.setPort(event.result().actualPort());
if (remainingCount.decrementAndGet() == 0) {
startFuture.complete();
}
});
httpsServer.listen(httpsPort, host, httpServerStartHandler);
}
}

Expand Down Expand Up @@ -467,4 +458,30 @@ public void initChannel(VirtualChannel ch) throws Exception {
public static Router getRouter() {
return router;
}

private static class HttpServerStartHandler implements Handler<AsyncResult<HttpServer>> {

private final Future<Void> startFuture;
private final HttpServerOptions httpOptions;
private final AtomicInteger remainingCount;

public HttpServerStartHandler(Future<Void> startFuture, HttpServerOptions httpOptions, AtomicInteger remainingCount) {
this.startFuture = startFuture;
this.httpOptions = httpOptions;
this.remainingCount = remainingCount;
}

@Override
public void handle(AsyncResult<HttpServer> event) {
if (event.cause() != null) {
startFuture.fail(event.cause());
} else {
// Port may be random, so set the actual port
httpOptions.setPort(event.result().actualPort());
if (remainingCount.decrementAndGet() == 0) {
startFuture.complete();
}
}
}
}
}

0 comments on commit 0963fc4

Please sign in to comment.