return splitter.via(Flow.fromGraph(GraphDSL.<FlowShape<F.Either<FlowIn, Out>, Out>>create(builder -> {
return splitter.via(Flow.fromGraph(GraphDSL.<FlowShape<F.Either<FlowIn, Out>, Out>>create(builder -> {
return splitter.via(Flow.fromGraph(GraphDSL.<FlowShape<F.Either<FlowIn, Out>, Out>>create(builder -> {
/** * Chain a collection of flows one after another. * * @param flows collection of flows. * @param <A> type of messages through the flows. * @return joined flow. */ public static <A> Graph<FlowShape<A, A>, NotUsed> joinFlows( final Collection<Graph<FlowShape<A, A>, NotUsed>> flows) { Flow<A, A, NotUsed> overallFlow = Flow.create(); for (Graph<FlowShape<A, A>, NotUsed> flow : flows) { overallFlow = overallFlow.via(flow); } return overallFlow; } }
/** * Chain a collection of flows one after another. * * @param flows collection of flows. * @param <A> type of messages through the flows. * @return joined flow. */ public static <A> Graph<FlowShape<A, A>, NotUsed> joinFlows( final Collection<Graph<FlowShape<A, A>, NotUsed>> flows) { Flow<A, A, NotUsed> overallFlow = Flow.create(); for (Graph<FlowShape<A, A>, NotUsed> flow : flows) { overallFlow = overallFlow.via(flow); } return overallFlow; } }
/** * Create an Akka stream graph to dispatch {@code RetrieveThings} and {@code ThingSearchCommand}. * * @param actorContext context of this actor. * @param configReader the configReader for the concierge service. * @param pubSubMediator Akka pub-sub mediator. * @param enforcerShardRegion shard region of enforcer actors. * @return Akka stream graph to dispatch {@code RetrieveThings} and {@code ThingSearchCommand}. */ private static Graph<FlowShape<WithSender, WithSender>, NotUsed> dispatchGraph( final AbstractActor.ActorContext actorContext, final AbstractConciergeConfigReader configReader, final ActorRef pubSubMediator, final ActorRef enforcerShardRegion) { return Flow.<WithSender>create() .via(DispatcherActorCreator.dispatchSearchCommands(pubSubMediator)) .via(DispatcherActorCreator.dispatchRetrieveThings(actorContext, configReader, enforcerShardRegion)); }
/** * Create Akka actor configuration Props object with pre-enforcer. * * @param configReader the configReader for the concierge service. * @param pubSubMediator Akka pub-sub mediator. * @param enforcerShardRegion shard region of enforcer actors. * @param preEnforcer the pre-enforcer as graph. * @return the Props object. */ public static Props props(final AbstractConciergeConfigReader configReader, final ActorRef pubSubMediator, final ActorRef enforcerShardRegion, final Graph<FlowShape<WithSender, WithSender>, NotUsed> preEnforcer) { return GraphActor.partial(actorContext -> { DispatcherActorCreator.initActor(actorContext.self(), pubSubMediator); return Flow.<WithSender>create() .via(preEnforcer) .via(DispatcherActorCreator.dispatchGraph(actorContext, configReader, pubSubMediator, enforcerShardRegion)); }); }
/** * Produces a Flow of escaped ByteString from a series of String elements. Calls * out to Comet.flow internally. * * @param callbackName the javascript callback method. * @return a flow of ByteString elements. */ public static Flow<String, ByteString, NotUsed> string(String callbackName) { return Flow.of(String.class).map(str -> { return ByteString.fromString("'" + StringEscapeUtils.escapeEcmaScript(str) + "'"); }).via(flow(callbackName)); }
/** * Produces a Flow of escaped ByteString from a series of String elements. Calls * out to Comet.flow internally. * * @param callbackName the javascript callback method. * @return a flow of ByteString elements. */ public static Flow<String, ByteString, NotUsed> string(String callbackName) { return Flow.of(String.class).map(str -> { return ByteString.fromString("'" + StringEscapeUtils.escapeEcmaScript(str) + "'"); }).via(flow(callbackName)); }
/** * Produces a flow of ByteString using `Json.stringify` from a Flow of JsonNode. Calls * out to Comet.flow internally. * * @param callbackName the javascript callback method. * @return a flow of ByteString elements. */ public static Flow<JsonNode, ByteString, NotUsed> json(String callbackName) { return Flow.of(JsonNode.class).map(json -> { return ByteString.fromString(Json.stringify(json)); }).via(flow(callbackName)); }
/** * Produces a flow of ByteString using `Json.stringify` from a Flow of JsonNode. Calls * out to Comet.flow internally. * * @param callbackName the javascript callback method. * @return a flow of ByteString elements. */ public static Flow<JsonNode, ByteString, NotUsed> json(String callbackName) { return Flow.of(JsonNode.class).map(json -> { return ByteString.fromString(Json.stringify(json)); }).via(flow(callbackName)); }
/** * Produces a Flow of escaped ByteString from a series of String elements. Calls * out to Comet.flow internally. * * @param callbackName the javascript callback method. * @return a flow of ByteString elements. */ public static Flow<String, ByteString, NotUsed> string(String callbackName) { return Flow.of(String.class).map(str -> { return ByteString.fromString("'" + StringEscapeUtils.escapeEcmaScript(str) + "'"); }).via(flow(callbackName)); }
/** * Produces a flow of ByteString using `Json.stringify` from a Flow of JsonNode. Calls * out to Comet.flow internally. * * @param callbackName the javascript callback method. * @return a flow of ByteString elements. */ public static Flow<JsonNode, ByteString, NotUsed> json(String callbackName) { return Flow.of(JsonNode.class).map(json -> { return ByteString.fromString(Json.stringify(json)); }).via(flow(callbackName)); }
private Sink<Message, NotUsed> createSink(final Integer version, final String connectionCorrelationId, final AuthorizationContext connectionAuthContext, final DittoHeaders additionalHeaders, final ProtocolAdapter adapter) { return Flow.<Message>create() .filter(Message::isText) .map(Message::asTextMessage) .map(textMsg -> { if (textMsg.isStrict()) { return Source.single(textMsg.getStrictText()); } else { return textMsg.getStreamedText(); } }) .flatMapConcat(textMsg -> textMsg.<String>fold("", (str1, str2) -> str1 + str2)) .via(Flow.fromFunction(result -> { LogUtil.logWithCorrelationId(LOGGER, connectionCorrelationId, logger -> logger.debug("Received incoming WebSocket message: {}", result)); return result; })) .withAttributes(Attributes.createLogLevels(Logging.DebugLevel(), Logging.DebugLevel(), Logging.WarningLevel())) .filter(strictText -> processProtocolMessage(connectionAuthContext, connectionCorrelationId, strictText)) .map(buildSignal(version, connectionCorrelationId, connectionAuthContext, additionalHeaders, adapter)) .to(Sink.actorSubscriber( CommandSubscriber.props(streamingActor, subscriberBackpressureQueueSize, eventStream))); }