Class SourceWithContext<Out,Ctx,Mat>
- java.lang.Object
-
- org.apache.pekko.stream.GraphDelegate<SourceShape<scala.Tuple2<Out,Ctx>>,Mat>
-
- org.apache.pekko.stream.scaladsl.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 org.apache.pekko.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 fromFlowOps
is supported. As an escape hatch you can useFlowWithContextOps.via
to manually provide the context propagation for otherwise unsupported operations.Can be created by calling
Source.asSourceWithContext
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.pekko.stream.Graph
Graph.GraphMapMatVal<S extends Shape,M>
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description SourceWithContext<Out,Ctx,Mat>
alsoTo(Graph<SinkShape<Out>,?> that)
Data variant ofpekko.stream.scaladsl.FlowOps.alsoTo
SourceWithContext<Out,Ctx,Mat>
alsoToContext(Graph<SinkShape<Ctx>,?> that)
Context variant ofpekko.stream.scaladsl.FlowOps.alsoTo
<JOut,JCtx,JMat>
SourceWithContext<JOut,JCtx,JMat>asJava()
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).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.<Mat2> SourceWithContext<Out,Ctx,Mat2>
mapMaterializedValue(scala.Function1<Mat,Mat2> f)
Context-preserving variant ofpekko.stream.scaladsl.Source.mapMaterializedValue
.<Mat2> Mat2
runWith(Graph<SinkShape<scala.Tuple2<Out,Ctx>>,Mat2> sink, Materializer materializer)
Connect thispekko.stream.scaladsl.SourceWithContext
to apekko.stream.scaladsl.Sink
and run it.<Mat2> RunnableGraph<Mat>
to(Graph<SinkShape<scala.Tuple2<Out,Ctx>>,Mat2> sink)
Connect thispekko.stream.scaladsl.SourceWithContext
to apekko.stream.scaladsl.Sink
, concatenating the processing steps of both.<Mat2,Mat3>
RunnableGraph<Mat3>toMat(Graph<SinkShape<scala.Tuple2<Out,Ctx>>,Mat2> sink, scala.Function2<Mat,Mat2,Mat3> combine)
Connect thispekko.stream.scaladsl.SourceWithContext
to apekko.stream.scaladsl.Sink
, concatenating the processing steps of both.<Out2,Mat2>
SourceWithContext<Out2,Ctx,Mat>unsafeDataVia(Graph<FlowShape<Out,Out2>,Mat2> viaFlow)
Transform this flow by the regular flow.static <SOut,FOut,Ctx,SMat,FMat,Mat>
SourceWithContext<scala.Option<FOut>,Ctx,Mat>unsafeOptionalDataVia(SourceWithContext<scala.Option<SOut>,Ctx,SMat> source, Flow<SOut,FOut,FMat> viaFlow, scala.Function2<SMat,FMat,Mat> combine)
Creates a SourceWithContext from an existing base SourceWithContext outputting an optional element and applying an additional viaFlow only if the element in the stream is defined.<Out2,Ctx2,Mat2>
SourceWithContext<Out2,Ctx2,Mat>via(Graph<FlowShape<scala.Tuple2<Out,Ctx>,scala.Tuple2<Out2,Ctx2>>,Mat2> viaFlow)
Transform this flow by the regular flow.<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)
Transform this flow by the regular flow.SourceWithContext<Out,Ctx,Mat>
wireTap(Graph<SinkShape<Out>,?> that)
Data variant ofpekko.stream.scaladsl.FlowOps.wireTap
SourceWithContext<Out,Ctx,Mat>
wireTapContext(Graph<SinkShape<Ctx>,?> that)
Context variant ofpekko.stream.scaladsl.FlowOps.wireTap
SourceWithContext<Out,Ctx,Mat>
withAttributes(Attributes attr)
Context-preserving variant ofpekko.stream.scaladsl.Source.withAttributes
.-
Methods inherited from class org.apache.pekko.stream.GraphDelegate
addAttributes, async, async, async, getAttributes, named, shape, traversalBuilder
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.pekko.stream.scaladsl.FlowWithContextOps
collect, filter, filterNot, flow, grouped, log, log$default$2, log$default$3, logWithMarker, logWithMarker$default$3, logWithMarker$default$4, map, mapAsync, mapAsyncPartitioned, mapAsyncPartitionedUnordered, mapConcat, mapContext, mapError, sliding, sliding$default$2, throttle, throttle, throttle, throttle
-
-
-
-
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.
-
unsafeOptionalDataVia
public static <SOut,FOut,Ctx,SMat,FMat,Mat> SourceWithContext<scala.Option<FOut>,Ctx,Mat> unsafeOptionalDataVia(SourceWithContext<scala.Option<SOut>,Ctx,SMat> source, Flow<SOut,FOut,FMat> viaFlow, scala.Function2<SMat,FMat,Mat> combine)
Creates a SourceWithContext from an existing base SourceWithContext 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:
source
- The base source that outputs an optional elementviaFlow
- 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 elementcombine
- How to combine the materialized values of source and viaFlow- Returns:
- a SourceWithContext with the viaFlow applied onto defined elements of the flow. The output value is contained within an Option which indicates whether the original source's element had viaFlow applied.
- Since:
- 1.1.0
-
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 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 interfaceFlowWithContextOps<Out,Ctx,Mat>
- See Also:
pekko.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://pekko.apache.org/docs/pekko/current/stream/stream-context.html.
- Specified by:
unsafeDataVia
in interfaceFlowWithContextOps<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 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 interfaceFlowWithContextOps<Out,Ctx,Mat>
- See Also:
pekko.stream.scaladsl.FlowOpsMat.viaMat
-
withAttributes
public SourceWithContext<Out,Ctx,Mat> withAttributes(Attributes attr)
Context-preserving variant ofpekko.stream.scaladsl.Source.withAttributes
.- Specified by:
withAttributes
in interfaceGraph<Out,Ctx>
- See Also:
pekko.stream.scaladsl.Source.withAttributes
-
mapMaterializedValue
public <Mat2> SourceWithContext<Out,Ctx,Mat2> mapMaterializedValue(scala.Function1<Mat,Mat2> f)
Context-preserving variant ofpekko.stream.scaladsl.Source.mapMaterializedValue
.- See Also:
pekko.stream.scaladsl.Source.mapMaterializedValue
-
to
public <Mat2> RunnableGraph<Mat> to(Graph<SinkShape<scala.Tuple2<Out,Ctx>>,Mat2> sink)
Connect thispekko.stream.scaladsl.SourceWithContext
to apekko.stream.scaladsl.Sink
, concatenating the processing steps of both.
-
toMat
public <Mat2,Mat3> RunnableGraph<Mat3> toMat(Graph<SinkShape<scala.Tuple2<Out,Ctx>>,Mat2> sink, scala.Function2<Mat,Mat2,Mat3> combine)
Connect thispekko.stream.scaladsl.SourceWithContext
to apekko.stream.scaladsl.Sink
, concatenating the processing steps of both.
-
alsoTo
public SourceWithContext<Out,Ctx,Mat> alsoTo(Graph<SinkShape<Out>,?> that)
Description copied from interface:FlowWithContextOps
Data variant ofpekko.stream.scaladsl.FlowOps.alsoTo
- Specified by:
alsoTo
in interfaceFlowWithContextOps<Out,Ctx,Mat>
- See Also:
pekko.stream.scaladsl.FlowOps.alsoTo
-
alsoToContext
public SourceWithContext<Out,Ctx,Mat> alsoToContext(Graph<SinkShape<Ctx>,?> that)
Description copied from interface:FlowWithContextOps
Context variant ofpekko.stream.scaladsl.FlowOps.alsoTo
- Specified by:
alsoToContext
in interfaceFlowWithContextOps<Out,Ctx,Mat>
- See Also:
pekko.stream.scaladsl.FlowOps.alsoTo
-
wireTap
public SourceWithContext<Out,Ctx,Mat> wireTap(Graph<SinkShape<Out>,?> that)
Description copied from interface:FlowWithContextOps
Data variant ofpekko.stream.scaladsl.FlowOps.wireTap
- Specified by:
wireTap
in interfaceFlowWithContextOps<Out,Ctx,Mat>
- See Also:
pekko.stream.scaladsl.FlowOps.wireTap
-
wireTapContext
public SourceWithContext<Out,Ctx,Mat> wireTapContext(Graph<SinkShape<Ctx>,?> that)
Description copied from interface:FlowWithContextOps
Context variant ofpekko.stream.scaladsl.FlowOps.wireTap
- Specified by:
wireTapContext
in interfaceFlowWithContextOps<Out,Ctx,Mat>
- See Also:
pekko.stream.scaladsl.FlowOps.wireTap
-
runWith
public <Mat2> Mat2 runWith(Graph<SinkShape<scala.Tuple2<Out,Ctx>>,Mat2> sink, Materializer materializer)
Connect thispekko.stream.scaladsl.SourceWithContext
to apekko.stream.scaladsl.Sink
and run it. The returned value is the materialized value of theSink
.Note that the
ActorSystem
can be used as the implicitmaterializer
parameter to use thepekko.stream.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()
-
-