Class SourceWithContext<Out,​Ctx,​Mat>

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

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

    Can be created by calling Source.asSourceWithContext

    • Method Detail

      • fromTuples

        public static <Out,​CtxOut,​Mat> SourceWithContext<Out,​CtxOut,​Mat> fromTuples​(Source<scala.Tuple2<Out,​CtxOut>,​Mat> source)
        Creates a SourceWithContext from a regular source that operates on a tuple of (data, context) elements.
      • via

        public <Out2,​Ctx2,​Mat2> SourceWithContext<Out2,​Ctx2,​Mat> via​(Graph<FlowShape<scala.Tuple2<Out,​Ctx>,​scala.Tuple2<Out2,​Ctx2>>,​Mat2> viaFlow)
        Description copied from interface: FlowWithContextOps
        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/libraries/akka-core/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.

        Specified by:
        via in interface FlowWithContextOps<Out,​Ctx,​Mat>
        See Also:
        akka.stream.scaladsl.FlowOps.via
      • unsafeDataVia

        public <Out2,​Mat2> SourceWithContext<Out2,​Ctx,​Mat> unsafeDataVia​(Graph<FlowShape<Out,​Out2>,​Mat2> viaFlow)
        Description copied from interface: FlowWithContextOps
        Transform this flow by the regular flow. The given flow works on the data portion of the stream and ignores the context.

        The given flow *must* not re-order, drop or emit multiple elements for one incoming element, the sequence of incoming contexts is re-combined with the outgoing elements of the stream. If a flow not fulfilling this requirement is used the stream will not fail but continue running in a corrupt state and re-combine incorrect pairs of elements and contexts or deadlock.

        For more background on these requirements see https://doc.akka.io/libraries/akka-core/current/stream/stream-context.html.

        Specified by:
        unsafeDataVia in interface FlowWithContextOps<Out,​Ctx,​Mat>
      • viaMat

        public <Out2,​Ctx2,​Mat2,​Mat3> SourceWithContext<Out2,​Ctx2,​Mat3> viaMat​(Graph<FlowShape<scala.Tuple2<Out,​Ctx>,​scala.Tuple2<Out2,​Ctx2>>,​Mat2> flow,
                                                                                                            scala.Function2<Mat,​Mat2,​Mat3> combine)
        Description copied from interface: FlowWithContextOps
        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/libraries/akka-core/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.

        The combine function is used to compose the materialized values of this flow and that flow into the materialized value of the resulting Flow.

        Specified by:
        viaMat in interface FlowWithContextOps<Out,​Ctx,​Mat>
        See Also:
        akka.stream.scaladsl.FlowOpsMat.viaMat
      • mapMaterializedValue

        public <Mat2> SourceWithContext<Out,​Ctx,​Mat2> mapMaterializedValue​(scala.Function1<Mat,​Mat2> f)
        Context-preserving variant of akka.stream.scaladsl.Source.mapMaterializedValue.

        See Also:
        akka.stream.scaladsl.Source.mapMaterializedValue
      • runWith

        public <Mat2> Mat2 runWith​(Graph<SinkShape<scala.Tuple2<Out,​Ctx>>,​Mat2> sink,
                                   Materializer materializer)
        Connect this SourceWithContext to a Sink and run it. The returned value is the materialized value of the Sink.

        Note that the ActorSystem can be used as the implicit materializer parameter to use the SystemMaterializer for running the stream.

      • asSource

        public Source<scala.Tuple2<Out,​Ctx>,​Mat> asSource()
        Stops automatic context propagation from here and converts this to a regular stream of a pair of (data, context).
      • asJava

        public <JOut,​JCtx,​JMat> SourceWithContext<JOut,​JCtx,​JMat> asJava()