private static Flow<Boolean, Boolean, NotUsed> stopTimer(final StartedTimer timer) { return Flow.fromFunction(foo -> { timer.stop(); // stop timer return foo; }); }
private static Flow<Boolean, Boolean, NotUsed> stopTimer(final StartedTimer timer) { return Flow.fromFunction(foo -> { timer.stop(); // stop timer return foo; }); }
private <T> Source<T, NotUsed> processSearchPersistenceResult(final Supplier<Source<T, NotUsed>> resultSupplier, final DittoHeaders dittoHeaders) { final Source<T, NotUsed> source = resultSupplier.get(); final Flow<T, T, NotUsed> logAndFinishPersistenceSegmentFlow = Flow.fromFunction(result -> { // we know that the source provides exactly one ResultList LogUtil.enhanceLogWithCorrelationId(log, dittoHeaders.getCorrelationId()); log.debug("Persistence returned: {}", result); return result; }); return source.<T, NotUsed>via(logAndFinishPersistenceSegmentFlow); }
private Source<Message, NotUsed> createSource(final String connectionCorrelationId, final ProtocolAdapter adapter) { return Source.<Jsonifiable.WithPredicate<JsonObject, JsonField>>actorPublisher( EventAndResponsePublisher.props(publisherBackpressureBufferSize)) .mapMaterializedValue(actorRef -> { streamingActor.tell(new Connect(actorRef, connectionCorrelationId, STREAMING_TYPE_WS), null); return NotUsed.getInstance(); }) .map(this::publishResponsePublishedEvent) .map(jsonifiableToString(adapter)) .via(Flow.fromFunction(result -> { LogUtil.logWithCorrelationId(LOGGER, connectionCorrelationId, logger -> logger.debug("Sending outgoing WebSocket message: {}", result)); return result; })) .map(TextMessage::create); }
() -> searchPersistence.count((PolicyRestrictedSearchAggregation) query), dittoHeaders) .via(Flow.fromFunction(result -> { databaseAccessTimer.stop(); return result; .via(Flow.fromFunction(result -> { databaseAccessTimer.stop(); return result; .via(Flow.fromFunction(result -> { countTimer.stop(); return result;
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))); }
() -> searchPersistence.findAll((PolicyRestrictedSearchAggregation) query), dittoHeaders) .via(Flow.fromFunction(result -> { databaseAccessTimer.stop(); return result; .via(Flow.fromFunction(result -> { databaseAccessTimer.stop(); return result; .via(Flow.fromFunction(result -> { searchTimer.stop(); return result;