Class SourceWithContext<Ctx,​Out,​Mat>

  • All Implemented Interfaces:
    Graph<SourceShape<scala.Tuple2<Out,​Ctx>>,​Mat>

    public final class SourceWithContext<Ctx,​Out,​Mat>
    extends GraphDelegate<SourceShape<scala.Tuple2<Out,​Ctx>>,​Mat>
    A source that provides operations which automatically propagate the context of an element. Only a subset of common operations from Source is supported. As an escape hatch you can use SourceWithContext.via to manually provide the context propagation for otherwise unsupported operations.

    Can be created by calling {@link Source.startContextPropagation()}

    API MAY CHANGE

    • Method Detail

      • collect

        public <Out2> SourceWithContext<Ctx,​Out2,​Mat> collect​(scala.PartialFunction<Out,​Out2> pf)
        Context-preserving variant of akka.stream.javadsl.Source.collect.

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

        Parameters:
        pf - (undocumented)
        Returns:
        (undocumented)
        See Also:
        akka.stream.javadsl.Source.collect
      • endContextPropagation

        public Source<Pair<Out,​Ctx>,​Mat> endContextPropagation()
        Stops automatic context propagation from here and converts this to a regular stream of a pair of (data, context).
        Returns:
        (undocumented)
      • filter

        public SourceWithContext<Ctx,​Out,​Mat> filter​(Predicate<Out> p)
        Context-preserving variant of akka.stream.javadsl.Source.filter.

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

        Parameters:
        p - (undocumented)
        Returns:
        (undocumented)
        See Also:
        akka.stream.javadsl.Source.filter
      • filterNot

        public SourceWithContext<Ctx,​Out,​Mat> filterNot​(Predicate<Out> p)
        Context-preserving variant of akka.stream.javadsl.Source.filterNot.

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

        Parameters:
        p - (undocumented)
        Returns:
        (undocumented)
        See Also:
        akka.stream.javadsl.Source.filterNot
      • grouped

        public SourceWithContext<java.util.List<Ctx>,​java.util.List<Out>,​Mat> grouped​(int n)
        Context-preserving variant of akka.stream.javadsl.Source.grouped.

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

        Parameters:
        n - (undocumented)
        Returns:
        (undocumented)
        See Also:
        akka.stream.javadsl.Source.grouped
      • map

        public <Out2> SourceWithContext<Ctx,​Out2,​Mat> map​(Function<Out,​Out2> f)
        Context-preserving variant of akka.stream.javadsl.Source.map.

        Parameters:
        f - (undocumented)
        Returns:
        (undocumented)
        See Also:
        akka.stream.javadsl.Source.map
      • mapConcat

        public <Out2> SourceWithContext<Ctx,​Out2,​Mat> mapConcat​(Function<Out,​? extends java.lang.Iterable<Out2>> f)
        Context-preserving variant of akka.stream.javadsl.Source.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)

        Parameters:
        f - (undocumented)
        Returns:
        (undocumented)
        See Also:
        akka.stream.javadsl.Source.mapConcat
      • mapContext

        public <Ctx2> SourceWithContext<Ctx2,​Out,​Mat> mapContext​(Function<Ctx,​Ctx2> extractContext)
        Apply the given function to each context element (leaving the data elements unchanged).
        Parameters:
        extractContext - (undocumented)
        Returns:
        (undocumented)
      • sliding

        public SourceWithContext<java.util.List<Ctx>,​java.util.List<Out>,​Mat> sliding​(int n,
                                                                                                  int step)
        Context-preserving variant of akka.stream.javadsl.Source.sliding.

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

        Parameters:
        n - (undocumented)
        step - (undocumented)
        Returns:
        (undocumented)
        See Also:
        akka.stream.javadsl.Source.sliding
      • sliding$default$2

        public int sliding$default$2()
      • statefulMapConcat

        public <Out2> SourceWithContext<Ctx,​Out2,​Mat> statefulMapConcat​(Creator<Function<Out,​java.lang.Iterable<Out2>>> f)
        Context-preserving variant of akka.stream.javadsl.Source.statefulMapConcat.

        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.statefulMapConcat(() => dup)

        Output:

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

        Parameters:
        f - (undocumented)
        Returns:
        (undocumented)
        See Also:
        akka.stream.javadsl.Source.statefulMapConcat
      • via

        public <Ctx2,​Out2,​Mat2> SourceWithContext<Ctx2,​Out2,​Mat> via​(Graph<FlowShape<Pair<Out,​Ctx>,​Pair<Out2,​Ctx2>>,​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).

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

        Parameters:
        viaFlow - (undocumented)
        Returns:
        (undocumented)
        See Also:
        akka.stream.javadsl.Flow.via