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

java.lang.Object
org.apache.pekko.stream.GraphDelegate<FlowShape<scala.Tuple2<In,CtxIn>,scala.Tuple2<Out,CtxOut>>,Mat>
org.apache.pekko.stream.scaladsl.FlowWithContext<In,CtxIn,Out,CtxOut,Mat>
All Implemented Interfaces:
Graph<FlowShape<scala.Tuple2<In,CtxIn>,scala.Tuple2<Out,CtxOut>>,Mat>, FlowWithContextOps<Out,CtxOut,Mat>

public final class FlowWithContext<In,CtxIn,Out,CtxOut,Mat> extends org.apache.pekko.stream.GraphDelegate<FlowShape<scala.Tuple2<In,CtxIn>,scala.Tuple2<Out,CtxOut>>,Mat> implements FlowWithContextOps<Out,CtxOut,Mat>
A flow 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.

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

  • Constructor Details

  • Method Details

    • apply

      public static <In, Ctx> FlowWithContext<In,Ctx,In,Ctx,NotUsed> apply()
      Creates an "empty" FlowWithContext that passes elements through with their context unchanged.
    • fromTuples

      public static <In, CtxIn, Out, CtxOut, Mat> FlowWithContext<In,CtxIn,Out,CtxOut,Mat> fromTuples(Flow<scala.Tuple2<In,CtxIn>,scala.Tuple2<Out,CtxOut>,Mat> flow)
      Creates a FlowWithContext from a regular flow that operates on a tuple of (data, context) elements.
    • unsafeOptionalDataVia

      public static <FIn, FOut, FViaOut, Ctx, FMat, FViaMat, Mat> FlowWithContext<FIn,Ctx,scala.Option<FViaOut>,Ctx,Mat> unsafeOptionalDataVia(FlowWithContext<FIn,Ctx,scala.Option<FOut>,Ctx,FMat> flow, Flow<FOut,FViaOut,FViaMat> viaFlow, scala.Function2<FMat,FViaMat,Mat> combine)
      Creates a FlowWithContext from an existing base FlowWithContext outputting an optional element and applying an additional viaFlow only if the element in the stream is defined.

      '''Emits when''' the provided viaFlow runs with defined elements

      '''Backpressures when''' the viaFlow runs for the defined elements and downstream backpressures

      '''Completes when''' upstream completes

      '''Cancels when''' downstream cancels

      Parameters:
      flow - The base flow that outputs an optional element
      viaFlow - The flow that gets used if the optional element in is defined. This flow only works on the data portion of flow and ignores the context so this flow *must* not re-order, drop or emit multiple elements for one incoming element
      combine - How to combine the materialized values of flow and viaFlow
      Returns:
      a FlowWithContext with the viaFlow applied onto defined elements of the flow. The output value is contained within an Option which indicates whether the original flow's element had viaFlow applied.
      Since:
      1.1.0
    • via

      public <Out2, Ctx2, Mat2> FlowWithContext<In,CtxIn,Out2,Ctx2,Mat> via(Graph<FlowShape<scala.Tuple2<Out,CtxOut>,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 behavior that is not expected by the downstream elements, such as reordering. For more background on these requirements see https://pekko.apache.org/docs/pekko/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<In,CtxIn,Out>
      See Also:
      • pekko.stream.scaladsl.FlowOps.via
    • unsafeDataVia

      public <Out2, Mat2> FlowWithContext<In,CtxIn,Out2,CtxOut,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://pekko.apache.org/docs/pekko/current/stream/stream-context.html.

      Specified by:
      unsafeDataVia in interface FlowWithContextOps<In,CtxIn,Out>
    • viaMat

      public <Out2, Ctx2, Mat2, Mat3> FlowWithContext<In,CtxIn,Out2,Ctx2,Mat3> viaMat(Graph<FlowShape<scala.Tuple2<Out,CtxOut>,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 behavior that is not expected by the downstream elements, such as reordering. For more background on these requirements see https://pekko.apache.org/docs/pekko/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<In,CtxIn,Out>
      See Also:
      • pekko.stream.scaladsl.FlowOpsMat.viaMat
    • alsoTo

      public FlowWithContext<In,CtxIn,Out,CtxOut,Mat> alsoTo(Graph<SinkShape<Out>,?> that)
      Description copied from interface: FlowWithContextOps
      Data variant of pekko.stream.scaladsl.FlowOps.alsoTo

      Specified by:
      alsoTo in interface FlowWithContextOps<In,CtxIn,Out>
      See Also:
      • pekko.stream.scaladsl.FlowOps.alsoTo
    • alsoToContext

      public FlowWithContext<In,CtxIn,Out,CtxOut,Mat> alsoToContext(Graph<SinkShape<CtxOut>,?> that)
      Description copied from interface: FlowWithContextOps
      Context variant of pekko.stream.scaladsl.FlowOps.alsoTo

      Specified by:
      alsoToContext in interface FlowWithContextOps<In,CtxIn,Out>
      See Also:
      • pekko.stream.scaladsl.FlowOps.alsoTo
    • wireTap

      public FlowWithContext<In,CtxIn,Out,CtxOut,Mat> wireTap(Graph<SinkShape<Out>,?> that)
      Description copied from interface: FlowWithContextOps
      Data variant of pekko.stream.scaladsl.FlowOps.wireTap

      Specified by:
      wireTap in interface FlowWithContextOps<In,CtxIn,Out>
      See Also:
      • pekko.stream.scaladsl.FlowOps.wireTap
    • wireTapContext

      public FlowWithContext<In,CtxIn,Out,CtxOut,Mat> wireTapContext(Graph<SinkShape<CtxOut>,?> that)
      Description copied from interface: FlowWithContextOps
      Context variant of pekko.stream.scaladsl.FlowOps.wireTap

      Specified by:
      wireTapContext in interface FlowWithContextOps<In,CtxIn,Out>
      See Also:
      • pekko.stream.scaladsl.FlowOps.wireTap
    • withAttributes

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

      Specified by:
      withAttributes in interface Graph<In,CtxIn>
      See Also:
      • pekko.stream.scaladsl.Flow.withAttributes
    • mapMaterializedValue

      public <Mat2> FlowWithContext<In,CtxIn,Out,CtxOut,Mat2> mapMaterializedValue(scala.Function1<Mat,Mat2> f)
      Context-preserving variant of pekko.stream.scaladsl.Flow.mapMaterializedValue.

      See Also:
      • pekko.stream.scaladsl.Flow.mapMaterializedValue
    • asFlow

      public Flow<scala.Tuple2<In,CtxIn>,scala.Tuple2<Out,CtxOut>,Mat> asFlow()
    • asJava

      public <JIn extends In, JCtxIn extends CtxIn, JOut, JCtxOut, JMat> FlowWithContext<JIn,JCtxIn,JOut,JCtxOut,JMat> asJava()