use of akka.http.javadsl.settings.WebSocketSettings in project mantis by Netflix.
the class JobStatusRouteTest method testJobStatus.
// @Test
// @Ignore
public void testJobStatus() throws InterruptedException {
Flow<Message, Message, NotUsed> clientFlow = Flow.fromSinkAndSource(Sink.foreach(x -> System.out.println("client got " + x.asTextMessage().getStrictText())), Source.empty());
ClientConnectionSettings defaultSettings = ClientConnectionSettings.create(system);
AtomicInteger pingCounter = new AtomicInteger();
WebSocketSettings customWebsocketSettings = defaultSettings.getWebsocketSettings().withPeriodicKeepAliveData(() -> ByteString.fromString(String.format("debug-%d", pingCounter.incrementAndGet())));
ClientConnectionSettings customSettings = defaultSettings.withWebsocketSettings(customWebsocketSettings);
http.singleWebSocketRequest(WebSocketRequest.create("ws://127.0.0.1:8207/job/status/sine-function-1"), clientFlow, ConnectionContext.noEncryption(), Optional.empty(), customSettings, system.log(), materializer);
while (pingCounter.get() != 2) {
statusEventBrokerActor.tell(new LifecycleEventsProto.WorkerStatusEvent(LifecycleEventsProto.StatusEvent.StatusEventType.INFO, "test message", 1, WorkerId.fromId("sine-function-1-worker-0-2").get(), WorkerState.Started), ActorRef.noSender());
Thread.sleep(2000);
}
}
use of akka.http.javadsl.settings.WebSocketSettings 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