Class FlowWithContext<In,CtxIn,Out,CtxOut,Mat>
- java.lang.Object
-
public final class FlowWithContext<In,CtxIn,Out,CtxOut,Mat> extends org.apache.pekko.stream.GraphDelegate<FlowShape<Pair<In,CtxIn>,Pair<Out,CtxOut>>,Mat>
A flow that provides operations which automatically propagate the context of an element. Only a subset of common operations fromFlow
is supported. As an escape hatch you can useFlowWithContext.via
to manually provide the context propagation for otherwise unsupported operations.An "empty" flow can be created by calling
FlowWithContext[Ctx, T]
.
-
-
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 Flow<Pair<In,CtxIn>,Pair<Out,CtxOut>,Mat>
asFlow()
Creates a regular flow of pairs (data, context).FlowWithContext<In,CtxIn,Out,CtxOut,Mat>
asScala()
<Out2> FlowWithContext<In,CtxIn,Out2,CtxOut,Mat>
collect(scala.PartialFunction<Out,Out2> pf)
Context-preserving variant ofpekko.stream.javadsl.Flow.collect
.static <In,Ctx>
FlowWithContext<In,Ctx,In,Ctx,NotUsed>create()
FlowWithContext<In,CtxIn,Out,CtxOut,Mat>
filter(Predicate<Out> p)
Context-preserving variant ofpekko.stream.javadsl.Flow.filter
.FlowWithContext<In,CtxIn,Out,CtxOut,Mat>
filterNot(Predicate<Out> p)
Context-preserving variant ofpekko.stream.javadsl.Flow.filterNot
.static <In,CtxIn,Out,CtxOut,Mat>
FlowWithContext<In,CtxIn,Out,CtxOut,Mat>fromPairs(Flow<Pair<In,CtxIn>,Pair<Out,CtxOut>,Mat> under)
Creates a FlowWithContext from a regular flow that operates onPair
elements.FlowWithContext<In,CtxIn,java.util.List<Out>,java.util.List<CtxOut>,Mat>
grouped(int n)
Context-preserving variant ofpekko.stream.javadsl.Flow.grouped
.FlowWithContext<In,CtxIn,Out,CtxOut,Mat>
log(java.lang.String name)
Context-preserving variant ofpekko.stream.javadsl.Flow.log
.FlowWithContext<In,CtxIn,Out,CtxOut,Mat>
log(java.lang.String name, LoggingAdapter log)
Context-preserving variant ofpekko.stream.javadsl.Flow.log
.FlowWithContext<In,CtxIn,Out,CtxOut,Mat>
log(java.lang.String name, Function<Out,java.lang.Object> extract)
Context-preserving variant ofpekko.stream.javadsl.Flow.log
.FlowWithContext<In,CtxIn,Out,CtxOut,Mat>
log(java.lang.String name, Function<Out,java.lang.Object> extract, LoggingAdapter log)
Context-preserving variant ofpekko.stream.javadsl.Flow.log
.FlowWithContext<In,CtxIn,Out,CtxOut,Mat>
logWithMarker(java.lang.String name, Function2<Out,CtxOut,LogMarker> marker)
Context-preserving variant ofpekko.stream.javadsl.Flow.logWithMarker
.FlowWithContext<In,CtxIn,Out,CtxOut,Mat>
logWithMarker(java.lang.String name, Function2<Out,CtxOut,LogMarker> marker, MarkerLoggingAdapter log)
Context-preserving variant ofpekko.stream.javadsl.Flow.logWithMarker
.FlowWithContext<In,CtxIn,Out,CtxOut,Mat>
logWithMarker(java.lang.String name, Function2<Out,CtxOut,LogMarker> marker, Function<Out,java.lang.Object> extract)
Context-preserving variant ofpekko.stream.javadsl.Flow.logWithMarker
.FlowWithContext<In,CtxIn,Out,CtxOut,Mat>
logWithMarker(java.lang.String name, Function2<Out,CtxOut,LogMarker> marker, Function<Out,java.lang.Object> extract, MarkerLoggingAdapter log)
Context-preserving variant ofpekko.stream.javadsl.Flow.logWithMarker
.<Out2> FlowWithContext<In,CtxIn,Out2,CtxOut,Mat>
map(Function<Out,Out2> f)
Context-preserving variant ofpekko.stream.javadsl.Flow.map
.<Out2> FlowWithContext<In,CtxIn,Out2,CtxOut,Mat>
mapAsync(int parallelism, Function<Out,java.util.concurrent.CompletionStage<Out2>> f)
Context-preserving variant ofpekko.stream.javadsl.Flow.mapAsync
.<Out2,P>
FlowWithContext<In,CtxIn,Out2,CtxOut,Mat>mapAsyncPartitioned(int parallelism, Function<Out,P> partitioner, Function2<Out,P,java.util.concurrent.CompletionStage<Out2>> f)
Context-preserving variant ofpekko.stream.javadsl.Flow.mapAsyncPartitioned
.<Out2,P>
FlowWithContext<In,CtxIn,Out2,CtxOut,Mat>mapAsyncPartitionedUnordered(int parallelism, Function<Out,P> partitioner, Function2<Out,P,java.util.concurrent.CompletionStage<Out2>> f)
Context-preserving variant ofpekko.stream.javadsl.Flow.mapAsyncPartitionedUnordered
.<Out2> FlowWithContext<In,CtxIn,Out2,CtxOut,Mat>
mapConcat(Function<Out,? extends java.lang.Iterable<Out2>> f)
Context-preserving variant ofpekko.stream.javadsl.Flow.mapConcat
.<CtxOut2> FlowWithContext<In,CtxIn,Out,CtxOut2,Mat>
mapContext(Function<CtxOut,CtxOut2> extractContext)
Apply the given function to each context element (leaving the data elements unchanged).FlowWithContext<In,CtxIn,Out,CtxOut,Mat>
mapError(scala.PartialFunction<java.lang.Throwable,java.lang.Throwable> pf)
Context-preserving variant ofpekko.stream.javadsl.Flow.mapError
.<Mat2> FlowWithContext<In,CtxIn,Out,CtxOut,Mat2>
mapMaterializedValue(Function<Mat,Mat2> f)
Context-preserving variant ofpekko.stream.javadsl.Flow.mapMaterializedValue
.FlowWithContext<In,CtxIn,java.util.List<Out>,java.util.List<CtxOut>,Mat>
sliding(int n, int step)
Context-preserving variant ofpekko.stream.javadsl.Flow.sliding
.int
sliding$default$2()
FlowWithContext<In,CtxIn,Out,CtxOut,Mat>
throttle(int elements, java.time.Duration per)
Context-preserving variant ofpekko.stream.javadsl.Flow.throttle
.FlowWithContext<In,CtxIn,Out,CtxOut,Mat>
throttle(int cost, java.time.Duration per, int maximumBurst, Function<Out,java.lang.Integer> costCalculation, ThrottleMode mode)
Context-preserving variant ofpekko.stream.javadsl.Flow.throttle
.FlowWithContext<In,CtxIn,Out,CtxOut,Mat>
throttle(int elements, java.time.Duration per, int maximumBurst, ThrottleMode mode)
Context-preserving variant ofpekko.stream.javadsl.Flow.throttle
.FlowWithContext<In,CtxIn,Out,CtxOut,Mat>
throttle(int cost, java.time.Duration per, Function<Out,java.lang.Integer> costCalculation)
Context-preserving variant ofpekko.stream.javadsl.Flow.throttle
.<Out2,Mat2>
FlowWithContext<In,CtxIn,Out2,CtxOut,Mat>unsafeDataVia(Graph<FlowShape<Out,Out2>,Mat2> viaFlow)
Transform this flow by the regular flow.static <FIn,FOut,FViaOut,Ctx,FMat,FViaMat,Mat>
FlowWithContext<FIn,Ctx,java.util.Optional<FViaOut>,Ctx,Mat>unsafeOptionalDataVia(FlowWithContext<FIn,Ctx,java.util.Optional<FOut>,Ctx,FMat> flow, Flow<FOut,FViaOut,FViaMat> viaFlow, 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.<Out2,CtxOut2,Mat2>
FlowWithContext<In,CtxIn,Out2,CtxOut2,Mat>via(Graph<FlowShape<Pair<Out,CtxOut>,Pair<Out2,CtxOut2>>,Mat2> viaFlow)
Transform this flow by the regular flow.FlowWithContext<In,CtxIn,Out,CtxOut,Mat>
withAttributes(Attributes attr)
Context-preserving variant ofpekko.stream.javadsl.Flow.withAttributes
.
-
-
-
Method Detail
-
create
public static <In,Ctx> FlowWithContext<In,Ctx,In,Ctx,NotUsed> create()
-
fromPairs
public static <In,CtxIn,Out,CtxOut,Mat> FlowWithContext<In,CtxIn,Out,CtxOut,Mat> fromPairs(Flow<Pair<In,CtxIn>,Pair<Out,CtxOut>,Mat> under)
Creates a FlowWithContext from a regular flow that operates onPair
elements.
-
unsafeOptionalDataVia
public static <FIn,FOut,FViaOut,Ctx,FMat,FViaMat,Mat> FlowWithContext<FIn,Ctx,java.util.Optional<FViaOut>,Ctx,Mat> unsafeOptionalDataVia(FlowWithContext<FIn,Ctx,java.util.Optional<FOut>,Ctx,FMat> flow, Flow<FOut,FViaOut,FViaMat> viaFlow, 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 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 flow and viaFlow- Returns:
- a FlowWithContext with the viaFlow applied onto defined elements of the flow. The output value is contained within an Optional which indicates whether the original flow's element had viaFlow applied.
- Since:
- 1.1.0
-
via
public <Out2,CtxOut2,Mat2> FlowWithContext<In,CtxIn,Out2,CtxOut2,Mat> via(Graph<FlowShape<Pair<Out,CtxOut>,Pair<Out2,CtxOut2>>,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> FlowWithContext<In,CtxIn,Out2,CtxOut,Mat> unsafeDataVia(Graph<FlowShape<Out,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
public FlowWithContext<In,CtxIn,Out,CtxOut,Mat> withAttributes(Attributes attr)
Context-preserving variant ofpekko.stream.javadsl.Flow.withAttributes
.- See Also:
pekko.stream.javadsl.Flow.withAttributes
-
mapError
public FlowWithContext<In,CtxIn,Out,CtxOut,Mat> mapError(scala.PartialFunction<java.lang.Throwable,java.lang.Throwable> pf)
Context-preserving variant ofpekko.stream.javadsl.Flow.mapError
.- See Also:
pekko.stream.javadsl.Flow.mapError
-
mapMaterializedValue
public <Mat2> FlowWithContext<In,CtxIn,Out,CtxOut,Mat2> mapMaterializedValue(Function<Mat,Mat2> f)
Context-preserving variant ofpekko.stream.javadsl.Flow.mapMaterializedValue
.- See Also:
pekko.stream.javadsl.Flow.mapMaterializedValue
-
asFlow
public Flow<Pair<In,CtxIn>,Pair<Out,CtxOut>,Mat> asFlow()
Creates a regular flow of pairs (data, context).
-
collect
public <Out2> FlowWithContext<In,CtxIn,Out2,CtxOut,Mat> collect(scala.PartialFunction<Out,Out2> pf)
Context-preserving variant ofpekko.stream.javadsl.Flow.collect
.Note, that the context of elements that are filtered out is skipped as well.
- See Also:
pekko.stream.javadsl.Flow.collect
-
filter
public FlowWithContext<In,CtxIn,Out,CtxOut,Mat> filter(Predicate<Out> p)
Context-preserving variant ofpekko.stream.javadsl.Flow.filter
.Note, that the context of elements that are filtered out is skipped as well.
- See Also:
pekko.stream.javadsl.Flow.filter
-
filterNot
public FlowWithContext<In,CtxIn,Out,CtxOut,Mat> filterNot(Predicate<Out> p)
Context-preserving variant ofpekko.stream.javadsl.Flow.filterNot
.Note, that the context of elements that are filtered out is skipped as well.
- See Also:
pekko.stream.javadsl.Flow.filterNot
-
grouped
public FlowWithContext<In,CtxIn,java.util.List<Out>,java.util.List<CtxOut>,Mat> grouped(int n)
Context-preserving variant ofpekko.stream.javadsl.Flow.grouped
.Each output group will be associated with a
Seq
of corresponding context elements.- See Also:
pekko.stream.javadsl.Flow.grouped
-
map
public <Out2> FlowWithContext<In,CtxIn,Out2,CtxOut,Mat> map(Function<Out,Out2> f)
Context-preserving variant ofpekko.stream.javadsl.Flow.map
.- See Also:
pekko.stream.javadsl.Flow.map
-
mapAsync
public <Out2> FlowWithContext<In,CtxIn,Out2,CtxOut,Mat> mapAsync(int parallelism, Function<Out,java.util.concurrent.CompletionStage<Out2>> f)
Context-preserving variant ofpekko.stream.javadsl.Flow.mapAsync
.- See Also:
pekko.stream.javadsl.Flow.mapAsync
-
mapAsyncPartitioned
public <Out2,P> FlowWithContext<In,CtxIn,Out2,CtxOut,Mat> mapAsyncPartitioned(int parallelism, Function<Out,P> partitioner, Function2<Out,P,java.util.concurrent.CompletionStage<Out2>> f)
Context-preserving variant ofpekko.stream.javadsl.Flow.mapAsyncPartitioned
.- Since:
- 1.1.0
- See Also:
pekko.stream.javadsl.Flow.mapAsyncPartitioned
-
mapAsyncPartitionedUnordered
public <Out2,P> FlowWithContext<In,CtxIn,Out2,CtxOut,Mat> mapAsyncPartitionedUnordered(int parallelism, Function<Out,P> partitioner, Function2<Out,P,java.util.concurrent.CompletionStage<Out2>> f)
Context-preserving variant ofpekko.stream.javadsl.Flow.mapAsyncPartitionedUnordered
.- Since:
- 1.1.0
- See Also:
pekko.stream.javadsl.Flow.mapAsyncPartitionedUnordered
-
mapConcat
public <Out2> FlowWithContext<In,CtxIn,Out2,CtxOut,Mat> mapConcat(Function<Out,? extends java.lang.Iterable<Out2>> f)
Context-preserving variant ofpekko.stream.javadsl.Flow.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.Flow.mapConcat
-
mapContext
public <CtxOut2> FlowWithContext<In,CtxIn,Out,CtxOut2,Mat> mapContext(Function<CtxOut,CtxOut2> extractContext)
Apply the given function to each context element (leaving the data elements unchanged).
-
sliding
public FlowWithContext<In,CtxIn,java.util.List<Out>,java.util.List<CtxOut>,Mat> sliding(int n, int step)
Context-preserving variant ofpekko.stream.javadsl.Flow.sliding
.Each output group will be associated with a
Seq
of corresponding context elements.- See Also:
pekko.stream.javadsl.Flow.sliding
-
sliding$default$2
public int sliding$default$2()
-
log
public FlowWithContext<In,CtxIn,Out,CtxOut,Mat> log(java.lang.String name, Function<Out,java.lang.Object> extract, LoggingAdapter log)
Context-preserving variant ofpekko.stream.javadsl.Flow.log
.- See Also:
pekko.stream.javadsl.Flow.log
-
log
public FlowWithContext<In,CtxIn,Out,CtxOut,Mat> log(java.lang.String name, Function<Out,java.lang.Object> extract)
Context-preserving variant ofpekko.stream.javadsl.Flow.log
.- See Also:
pekko.stream.javadsl.Flow.log
-
log
public FlowWithContext<In,CtxIn,Out,CtxOut,Mat> log(java.lang.String name, LoggingAdapter log)
Context-preserving variant ofpekko.stream.javadsl.Flow.log
.- See Also:
pekko.stream.javadsl.Flow.log
-
log
public FlowWithContext<In,CtxIn,Out,CtxOut,Mat> log(java.lang.String name)
Context-preserving variant ofpekko.stream.javadsl.Flow.log
.- See Also:
pekko.stream.javadsl.Flow.log
-
logWithMarker
public FlowWithContext<In,CtxIn,Out,CtxOut,Mat> logWithMarker(java.lang.String name, Function2<Out,CtxOut,LogMarker> marker, Function<Out,java.lang.Object> extract, MarkerLoggingAdapter log)
Context-preserving variant ofpekko.stream.javadsl.Flow.logWithMarker
.- See Also:
pekko.stream.javadsl.Flow.logWithMarker
-
logWithMarker
public FlowWithContext<In,CtxIn,Out,CtxOut,Mat> logWithMarker(java.lang.String name, Function2<Out,CtxOut,LogMarker> marker, Function<Out,java.lang.Object> extract)
Context-preserving variant ofpekko.stream.javadsl.Flow.logWithMarker
.- See Also:
pekko.stream.javadsl.Flow.logWithMarker
-
logWithMarker
public FlowWithContext<In,CtxIn,Out,CtxOut,Mat> logWithMarker(java.lang.String name, Function2<Out,CtxOut,LogMarker> marker, MarkerLoggingAdapter log)
Context-preserving variant ofpekko.stream.javadsl.Flow.logWithMarker
.- See Also:
pekko.stream.javadsl.Flow.logWithMarker
-
logWithMarker
public FlowWithContext<In,CtxIn,Out,CtxOut,Mat> logWithMarker(java.lang.String name, Function2<Out,CtxOut,LogMarker> marker)
Context-preserving variant ofpekko.stream.javadsl.Flow.logWithMarker
.- See Also:
pekko.stream.javadsl.Flow.logWithMarker
-
throttle
public FlowWithContext<In,CtxIn,Out,CtxOut,Mat> throttle(int elements, java.time.Duration per)
Context-preserving variant ofpekko.stream.javadsl.Flow.throttle
.- See Also:
pekko.stream.javadsl.Flow.throttle
-
throttle
public FlowWithContext<In,CtxIn,Out,CtxOut,Mat> throttle(int elements, java.time.Duration per, int maximumBurst, ThrottleMode mode)
Context-preserving variant ofpekko.stream.javadsl.Flow.throttle
.- See Also:
pekko.stream.javadsl.Flow.throttle
-
throttle
public FlowWithContext<In,CtxIn,Out,CtxOut,Mat> throttle(int cost, java.time.Duration per, Function<Out,java.lang.Integer> costCalculation)
Context-preserving variant ofpekko.stream.javadsl.Flow.throttle
.- See Also:
pekko.stream.javadsl.Flow.throttle
-
throttle
public FlowWithContext<In,CtxIn,Out,CtxOut,Mat> throttle(int cost, java.time.Duration per, int maximumBurst, Function<Out,java.lang.Integer> costCalculation, ThrottleMode mode)
Context-preserving variant ofpekko.stream.javadsl.Flow.throttle
.- See Also:
pekko.stream.javadsl.Flow.throttle
-
-