@Override public CompletionStage<F.Either<Result, Flow<Message, Message, ?>>> apply(Http.RequestHeader request) { return f.apply(request).thenApply(resultOrFlow -> { if (resultOrFlow.left.isPresent()) { return F.Either.Left(resultOrFlow.left.get()); } else { Flow<Message, Message, ?> flow = AkkaStreams.bypassWith( Flow.<Message>create().collect(inMapper), play.api.libs.streams.AkkaStreams.onlyFirstCanFinishMerge(2), resultOrFlow.right.get().map(outMapper::apply) ); return F.Either.Right(flow); } }); } };
@Override public CompletionStage<F.Either<Result, Flow<Message, Message, ?>>> apply(Http.RequestHeader request) { return f.apply(request).thenApply(resultOrFlow -> { if (resultOrFlow.left.isPresent()) { return F.Either.Left(resultOrFlow.left.get()); } else { Flow<Message, Message, ?> flow = AkkaStreams.bypassWith( Flow.<Message>create().collect(inMapper), play.api.libs.streams.AkkaStreams.onlyFirstCanFinishMerge(2), resultOrFlow.right.get().map(outMapper::apply) ); return F.Either.Right(flow); } }); } };
@Override public CompletionStage<F.Either<Result, Flow<Message, Message, ?>>> apply(Http.RequestHeader request) { return f.apply(request).thenApply(resultOrFlow -> { if (resultOrFlow.left.isPresent()) { return F.Either.Left(resultOrFlow.left.get()); } else { Flow<Message, Message, ?> flow = AkkaStreams.bypassWith( Flow.<Message>create().collect(inMapper), play.api.libs.streams.AkkaStreams.onlyFirstCanFinishMerge(2), resultOrFlow.right.get().map(outMapper::apply) ); return F.Either.Right(flow); } }); } };
/** * Bypass the given flow using the given splitter function. * <p> * If the splitter function returns Left, they will go through the flow. If it returns Right, they will bypass the * flow. * <p> * Uses onlyFirstCanFinishMerge(2) by default. * * @param <In> the In type parameter for Flow * @param <FlowIn> the FlowIn type parameter for the left branch in Either. * @param <Out> the Out type parameter for Flow * @param flow the original flow * @param splitter the splitter function to use * * @return the flow with a bypass. */ public static <In, FlowIn, Out> Flow<In, Out, ?> bypassWith(Function<In, F.Either<FlowIn, Out>> splitter, Flow<FlowIn, Out, ?> flow) { return bypassWith(Flow.<In>create().map(splitter::apply), play.api.libs.streams.AkkaStreams.onlyFirstCanFinishMerge(2), flow); }
/** * Bypass the given flow using the given splitter function. * <p> * If the splitter function returns Left, they will go through the flow. If it returns Right, they will bypass the * flow. * <p> * Uses onlyFirstCanFinishMerge(2) by default. * * @param <In> the In type parameter for Flow * @param <FlowIn> the FlowIn type parameter for the left branch in Either. * @param <Out> the Out type parameter for Flow * @param flow the original flow * @param splitter the splitter function to use * * @return the flow with a bypass. */ public static <In, FlowIn, Out> Flow<In, Out, ?> bypassWith(Function<In, F.Either<FlowIn, Out>> splitter, Flow<FlowIn, Out, ?> flow) { return bypassWith(Flow.<In>create().map(splitter::apply), play.api.libs.streams.AkkaStreams.onlyFirstCanFinishMerge(2), flow); }
/** * Bypass the given flow using the given splitter function. * <p> * If the splitter function returns Left, they will go through the flow. If it returns Right, they will bypass the * flow. * <p> * Uses onlyFirstCanFinishMerge(2) by default. * * @param <In> the In type parameter for Flow * @param <FlowIn> the FlowIn type parameter for the left branch in Either. * @param <Out> the Out type parameter for Flow * @param flow the original flow * @param splitter the splitter function to use * * @return the flow with a bypass. */ public static <In, FlowIn, Out> Flow<In, Out, ?> bypassWith(Function<In, F.Either<FlowIn, Out>> splitter, Flow<FlowIn, Out, ?> flow) { return bypassWith(Flow.<In>create().map(splitter::apply), play.api.libs.streams.AkkaStreams.onlyFirstCanFinishMerge(2), flow); }
/** * @return a flow of EventSource.Event to ByteString. */ public static Flow<EventSource.Event, ByteString, ?> flow() { Flow<Event, Event, NotUsed> flow = Flow.of(Event.class); return flow.map((EventSource.Event event) -> ByteString.fromString(event.formatted())); }
/** * @return a flow of EventSource.Event to ByteString. */ public static Flow<EventSource.Event, ByteString, ?> flow() { Flow<Event, Event, NotUsed> flow = Flow.of(Event.class); return flow.map((EventSource.Event event) -> ByteString.fromString(event.formatted())); }
/** * @return a flow of EventSource.Event to ByteString. */ public static Flow<EventSource.Event, ByteString, ?> flow() { Flow<Event, Event, NotUsed> flow = Flow.of(Event.class); return flow.map((EventSource.Event event) -> ByteString.fromString(event.formatted())); }
/** * 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 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 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 with a prepended block and a script wrapper. * * @param callbackName the javascript callback method. * @return a flow of ByteString elements. */ public static Flow<ByteString, ByteString, NotUsed> flow(String callbackName) { ByteString cb = ByteString.fromString(callbackName); return Flow.of(ByteString.class).map((msg) -> { return formatted(cb, msg); }).prepend(Source.single(initialChunk)); }
/** * Produces a flow of ByteString with a prepended block and a script wrapper. * * @param callbackName the javascript callback method. * @return a flow of ByteString elements. */ public static Flow<ByteString, ByteString, NotUsed> flow(String callbackName) { ByteString cb = ByteString.fromString(callbackName); return Flow.of(ByteString.class).map((msg) -> { return formatted(cb, msg); }).prepend(Source.single(initialChunk)); }
/** * Produces a flow of ByteString with a prepended block and a script wrapper. * * @param callbackName the javascript callback method. * @return a flow of ByteString elements. */ public static Flow<ByteString, ByteString, NotUsed> flow(String callbackName) { ByteString cb = ByteString.fromString(callbackName); return Flow.of(ByteString.class).map((msg) -> { return formatted(cb, msg); }).prepend(Source.single(initialChunk)); }
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))); }