Search in sources :

Example 1 with ServerSettings

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
}
Also used : HttpRequest(akka.http.javadsl.model.HttpRequest) ServerSettings(akka.http.javadsl.settings.ServerSettings) HttpResponse(akka.http.javadsl.model.HttpResponse) Http(akka.http.javadsl.Http) ConnectHttp(akka.http.javadsl.ConnectHttp) WebSocketSettings(akka.http.javadsl.settings.WebSocketSettings) NotUsed(akka.NotUsed) ServerBinding(akka.http.javadsl.ServerBinding)

Aggregations

NotUsed (akka.NotUsed)1 ConnectHttp (akka.http.javadsl.ConnectHttp)1 Http (akka.http.javadsl.Http)1 ServerBinding (akka.http.javadsl.ServerBinding)1 HttpRequest (akka.http.javadsl.model.HttpRequest)1 HttpResponse (akka.http.javadsl.model.HttpResponse)1 ServerSettings (akka.http.javadsl.settings.ServerSettings)1 WebSocketSettings (akka.http.javadsl.settings.WebSocketSettings)1