@Override public Removable addUpstream(Source<Object, NotUsed> publisher) { UniqueKillSwitch killSwitch = publisher.viaMat(busFlow, Keep.right()) .to(Sink.ignore()) .run(mat); subscriptions.put(publisher, killSwitch); return () -> AkkaHubProxy.this.removeUpstream(publisher); }
private GraphActor(final BiFunction<ActorContext, DiagnosticLoggingAdapter, Graph<SinkShape<WithSender>, NotUsed>> graphCreator) { materializer = ActorMaterializer.create(getContext()); messageHandler = MergeHub.of(WithSender.class).to(graphCreator.apply(getContext(), log)).run(materializer); }
private GraphActor(final BiFunction<ActorContext, DiagnosticLoggingAdapter, Graph<SinkShape<WithSender>, NotUsed>> graphCreator) { materializer = ActorMaterializer.create(getContext()); messageHandler = MergeHub.of(WithSender.class).to(graphCreator.apply(getContext(), log)).run(materializer); }
private GraphActor(final Function<ActorContext, Graph<SinkShape<WithSender>, NotUsed>> graphCreator) { materializer = ActorMaterializer.create(getContext()); messageHandler = MergeHub.of(WithSender.class).to(graphCreator.apply(getContext())).run(materializer); }
private GraphActor(final Function<ActorContext, Graph<SinkShape<WithSender>, NotUsed>> graphCreator) { materializer = ActorMaterializer.create(getContext()); messageHandler = MergeHub.of(WithSender.class).to(graphCreator.apply(getContext())).run(materializer); }
@Override public void emit(Object event) { Source.single(event).viaMat(busFlow, Keep.right()) .to(Sink.ignore()) .run(mat); }
private Route handleDevOpsPerRequest(final RequestContext ctx, final Source<ByteString, ?> payloadSource, final Function<String, DevOpsCommand> requestJsonToCommandFunction) { final CompletableFuture<HttpResponse> httpResponseFuture = new CompletableFuture<>(); payloadSource .fold(ByteString.empty(), ByteString::concat) .map(ByteString::utf8String) .map(requestJsonToCommandFunction) .to(Sink.actorRef(createHttpPerRequestActor(ctx, httpResponseFuture), HttpRequestActor.COMPLETE_MESSAGE)) .run(materializer); return completeWithFuture(httpResponseFuture); }
private Route handleMessage(final RequestContext ctx, final Source<ByteString, Object> payloadSource, final Function<ByteBuffer, MessageCommand<?, ?>> requestPayloadToCommandFunction) { final CompletableFuture<HttpResponse> httpResponseFuture = new CompletableFuture<>(); payloadSource.fold(ByteString.empty(), ByteString::concat) .map(ByteString::toArray) .map(ByteBuffer::wrap) .map(requestPayloadToCommandFunction) .to(Sink.actorRef(createHttpPerRequestActor(ctx, httpResponseFuture), HttpRequestActor.COMPLETE_MESSAGE)) .run(materializer); return completeWithFuture(preprocessResponse(httpResponseFuture)); }
private Route handleSudoCountThingsPerRequest(final RequestContext ctx, final SudoCountThings command) { final CompletableFuture<HttpResponse> httpResponseFuture = new CompletableFuture<>(); Source.single(command) .to(Sink.actorRef(createHttpPerRequestActor(ctx, httpResponseFuture), HttpRequestActor.COMPLETE_MESSAGE)) .run(materializer); final CompletionStage<HttpResponse> allThingsCountHttpResponse = Source.fromCompletionStage(httpResponseFuture) .flatMapConcat(httpResponse -> httpResponse.entity().getDataBytes()) .fold(ByteString.empty(), ByteString::concat) .map(ByteString::utf8String) .map(Integer::valueOf) .map(count -> JsonObject.newBuilder().set("allThingsCount", count).build()) .map(jsonObject -> HttpResponse.create() .withEntity(ContentTypes.APPLICATION_JSON, ByteString.fromString(jsonObject.toString())) .withStatus(HttpStatusCode.OK.toInt())) .runWith(Sink.head(), materializer); return completeWithFuture(allThingsCountHttpResponse); }
.build(); }) .to(Sink.actorRef(createHttpPerRequestActor(ctx, httpResponseFuture), HttpRequestActor.COMPLETE_MESSAGE)) .run(materializer);