use of akka.http.javadsl.settings.ServerSettings in project mantis by Netflix.
the class MasterApiAkkaService method startAPIServer.
private void startAPIServer() {
final Flow<HttpRequest, HttpResponse, NotUsed> routeFlow = this.mantisMasterRoute.createRoute().flow(system, materializer);
final Http http = Http.get(system);
ServerSettings defaultSettings = ServerSettings.create(system);
java.time.Duration idleTimeout = system.settings().config().getDuration("akka.http.server.idle-timeout");
logger.info("idle timeout {} sec ", idleTimeout.getSeconds());
WebSocketSettings customWebsocketSettings = defaultSettings.getWebsocketSettings().withPeriodicKeepAliveMaxIdle(Duration.create(idleTimeout.getSeconds() - 1, TimeUnit.SECONDS)).withPeriodicKeepAliveMode("pong");
ServerSettings customServerSettings = defaultSettings.withWebsocketSettings(customWebsocketSettings);
final CompletionStage<ServerBinding> binding = http.bindAndHandle(routeFlow, ConnectHttp.toHost("0.0.0.0", port), customServerSettings, system.log(), materializer);
binding.exceptionally(failure -> {
System.err.println("API service exited, committing suicide !" + failure.getMessage());
logger.info("Master API service exited in error, committing suicide !");
system.terminate();
System.exit(2);
return null;
});
logger.info("Starting Mantis Master API on port {}", port);
try {
serviceLatch.await();
} catch (InterruptedException e) {
logger.error("Master API thread interrupted, committing suicide", e);
System.exit(2);
}
binding.thenCompose(// trigger unbinding from the port
ServerBinding::unbind).thenAccept(unbound -> {
logger.error("Master API service unbind, committing suicide");
system.terminate();
System.exit(2);
});
// and shutdown when done
}
Aggregations