Class FlowWithContext<In,​CtxIn,​Out,​CtxOut,​Mat>

  • All Implemented Interfaces:
    Graph<FlowShape<Pair<In,​CtxIn>,​Pair<Out,​CtxOut>>,​Mat>

    public final class FlowWithContext<In,​CtxIn,​Out,​CtxOut,​Mat>
    extends GraphDelegate<FlowShape<Pair<In,​CtxIn>,​Pair<Out,​CtxOut>>,​Mat>
    A flow that provides operations which automatically propagate the context of an element. Only a subset of common operations from Flow is supported. As an escape hatch you can use FlowWithContext.via to manually provide the context propagation for otherwise unsupported operations.

    An "empty" flow can be created by calling FlowWithContext[Ctx, T].

    • Method Detail

      • fromPairs

        public static <In,​CtxIn,​Out,​CtxOut,​Mat> FlowWithContext<In,​CtxIn,​Out,​CtxOut,​Mat> fromPairs​(Flow<Pair<In,​CtxIn>,​Pair<Out,​CtxOut>,​Mat> under)
        Creates a FlowWithContext from a regular flow that operates on Pair elements.
      • via

        public <Out2,​CtxOut2,​Mat2> FlowWithContext<In,​CtxIn,​Out2,​CtxOut2,​Mat> via​(Graph<FlowShape<Pair<Out,​CtxOut>,​Pair<Out2,​CtxOut2>>,​Mat2> viaFlow)
        Transform this flow by the regular flow. The given flow must support manual context propagation by taking and producing tuples of (data, context).

        It is up to the implementer to ensure the inner flow does not exhibit any behaviour that is not expected by the downstream elements, such as reordering. For more background on these requirements see https://doc.akka.io/docs/akka/current/stream/stream-context.html.

        This can be used as an escape hatch for operations that are not (yet) provided with automatic context propagation here.

        See Also:
        akka.stream.javadsl.Flow.via
      • withAttributes

        public FlowWithContext<In,​CtxIn,​Out,​CtxOut,​Mat> withAttributes​(Attributes attr)
        Context-preserving variant of akka.stream.javadsl.Flow.withAttributes.

        See Also:
        akka.stream.javadsl.Flow.withAttributes
      • mapError

        public FlowWithContext<In,​CtxIn,​Out,​CtxOut,​Mat> mapError​(scala.PartialFunction<java.lang.Throwable,​java.lang.Throwable> pf)
        Context-preserving variant of akka.stream.javadsl.Flow.mapError.

        See Also:
        akka.stream.javadsl.Flow.mapError
      • mapMaterializedValue

        public <Mat2> FlowWithContext<In,​CtxIn,​Out,​CtxOut,​Mat2> mapMaterializedValue​(Function<Mat,​Mat2> f)
        Context-preserving variant of akka.stream.javadsl.Flow.mapMaterializedValue.

        See Also:
        akka.stream.javadsl.Flow.mapMaterializedValue
      • collect

        public <Out2> FlowWithContext<In,​CtxIn,​Out2,​CtxOut,​Mat> collect​(scala.PartialFunction<Out,​Out2> pf)
        Context-preserving variant of akka.stream.javadsl.Flow.collect.

        Note, that the context of elements that are filtered out is skipped as well.

        See Also:
        akka.stream.javadsl.Flow.collect
      • filter

        public FlowWithContext<In,​CtxIn,​Out,​CtxOut,​Mat> filter​(Predicate<Out> p)
        Context-preserving variant of akka.stream.javadsl.Flow.filter.

        Note, that the context of elements that are filtered out is skipped as well.

        See Also:
        akka.stream.javadsl.Flow.filter
      • filterNot

        public FlowWithContext<In,​CtxIn,​Out,​CtxOut,​Mat> filterNot​(Predicate<Out> p)
        Context-preserving variant of akka.stream.javadsl.Flow.filterNot.

        Note, that the context of elements that are filtered out is skipped as well.

        See Also:
        akka.stream.javadsl.Flow.filterNot
      • grouped

        public FlowWithContext<In,​CtxIn,​java.util.List<Out>,​java.util.List<CtxOut>,​Mat> grouped​(int n)
        Context-preserving variant of akka.stream.javadsl.Flow.grouped.

        Each output group will be associated with a Seq of corresponding context elements.

        See Also:
        akka.stream.javadsl.Flow.grouped
      • mapConcat

        public <Out2> FlowWithContext<In,​CtxIn,​Out2,​CtxOut,​Mat> mapConcat​(Function<Out,​? extends java.lang.Iterable<Out2>> f)
        Context-preserving variant of akka.stream.javadsl.Flow.mapConcat.

        The context of the input element will be associated with each of the output elements calculated from this input element.

        Example:

        def dup(element: String) = Seq(element, element)

        Input:

        ("a", 1) ("b", 2)

        inputElements.mapConcat(dup)

        Output:

        ("a", 1) ("a", 1) ("b", 2) ("b", 2)

        See Also:
        akka.stream.javadsl.Flow.mapConcat
      • mapContext

        public <CtxOut2> FlowWithContext<In,​CtxIn,​Out,​CtxOut2,​Mat> mapContext​(Function<CtxOut,​CtxOut2> extractContext)
        Apply the given function to each context element (leaving the data elements unchanged).
      • sliding

        public FlowWithContext<In,​CtxIn,​java.util.List<Out>,​java.util.List<CtxOut>,​Mat> sliding​(int n,
                                                                                                                        int step)
        Context-preserving variant of akka.stream.javadsl.Flow.sliding.

        Each output group will be associated with a Seq of corresponding context elements.

        See Also:
        akka.stream.javadsl.Flow.sliding
      • sliding$default$2

        public int sliding$default$2()
      • log

        public FlowWithContext<In,​CtxIn,​Out,​CtxOut,​Mat> log​(java.lang.String name,
                                                                                    Function<Out,​java.lang.Object> extract)
        Context-preserving variant of akka.stream.javadsl.Flow.log.

        See Also:
        akka.stream.javadsl.Flow.log
      • log

        public FlowWithContext<In,​CtxIn,​Out,​CtxOut,​Mat> log​(java.lang.String name)
        Context-preserving variant of akka.stream.javadsl.Flow.log.

        See Also:
        akka.stream.javadsl.Flow.log
      • throttle

        public FlowWithContext<In,​CtxIn,​Out,​CtxOut,​Mat> throttle​(int elements,
                                                                                         java.time.Duration per)
        Context-preserving variant of akka.stream.javadsl.Flow.throttle.

        See Also:
        akka.stream.javadsl.Flow.throttle
      • throttle

        public FlowWithContext<In,​CtxIn,​Out,​CtxOut,​Mat> throttle​(int elements,
                                                                                         java.time.Duration per,
                                                                                         int maximumBurst,
                                                                                         ThrottleMode mode)
        Context-preserving variant of akka.stream.javadsl.Flow.throttle.

        See Also:
        akka.stream.javadsl.Flow.throttle
      • throttle

        public FlowWithContext<In,​CtxIn,​Out,​CtxOut,​Mat> throttle​(int cost,
                                                                                         java.time.Duration per,
                                                                                         Function<Out,​java.lang.Integer> costCalculation)
        Context-preserving variant of akka.stream.javadsl.Flow.throttle.

        See Also:
        akka.stream.javadsl.Flow.throttle
      • throttle

        public FlowWithContext<In,​CtxIn,​Out,​CtxOut,​Mat> throttle​(int cost,
                                                                                         java.time.Duration per,
                                                                                         int maximumBurst,
                                                                                         Function<Out,​java.lang.Integer> costCalculation,
                                                                                         ThrottleMode mode)
        Context-preserving variant of akka.stream.javadsl.Flow.throttle.

        See Also:
        akka.stream.javadsl.Flow.throttle