Class SourceWithContext<Out,Ctx,Mat>
- All Implemented Interfaces:
Graph<SourceShape<Pair<Out,Ctx>>, Mat>
Source is supported. As an escape hatch you can
use via(org.apache.pekko.stream.Graph<? extends org.apache.pekko.stream.FlowShape<? super org.apache.pekko.japi.Pair<Out, Ctx>, ? extends org.apache.pekko.japi.Pair<Out2, Ctx2>>, Mat2>) to manually provide the context propagation for otherwise unsupported
operations.
When used as a Graph, its outlet emits pekko.japi.Pair elements, matching asSource().
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> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionasScala()asSource()Stops automatic context propagation from here and converts this to a regular stream of a pair of (data, context).<Out2> SourceWithContext<Out2,Ctx, Mat> Context-preserving variant ofpekko.stream.javadsl.Source.collect.<Out2> SourceWithContext<Out2,Ctx, Mat> collectFirst(scala.PartialFunction<Out, Out2> pf) Context-preserving variant ofpekko.stream.javadsl.Source.collectFirst.<Out2> SourceWithContext<Out2,Ctx, Mat> collectType(Class<Out2> clazz) Context-preserving variant ofpekko.stream.javadsl.Source.collectType.<Out2> SourceWithContext<Out2,Ctx, Mat> collectWhile(scala.PartialFunction<Out, Out2> pf) Context-preserving variant ofpekko.stream.javadsl.Source.collectWhile.drop(long n) Context-preserving variant ofpekko.stream.javadsl.Source.drop.Context-preserving variant ofpekko.stream.javadsl.Source.dropRepeated.dropRepeated(Function2<? super Out, ? super Out, Object> p) Context-preserving variant ofpekko.stream.javadsl.Source.dropRepeated.Context-preserving variant ofpekko.stream.javadsl.Source.dropWhile.dropWithin(Duration duration) Context-preserving variant ofpekko.stream.javadsl.Source.dropWithin.Context-preserving variant ofpekko.stream.javadsl.Source.filter.Context-preserving variant ofpekko.stream.javadsl.Source.filterNot.static <Out,CtxOut, Mat>
SourceWithContext<Out,CtxOut, Mat> Creates a SourceWithContext from a regular flow that operates onPair<data, context>elements.grouped(int n) Context-preserving variant ofpekko.stream.javadsl.Source.grouped.limit(int max) Context-preserving variant ofpekko.stream.javadsl.Source.limit.limitWeighted(long max, Function<? super Out, Long> costFn) Context-preserving variant ofpekko.stream.javadsl.Source.limitWeighted.Context-preserving variant ofpekko.stream.javadsl.Flow.log.log(String name, LoggingAdapter log) Context-preserving variant ofpekko.stream.javadsl.Flow.log.Context-preserving variant ofpekko.stream.javadsl.Flow.log.Context-preserving variant ofpekko.stream.javadsl.Source.log.Context-preserving variant ofpekko.stream.javadsl.Flow.logWithMarker.logWithMarker(String name, Function2<? super Out, ? super Ctx, ? extends LogMarker> marker, MarkerLoggingAdapter log) Context-preserving variant ofpekko.stream.javadsl.Flow.logWithMarker.logWithMarker(String name, Function2<? super Out, ? super Ctx, ? extends LogMarker> marker, Function<? super Out, Object> extract) Context-preserving variant ofpekko.stream.javadsl.Flow.logWithMarker.,logWithMarker(String name, Function2<? super Out, ? super Ctx, ? extends LogMarker> marker, Function<? super Out, Object> extract, MarkerLoggingAdapter log) Context-preserving variant ofpekko.stream.javadsl.Source.logWithMarker.<Out2> SourceWithContext<Out2,Ctx, Mat> Context-preserving variant ofpekko.stream.javadsl.Source.map.<Out2> SourceWithContext<Out2,Ctx, Mat> mapAsync(int parallelism, Function<? super Out, ? extends CompletionStage<? extends Out2>> f) Context-preserving variant ofpekko.stream.javadsl.Source.mapAsync.<Out2,P> SourceWithContext<Out2, Ctx, Mat> mapAsyncPartitioned(int parallelism, Function<? super Out, ? extends P> partitioner, Function2<? super Out, ? super P, ? extends CompletionStage<? extends Out2>> f) Context-preserving variant ofpekko.stream.javadsl.Source.mapAsyncPartitioned.<Out2,P> SourceWithContext<Out2, Ctx, Mat> mapAsyncPartitionedUnordered(int parallelism, Function<? super Out, ? extends P> partitioner, Function2<? super Out, ? super P, ? extends CompletionStage<? extends Out2>> f) Context-preserving variant ofpekko.stream.javadsl.Source.mapAsyncPartitionedUnordered.<Out2> SourceWithContext<Out2,Ctx, Mat> Context-preserving variant ofpekko.stream.javadsl.Source.mapConcat.<Ctx2> SourceWithContext<Out,Ctx2, Mat> mapContext(Function<? super Ctx, ? extends Ctx2> extractContext) Apply the given function to each context element (leaving the data elements unchanged).Context-preserving variant ofpekko.stream.javadsl.Source.mapError.<Mat2> SourceWithContext<Out,Ctx, Mat2> mapMaterializedValue(Function<? super Mat, ? extends Mat2> f) Context-preserving variant ofpekko.stream.javadsl.Source.mapMaterializedValue.<Out2> SourceWithContext<Out2,Ctx, Mat> Context-preserving variant ofpekko.stream.javadsl.Source.mapOption.<M> MrunWith(Graph<? extends SinkShape<? super Pair<Out, Ctx>>, M> sink, ClassicActorSystemProvider systemProvider) Connect thispekko.stream.javadsl.SourceWithContextto apekko.stream.javadsl.Sinkand run it.<M> MConnect thispekko.stream.javadsl.SourceWithContextto apekko.stream.javadsl.Sinkand run it.sliding(int n, int step) Context-preserving variant ofpekko.stream.javadsl.Source.sliding.inttake(long n) Context-preserving variant ofpekko.stream.javadsl.Source.take.Context-preserving variant ofpekko.stream.javadsl.Source.takeUntil.Context-preserving variant ofpekko.stream.javadsl.Source.takeWhile.Context-preserving variant ofpekko.stream.javadsl.Source.takeWhile.takeWithin(Duration duration) Context-preserving variant ofpekko.stream.javadsl.Source.takeWithin.Context-preserving variant ofpekko.stream.javadsl.Source.throttle.throttle(int cost, Duration per, int maximumBurst, Function<? super Out, Integer> costCalculation, ThrottleMode mode) Context-preserving variant ofpekko.stream.javadsl.Source.throttle.throttle(int elements, Duration per, int maximumBurst, ThrottleMode mode) Context-preserving variant ofpekko.stream.javadsl.Source.throttle.Context-preserving variant ofpekko.stream.javadsl.Source.throttle.<Mat2> RunnableGraph<Mat>Connect thispekko.stream.javadsl.SourceWithContextto apekko.stream.javadsl.Sink, concatenating the processing steps of both.<Mat2,Mat3>
RunnableGraph<Mat3>toMat(Graph<? extends SinkShape<? super Pair<Out, Ctx>>, Mat2> sink, Function2<? super Mat, ? super Mat2, ? extends Mat3> combine) Connect thispekko.stream.javadsl.SourceWithContextto apekko.stream.javadsl.Sink, concatenating the processing steps of both.<Out2,Mat2>
SourceWithContext<Out2,Ctx, Mat> unsafeDataVia(Graph<? extends FlowShape<? super Out, ? extends Out2>, Mat2> viaFlow) Transform this flow by the regular flow.static <SOut,FOut, Ctx, SMat, FMat, Mat>
SourceWithContext<Optional<FOut>,Ctx, Mat> unsafeOptionalDataVia(SourceWithContext<Optional<SOut>, Ctx, SMat> source, Flow<SOut, FOut, FMat> viaFlow, Function2<? super SMat, ? super FMat, ? extends 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> Transform this flow by the regular flow.withAttributes(Attributes attr) Context-preserving variant ofpekko.stream.javadsl.Source.withAttributes.Methods inherited from class org.apache.pekko.stream.GraphDelegate
addAttributes, async, async, async, getAttributes, named, shape, traversalBuilder
-
Constructor Details
-
SourceWithContext
-
-
Method Details
-
fromPairs
public static <Out,CtxOut, SourceWithContext<Out,Mat> CtxOut, fromPairsMat> (Source<Pair<Out, CtxOut>, Mat> under) Creates a SourceWithContext from a regular flow that operates onPair<data, context>elements. -
unsafeOptionalDataVia
public static <SOut,FOut, SourceWithContext<Optional<FOut>,Ctx, SMat, FMat, Mat> Ctx, unsafeOptionalDataViaMat> (SourceWithContext<Optional<SOut>, Ctx, SMat> source, Flow<SOut, FOut, FMat> viaFlow, Function2<? super SMat, ? super FMat, ? extends 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 Optional which indicates whether the original source's element had viaFlow applied.
- Since:
- 1.1.0
-
via
public <Out2,Ctx2, SourceWithContext<Out2,Mat2> Ctx2, viaMat> (Graph<? extends FlowShape<? super Pair<Out, Ctx>, ? extends 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).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.
- See Also:
-
pekko.stream.javadsl.Flow.via
-
unsafeDataVia
public <Out2,Mat2> SourceWithContext<Out2,Ctx, unsafeDataViaMat> (Graph<? extends FlowShape<? super Out, ? extends Out2>, Mat2> viaFlow) 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.
-
withAttributes
Context-preserving variant ofpekko.stream.javadsl.Source.withAttributes.- See Also:
-
pekko.stream.javadsl.Source.withAttributes
-
mapError
Context-preserving variant ofpekko.stream.javadsl.Source.mapError.- See Also:
-
pekko.stream.javadsl.Source.mapError
-
mapMaterializedValue
public <Mat2> SourceWithContext<Out,Ctx, mapMaterializedValueMat2> (Function<? super Mat, ? extends Mat2> f) Context-preserving variant ofpekko.stream.javadsl.Source.mapMaterializedValue.- See Also:
-
pekko.stream.javadsl.Flow.mapMaterializedValue
-
asSource
Stops automatic context propagation from here and converts this to a regular stream of a pair of (data, context). -
collect
Context-preserving variant ofpekko.stream.javadsl.Source.collect.Note, that the context of elements that are filtered out is skipped as well.
- See Also:
-
pekko.stream.javadsl.Source.collect
-
collectFirst
Context-preserving variant ofpekko.stream.javadsl.Source.collectFirst.Note, that the context of elements that are filtered out is skipped as well.
- Since:
- 2.0.0
- See Also:
-
pekko.stream.javadsl.Source.collectFirst
-
collectWhile
Context-preserving variant ofpekko.stream.javadsl.Source.collectWhile.Note, that the context of elements that are filtered out is skipped as well.
- Since:
- 2.0.0
- See Also:
-
pekko.stream.javadsl.Source.collectWhile
-
collectType
Context-preserving variant ofpekko.stream.javadsl.Source.collectType.Note, that the context of elements that are filtered out is skipped as well.
- Since:
- 2.0.0
- See Also:
-
pekko.stream.javadsl.Source.collectType
-
filter
Context-preserving variant ofpekko.stream.javadsl.Source.filter.Note, that the context of elements that are filtered out is skipped as well.
- See Also:
-
pekko.stream.javadsl.Source.filter
-
filterNot
Context-preserving variant ofpekko.stream.javadsl.Source.filterNot.Note, that the context of elements that are filtered out is skipped as well.
- See Also:
-
pekko.stream.javadsl.Source.filterNot
-
dropRepeated
Context-preserving variant ofpekko.stream.javadsl.Source.dropRepeated.- Since:
- 2.0.0
- See Also:
-
pekko.stream.javadsl.Source.dropRepeated
-
dropRepeated
Context-preserving variant ofpekko.stream.javadsl.Source.dropRepeated.- Since:
- 2.0.0
- See Also:
-
pekko.stream.javadsl.Source.dropRepeated
-
dropWhile
Context-preserving variant ofpekko.stream.javadsl.Source.dropWhile.- Since:
- 2.0.0
- See Also:
-
pekko.stream.javadsl.Source.dropWhile
-
drop
Context-preserving variant ofpekko.stream.javadsl.Source.drop.- Since:
- 2.0.0
- See Also:
-
pekko.stream.javadsl.Source.drop
-
dropWithin
Context-preserving variant ofpekko.stream.javadsl.Source.dropWithin.- Since:
- 2.0.0
- See Also:
-
pekko.stream.javadsl.Source.dropWithin
-
grouped
Context-preserving variant ofpekko.stream.javadsl.Source.grouped.Each output group will be associated with a
Seqof corresponding context elements.- See Also:
-
pekko.stream.javadsl.Source.grouped
-
map
Context-preserving variant ofpekko.stream.javadsl.Source.map.- See Also:
-
pekko.stream.javadsl.Source.map
-
mapOption
public <Out2> SourceWithContext<Out2,Ctx, mapOptionMat> (Function<? super Out, ? extends Optional<? extends Out2>> f) Context-preserving variant ofpekko.stream.javadsl.Source.mapOption.Note, that the context of elements that are filtered out is skipped as well.
- Since:
- 2.0.0
- See Also:
-
pekko.stream.javadsl.Source.mapOption
-
mapAsync
public <Out2> SourceWithContext<Out2,Ctx, mapAsyncMat> (int parallelism, Function<? super Out, ? extends CompletionStage<? extends Out2>> f) Context-preserving variant ofpekko.stream.javadsl.Source.mapAsync.- See Also:
-
pekko.stream.javadsl.Source.mapAsync
-
mapAsyncPartitioned
public <Out2,P> SourceWithContext<Out2,Ctx, mapAsyncPartitionedMat> (int parallelism, Function<? super Out, ? extends P> partitioner, Function2<? super Out, ? super P, ? extends CompletionStage<? extends Out2>> f) Context-preserving variant ofpekko.stream.javadsl.Source.mapAsyncPartitioned.- Since:
- 1.1.0
- See Also:
-
pekko.stream.javadsl.Source.mapAsyncPartitioned
-
mapAsyncPartitionedUnordered
public <Out2,P> SourceWithContext<Out2,Ctx, mapAsyncPartitionedUnorderedMat> (int parallelism, Function<? super Out, ? extends P> partitioner, Function2<? super Out, ? super P, ? extends CompletionStage<? extends Out2>> f) Context-preserving variant ofpekko.stream.javadsl.Source.mapAsyncPartitionedUnordered.- Since:
- 1.1.0
- See Also:
-
pekko.stream.javadsl.Source.mapAsyncPartitionedUnordered
-
mapConcat
public <Out2> SourceWithContext<Out2,Ctx, mapConcatMat> (Function<? super Out, ? extends Iterable<? extends Out2>> f) Context-preserving variant ofpekko.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)
- See Also:
-
pekko.stream.javadsl.Source.mapConcat
-
mapContext
public <Ctx2> SourceWithContext<Out,Ctx2, mapContextMat> (Function<? super Ctx, ? extends Ctx2> extractContext) Apply the given function to each context element (leaving the data elements unchanged). -
limit
Context-preserving variant ofpekko.stream.javadsl.Source.limit.- Since:
- 2.0.0
- See Also:
-
pekko.stream.javadsl.Source.limit
-
limitWeighted
Context-preserving variant ofpekko.stream.javadsl.Source.limitWeighted.- Since:
- 2.0.0
- See Also:
-
pekko.stream.javadsl.Source.limitWeighted
-
sliding
Context-preserving variant ofpekko.stream.javadsl.Source.sliding.Each output group will be associated with a
Seqof corresponding context elements.- See Also:
-
pekko.stream.javadsl.Source.sliding
-
sliding$default$2
public int sliding$default$2() -
log
public SourceWithContext<Out,Ctx, logMat> (String name, Function<? super Out, Object> extract, LoggingAdapter log) Context-preserving variant ofpekko.stream.javadsl.Source.log.- See Also:
-
pekko.stream.javadsl.Source.log
-
log
Context-preserving variant ofpekko.stream.javadsl.Flow.log.- See Also:
-
pekko.stream.javadsl.Flow.log
-
log
Context-preserving variant ofpekko.stream.javadsl.Flow.log.- See Also:
-
pekko.stream.javadsl.Flow.log
-
log
Context-preserving variant ofpekko.stream.javadsl.Flow.log.- See Also:
-
pekko.stream.javadsl.Flow.log
-
logWithMarker
public SourceWithContext<Out,Ctx, logWithMarkerMat> (String name, Function2<? super Out, ? super Ctx, ? extends LogMarker> marker, Function<? super Out, Object> extract, MarkerLoggingAdapter log) Context-preserving variant ofpekko.stream.javadsl.Source.logWithMarker.- See Also:
-
pekko.stream.javadsl.Source.logWithMarker
-
logWithMarker
public SourceWithContext<Out,Ctx, logWithMarkerMat> (String name, Function2<? super Out, ? super Ctx, ? extends LogMarker> marker, Function<? super Out, Object> extract) Context-preserving variant ofpekko.stream.javadsl.Flow.logWithMarker.,- See Also:
-
pekko.stream.javadsl.Flow.logWithMarker
-
logWithMarker
public SourceWithContext<Out,Ctx, logWithMarkerMat> (String name, Function2<? super Out, ? super Ctx, ? extends LogMarker> marker, MarkerLoggingAdapter log) Context-preserving variant ofpekko.stream.javadsl.Flow.logWithMarker.- See Also:
-
pekko.stream.javadsl.Flow.logWithMarker
-
logWithMarker
public SourceWithContext<Out,Ctx, logWithMarkerMat> (String name, Function2<? super Out, ? super Ctx, ? extends LogMarker> marker) Context-preserving variant ofpekko.stream.javadsl.Flow.logWithMarker.- See Also:
-
pekko.stream.javadsl.Flow.logWithMarker
-
takeWhile
Context-preserving variant ofpekko.stream.javadsl.Source.takeWhile.- Since:
- 2.0.0
- See Also:
-
pekko.stream.javadsl.Source.takeWhile
-
takeWhile
Context-preserving variant ofpekko.stream.javadsl.Source.takeWhile.- Since:
- 2.0.0
- See Also:
-
pekko.stream.javadsl.Source.takeWhile
-
takeUntil
Context-preserving variant ofpekko.stream.javadsl.Source.takeUntil.- Since:
- 2.0.0
- See Also:
-
pekko.stream.javadsl.Source.takeUntil
-
take
Context-preserving variant ofpekko.stream.javadsl.Source.take.- Since:
- 2.0.0
- See Also:
-
pekko.stream.javadsl.Source.take
-
takeWithin
Context-preserving variant ofpekko.stream.javadsl.Source.takeWithin.- Since:
- 2.0.0
- See Also:
-
pekko.stream.javadsl.Source.takeWithin
-
throttle
Context-preserving variant ofpekko.stream.javadsl.Source.throttle.- See Also:
-
pekko.stream.javadsl.Source.throttle
-
throttle
public SourceWithContext<Out,Ctx, throttleMat> (int elements, Duration per, int maximumBurst, ThrottleMode mode) Context-preserving variant ofpekko.stream.javadsl.Source.throttle.- See Also:
-
pekko.stream.javadsl.Source.throttle
-
throttle
public SourceWithContext<Out,Ctx, throttleMat> (int cost, Duration per, Function<? super Out, Integer> costCalculation) Context-preserving variant ofpekko.stream.javadsl.Source.throttle.- See Also:
-
pekko.stream.javadsl.Source.throttle
-
throttle
public SourceWithContext<Out,Ctx, throttleMat> (int cost, Duration per, int maximumBurst, Function<? super Out, Integer> costCalculation, ThrottleMode mode) Context-preserving variant ofpekko.stream.javadsl.Source.throttle.- See Also:
-
pekko.stream.javadsl.Source.throttle
-
to
Connect thispekko.stream.javadsl.SourceWithContextto apekko.stream.javadsl.Sink, concatenating the processing steps of both. -
toMat
public <Mat2,Mat3> RunnableGraph<Mat3> toMat(Graph<? extends SinkShape<? super Pair<Out, Ctx>>, Mat2> sink, Function2<? super Mat, ? super Mat2, ? extends Mat3> combine) Connect thispekko.stream.javadsl.SourceWithContextto apekko.stream.javadsl.Sink, concatenating the processing steps of both. -
runWith
public <M> M runWith(Graph<? extends SinkShape<? super Pair<Out, Ctx>>, M> sink, ClassicActorSystemProvider systemProvider) Connect thispekko.stream.javadsl.SourceWithContextto apekko.stream.javadsl.Sinkand run it. The returned value is the materialized value of theSink. -
runWith
public <M> M runWith(Graph<? extends SinkShape<? super Pair<Out, Ctx>>, M> sink, Materializer materializer) Connect thispekko.stream.javadsl.SourceWithContextto apekko.stream.javadsl.Sinkand run it. The returned value is the materialized value of theSink.Prefer the method taking an ActorSystem unless you have special requirements.
-
asScala
-