Top Description Constructors Methods
reactor.core.publisher

public abstract Class ParallelFlux<T>

extends Object
implements CorePublisher<T>
Class Inheritance
All Implemented Interfaces
reactor.core.CorePublisher, org.reactivestreams.Publisher
Known Direct Subclasses
reactor.core.publisher.ParallelFluxHide, reactor.core.publisher.ParallelFluxName, reactor.core.publisher.ParallelFluxOnAssembly, reactor.core.publisher.ParallelFluxRestoringThreadLocals, reactor.core.publisher.ParallelLift, reactor.core.publisher.ParallelLiftFuseable, reactor.core.publisher.ParallelLog, reactor.core.publisher.ParallelMap, reactor.core.publisher.ParallelPeek, reactor.core.publisher.ParallelReduceSeed, reactor.core.publisher.ParallelRunOn, reactor.core.publisher.ParallelSource, reactor.core.publisher.ParallelArraySource, reactor.core.publisher.ParallelCollect, reactor.core.publisher.ParallelConcatMap, reactor.core.publisher.ParallelDoOnEach, reactor.core.publisher.ParallelFilter, reactor.core.publisher.ParallelFlatMap
Type Parameters
<T>
the value type
Imports
java.util.ArrayList, .Comparator, .Iterator, .List, .Objects, .Queue, .Set, java.util.function.BiConsumer, .BiFunction, .Consumer, .Function, .LongConsumer, .Predicate, .Supplier, java.util.logging.Level, org.reactivestreams.Publisher, .Subscriber, .Subscription, reactor.core.CorePublisher, .CoreSubscriber, .Disposable, .Disposables, .Exceptions, .Scannable, reactor.core.publisher.FluxConcatMap.ErrorMode, .FluxOnAssembly.CheckpointHeavySnapshot, .FluxOnAssembly.CheckpointLightSnapshot, .FluxOnAssembly.AssemblySnapshot, reactor.core.scheduler.Scheduler, .Schedulers, reactor.util.Logger, reactor.util.annotation.Nullable, reactor.util.concurrent.Queues, reactor.util.context.Context

A ParallelFlux publishes to an array of Subscribers, in parallel 'rails' (or 'groups').

Use from to start processing a regular Publisher in 'rails', which each cover a subset of the original Publisher's data. Flux#parallel() is a convenient shortcut to achieve that on a Flux.

Use runOn to introduce where each 'rail' should run on thread-wise.

Use sequential to merge the sources back into a single Flux.

Use then to listen for all rails termination in the produced Mono

subscribe(Subscriber) if you simply want to subscribe to the merged sequence. Note that other variants like subscribe(Consumer) instead do multiple subscribes, one on each rail (which means that the lambdas should be as stateless and side-effect free as possible).

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public final <
the output value type
U
>
U

Returns:

the value returned by the converter function
as
(Function<? super ParallelFlux<T>, U>
the converter function from ParallelFlux to some type
converter
)

Perform a fluent transformation to a value via a converter function which receives this ParallelFlux.

public final ParallelFlux<T>

Returns:

the assembly tracing ParallelFlux
checkpoint
()

Activate traceback (full assembly tracing) for this particular ParallelFlux, in case of an error upstream of the checkpoint.

public final ParallelFlux<T>

Returns:

the assembly marked ParallelFlux
checkpoint
(String
a unique enough description to include in the light assembly traceback.
description
)

Activate traceback (assembly marker) for this particular ParallelFlux by giving it a description that will be reflected in the assembly traceback in case of an error upstream of the checkpoint.

public final ParallelFlux<T>

Returns:

the assembly marked ParallelFlux.
checkpoint
(String
a description (must be unique enough if forceStackTrace is set to false).
description
,
boolean
false to make a light checkpoint without a stacktrace, true to use a stack trace.
forceStackTrace
)

Activate traceback (full assembly tracing or the lighter assembly marking depending on the forceStackTrace option).

public final <
the collection type
C
>
ParallelFlux<C>

Returns:

the new ParallelFlux instance
collect
(Supplier<? extends C>
the supplier of the collection in each rail
collectionSupplier
,
BiConsumer<? super C, ? super T>
the collector, taking the per-rail collection and the current item
collector
)

Collect the elements in each rail into a collection supplied via a collectionSupplier and collected into with a collector action, emitting the collection at the end.

public final Mono<List<T>>

Returns:

the new Flux instance
collectSortedList
(Comparator<? super T>
the comparator to compare elements
comparator
)

Sorts the 'rails' according to the comparator and returns a full sorted list as a Publisher.

public final Mono<List<T>>

Returns:

the new Mono instance
collectSortedList
(Comparator<? super T>
the comparator to compare elements
comparator
,
int
the expected number of total elements
capacityHint
)

Sorts the 'rails' according to the comparator and returns a full sorted list as a Publisher.

public final <
the result type
R
>
ParallelFlux<R>

Returns:

the new ParallelFlux instance
concatMap
(Function<? super T, ? extends Publisher<? extends R>>
the function to map each rail's value into a Publisher source and the inner Publishers (immediate, boundary, end)
mapper
)

Generates and concatenates Publishers on each 'rail', signalling errors immediately and generating 2 publishers upfront.

public final <
the result type
R
>
ParallelFlux<R>

Returns:

the new ParallelFlux instance
concatMap
(Function<? super T, ? extends Publisher<? extends R>>
the function to map each rail's value into a Publisher
mapper
,
int
the number of items to prefetch from each inner Publisher source and the inner Publishers (immediate, boundary, end)
prefetch
)

Generates and concatenates Publishers on each 'rail', signalling errors immediately and using the given prefetch amount for generating Publishers upfront.

pack-priv final <
the result type
R
>
ParallelFlux<R>

Returns:

the new ParallelFlux instance
concatMap
(Function<? super T, ? extends Publisher<? extends R>>
the function to map each rail's value into a Publisher
mapper
,
int
the number of items to prefetch from each inner Publisher
prefetch
,
FluxConcatMap.ErrorMode
the error handling, i.e., when to report errors from the main source and the inner Publishers (immediate, boundary, end)
errorMode
)

Generates and concatenates Publishers on each 'rail', optionally delaying errors and using the given prefetch amount for generating Publishers upfront.

public final <
the result type
R
>
ParallelFlux<R>

Returns:

the new ParallelFlux instance
concatMapDelayError
(Function<? super T, ? extends Publisher<? extends R>>
the function to map each rail's value into a Publisher source and the inner Publishers (immediate, boundary, end)
mapper
)

Generates and concatenates Publishers on each 'rail', delaying errors and generating 2 publishers upfront.

pack-priv final <
the result type
R
>
ParallelFlux<R>

Returns:

the new ParallelFlux instance
concatMapDelayError
(Function<? super T, ? extends Publisher<? extends R>>
the function to map each rail's value into a Publisher
mapper
,
boolean
true if delayed until all sources are concatenated
delayUntilEnd
,
int
the number of items to prefetch from each inner Publisher source and the inner Publishers (immediate, boundary, end)
prefetch
)

Generates and concatenates Publishers on each 'rail', delaying errors and using the given prefetch amount for generating Publishers upfront.

pack-priv final <
the result type
R
>
ParallelFlux<R>

Returns:

the new ParallelFlux instance
concatMapDelayError
(Function<? super T, ? extends Publisher<? extends R>>
the function to map each rail's value into a Publisher
mapper
,
int
the number of items to prefetch from each inner Publisher source and the inner Publishers (immediate, boundary, end)
prefetch
)

Generates and concatenates Publishers on each 'rail', delaying errors and using the given prefetch amount for generating Publishers upfront.

public final ParallelFlux<T>

Returns:

the new ParallelFlux instance
doAfterTerminate
(Runnable
the callback
afterTerminate
)

Run the specified runnable when a 'rail' completes or signals an error.

public final ParallelFlux<T>

Returns:

the new ParallelFlux instance
doOnCancel
(Runnable
the callback
onCancel
)

Run the specified runnable when a 'rail' receives a cancellation.

public final ParallelFlux<T>

Returns:

the new ParallelFlux instance
doOnComplete
(Runnable
the callback
onComplete
)

Run the specified runnable when a 'rail' completes.

public final ParallelFlux<T>

Returns:

an observed ParallelFlux
doOnEach
(Consumer<? super Signal<T>> signalConsumer)

Triggers side-effects when the ParallelFlux emits an item, fails with an error or completes successfully.

public final ParallelFlux<T>

Returns:

the new ParallelFlux instance
doOnError
(Consumer<? super Throwable>
the callback
onError
)

Call the specified consumer with the exception passing through any 'rail'.

public final ParallelFlux<T>

Returns:

the new ParallelFlux instance
doOnNext
(Consumer<? super T>
the callback
onNext
)

Call the specified consumer with the current element passing through any 'rail'.

public final ParallelFlux<T>

Returns:

the new ParallelFlux instance
doOnRequest
(LongConsumer
the callback
onRequest
)

Call the specified consumer with the request amount if any rail receives a request.

pack-priv static <T> ParallelFlux<T>
doOnSignal(ParallelFlux<T> source, Consumer<? super T> onNext, Consumer<? super T> onAfterNext, Consumer<? super Throwable> onError, Runnable onComplete, Runnable onAfterTerminate, Consumer<? super Subscription> onSubscribe, LongConsumer onRequest, Runnable onCancel)

public final ParallelFlux<T>

Returns:

the new ParallelFlux instance
doOnSubscribe
(Consumer<? super Subscription>
the callback
onSubscribe
)

Call the specified callback when a 'rail' receives a Subscription from its upstream.

public final ParallelFlux<T>

Returns:

an observed ParallelFlux
doOnTerminate
(Runnable
the callback to call on Subscriber#onComplete or Subscriber#onError
onTerminate
)

Triggered when the ParallelFlux terminates, either by completing successfully or with an error.

public final ParallelFlux<T>

Returns:

the new ParallelFlux instance
filter
(Predicate<? super T>
the function returning true to keep a value or false to drop a value
predicate
)

Filters the source values on each 'rail'.

public final <
the result type
R
>
ParallelFlux<R>

Returns:

the new ParallelFlux instance
flatMap
(Function<? super T, ? extends Publisher<? extends R>>
the function to map each rail's value into a Publisher
mapper
)

Generates and flattens Publishers on each 'rail'.

public final <
the result type
R
>
ParallelFlux<R>

Returns:

the new ParallelFlux instance
flatMap
(Function<? super T, ? extends Publisher<? extends R>>
the function to map each rail's value into a Publisher
mapper
,
boolean
should the errors from the main and the inner sources delayed till everybody terminates?
delayError
)

Generates and flattens Publishers on each 'rail', optionally delaying errors.

public final <
the result type
R
>
ParallelFlux<R>

Returns:

the new ParallelFlux instance
flatMap
(Function<? super T, ? extends Publisher<? extends R>>
the function to map each rail's value into a Publisher
mapper
,
boolean
should the errors from the main and the inner sources delayed till everybody terminates?
delayError
,
int
the maximum number of simultaneous subscriptions to the generated inner Publishers
maxConcurrency
)

Generates and flattens Publishers on each 'rail', optionally delaying errors and having a total number of simultaneous subscriptions to the inner Publishers.

public final <
the result type
R
>
ParallelFlux<R>

Returns:

the new ParallelFlux instance
flatMap
(Function<? super T, ? extends Publisher<? extends R>>
the function to map each rail's value into a Publisher
mapper
,
boolean
should the errors from the main and the inner sources delayed till everybody terminates?
delayError
,
int
the maximum number of simultaneous subscriptions to the generated inner Publishers
maxConcurrency
,
int
the number of items to prefetch from each inner Publisher
prefetch
)

Generates and flattens Publishers on each 'rail', optionally delaying errors, having a total number of simultaneous subscriptions to the inner Publishers and using the given prefetch amount for the inner Publishers.

pack-priv static <T> ParallelFlux<T>
from(ParallelFlux<T> source)

public static <
the value type
T
>
ParallelFlux<T>

Returns:

the ParallelFlux instance
from
(Publisher<? extends T>
the source Publisher
source
)

Take a Publisher and prepare to consume it on multiple 'rails' (one per CPU core) in a round-robin fashion.

public static <
the value type
T
>
ParallelFlux<T>

Returns:

the new ParallelFlux instance
from
(Publisher<? extends T>
the source Publisher
source
,
int
the number of parallel rails
parallelism
)

Take a Publisher and prepare to consume it on parallelism number of 'rails', possibly ordered and in a round-robin fashion.

public static <
the value type
T
>
ParallelFlux<T>

Returns:

the new ParallelFlux instance
from
(Publisher<? extends T>
the source Publisher
source
,
int
the number of parallel rails
parallelism
,
int
the number of values to prefetch from the source
prefetch
,
Supplier<Queue<T>>
the queue structure supplier to hold the prefetched values from the source until there is a rail ready to process it.
queueSupplier
)

Take a Publisher and prepare to consume it on parallelism number of 'rails' and in a round-robin fashion and use custom prefetch amount and queue for dealing with the source Publisher's values.

public static <
the value type
T
>
ParallelFlux<T>

Returns:

the new ParallelFlux instance
from
(Publisher<T>...
the array of publishers
publishers
)

Wraps multiple Publishers into a ParallelFlux which runs them in parallel and unordered.

public int

Returns:

the prefetch configuration of the component
getPrefetch
()

The prefetch configuration of the component

public final Flux<GroupedFlux<Integer, T>>

Returns:

the new Flux instance
groups
()

Exposes the 'rails' as individual GroupedFlux instances, keyed by the rail index (zero based).

public final ParallelFlux<T>

Returns:

a new ParallelFlux defeating any Publisher / Subscription feature-detection
hide
()

Hides the identities of this ParallelFlux and its Subscription as well.

public final ParallelFlux<T>

Returns:

a new unaltered ParallelFlux
log
()

Observe all Reactive Streams signals and use Logger support to handle trace implementation.

public final ParallelFlux<T>

Returns:

a new unaltered ParallelFlux
log
(String
to be mapped into logger configuration (e.g. org.springframework .reactor). If category ends with "." like "reactor.", a generated operator suffix will complete, e.g. "reactor.Parallel.Map".
category
)

Observe all Reactive Streams signals and use Logger support to handle trace implementation.

public final ParallelFlux<T>

Returns:

a new unaltered ParallelFlux
log
(String
to be mapped into logger configuration (e.g. org.springframework .reactor). If category ends with "." like "reactor.", a generated operator suffix will complete, e.g. "reactor.Parallel.Map".
category
,
Level
the Level to enforce for this tracing ParallelFlux (only FINEST, FINE, INFO, WARNING and SEVERE are taken into account)
level
,
SignalType...
a vararg SignalType option to filter log messages
options
)

Observe Reactive Streams signals matching the passed filter options and use Logger support to handle trace implementation.

public final ParallelFlux<T>

Returns:

a new unaltered ParallelFlux
log
(String
to be mapped into logger configuration (e.g. org.springframework .reactor). If category ends with "." like "reactor.", a generated operator suffix will complete, e.g. "reactor.ParallelFlux.Map".
category
,
Level
the Level to enforce for this tracing ParallelFlux (only FINEST, FINE, INFO, WARNING and SEVERE are taken into account)
level
,
boolean
capture the current stack to display operator class/line number.
showOperatorLine
,
SignalType...
a vararg SignalType option to filter log messages
options
)

Observe Reactive Streams signals matching the passed filter options and use Logger support to handle trace implementation.

public final <
the output value type
U
>
ParallelFlux<U>

Returns:

the new ParallelFlux instance
map
(Function<? super T, ? extends U>
the mapper function turning Ts into Us.
mapper
)

Maps the source values on each 'rail' to another value.

public final ParallelFlux<T>

Returns:

the same sequence, but bearing a name
name
(String
a name for the sequence
name
)

Give a name to this sequence, which can be retrieved using Scannable#name() as long as this is the first reachable Scannable#parents().

protected static <
the value type
T
>
ParallelFlux<T>

Returns:

the potentially wrapped source
onAssembly
(ParallelFlux<T>
the source to wrap
source
)

Invoke Hooks pointcut given a ParallelFlux and returning an eventually new ParallelFlux

public final Flux<T>

Returns:

the new Flux instance
ordered
(Comparator<? super T>
the comparator to choose the smallest value available from all rails
comparator
)

Merges the values from each 'rail', but choose which one to merge by way of a provided Comparator, picking the smallest of all rails.

public final Flux<T>

Returns:

the new Flux instance
ordered
(Comparator<? super T>
the comparator to choose the smallest value available from all rails
comparator
,
int
the prefetch to use
prefetch
)

Merges the values from each 'rail', but choose which one to merge by way of a provided Comparator, picking the smallest of all rails.

public abstract int

Returns:

the number of expected parallel Subscribers
parallelism
()

Returns the number of expected parallel Subscribers.

public final Mono<T>

Returns:

the new Mono instance emitting the reduced value or empty if the ParallelFlux was empty
reduce
(BiFunction<T, T, T>
the function to reduce two values into one.
reducer
)

Reduces all values within a 'rail' and across 'rails' with a reducer function into a single sequential value.

public final <
the reduced output type
R
>
ParallelFlux<R>

Returns:

the new ParallelFlux instance
reduce
(Supplier<R>
the supplier for the initial value
initialSupplier
,
BiFunction<R, ? super T, R>
the function to reduce a previous output of reduce (or the initial value supplied) with a current source value.
reducer
)

Reduces all values within a 'rail' to a single value (with a possibly different type) via a reducer function that is initialized on each rail from an initialSupplier value.

public final ParallelFlux<T>

Returns:

the new ParallelFlux instance
runOn
(Scheduler
the scheduler to use
scheduler
)

Specifies where each 'rail' will observe its incoming values with possible work-stealing and default prefetch amount.

public final ParallelFlux<T>

Returns:

the new ParallelFlux instance
runOn
(Scheduler
the scheduler to use that rail's worker has run out of work.
scheduler
,
int
the number of values to request on each 'rail' from the source
prefetch
)

Specifies where each 'rail' will observe its incoming values with possible work-stealing and a given prefetch amount.

public final Flux<T>

Returns:

the new Flux instance
sequential
()

Merges the values from each 'rail' in a round-robin or same-order fashion and exposes it as a regular Publisher sequence, running with a default prefetch value for the rails.

public final Flux<T>

Returns:

the new Flux instance
sequential
(int
the prefetch amount to use for each rail
prefetch
)

Merges the values from each 'rail' in a round-robin or same-order fashion and exposes it as a regular Publisher sequence, running with a give prefetch value for the rails.

public final Flux<T>

Returns:

the new Flux instance
sorted
(Comparator<? super T>
the comparator to use
comparator
)

Sorts the 'rails' of this ParallelFlux and returns a Publisher that sequentially picks the smallest next value from the rails.

public final Flux<T>

Returns:

the new Flux instance
sorted
(Comparator<? super T>
the comparator to use
comparator
,
int
the expected number of total elements
capacityHint
)

Sorts the 'rails' of this ParallelFlux and returns a Publisher that sequentially picks the smallest next value from the rails.

pack-priv static final <T> List<T>
sortedMerger(List<T> a, List<T> b, Comparator<? super T> comparator)

public abstract void
subscribe(CoreSubscriber<? super T>[]
the subscribers array to run in parallel, the number of items must be equal to the parallelism level of this ParallelFlux
subscribers
)

Subscribes an array of Subscribers to this ParallelFlux and triggers the execution chain for all 'rails'.

public final Disposable
subscribe()

Subscribes to this ParallelFlux and triggers the execution chain for all 'rails'.

public final Disposable
subscribe(Consumer<? super T>
consumer of onNext signals
onNext
)

Subscribes to this ParallelFlux by providing an onNext callback and triggers the execution chain for all 'rails'.

public final Disposable
subscribe(Consumer<? super T>
consumer of onNext signals
onNext
,
Consumer<? super Throwable>
consumer of error signal
onError
)

Subscribes to this ParallelFlux by providing an onNext and onError callback and triggers the execution chain for all 'rails'.

public final Disposable
subscribe(Consumer<? super T>
consumer of onNext signals
onNext
,
Consumer<? super Throwable>
consumer of error signal
onError
,
Runnable
callback on completion signal
onComplete
)

Subscribes to this ParallelFlux by providing an onNext, onError and onComplete callback and triggers the execution chain for all 'rails'.

public final void
subscribe(CoreSubscriber<? super T>
the Subscriber interested into the published sequence
s
)

Implements reactor.core.CorePublisher.subscribe.

An internal Publisher#subscribe(Subscriber) that will bypass Hooks#onLastOperator(Function) pointcut.
public final Disposable
subscribe(Consumer<? super T>
consumer of onNext signals
onNext
,
Consumer<? super Throwable>
consumer of error signal
onError
,
Runnable
callback on completion signal
onComplete
,
Consumer<? super Subscription>
consumer of the subscription signal
onSubscribe
)

Subscribes to this ParallelFlux by providing an onNext, onError, onComplete and onSubscribe callback and triggers the execution chain for all 'rails'.

public final Disposable
subscribe(Consumer<? super T>
consumer of onNext signals
onNext
,
Consumer<? super Throwable>
consumer of error signal
onError
,
Runnable
callback on completion signal
onComplete
,
Context
Context for the rails
initialContext
)

Subscribes to this ParallelFlux by providing an onNext, onError and onComplete callback as well as an initial Context, then trigger the execution chain for all 'rails'.

pack-priv final Disposable
subscribe(Consumer<? super T> onNext, Consumer<? super Throwable> onError, Runnable onComplete, Consumer<? super Subscription> onSubscribe, Context initialContext)

public final void
subscribe(Subscriber<? super T>
the subscriber to use on sequential() Flux
s
)

Implements org.reactivestreams.Publisher.subscribe.

Merge the rails into a sequential() Flux and subscribe to said Flux.
public final ParallelFlux<T>

Returns:

the same sequence, but bearing tags
tag
(String
a tag key
key
,
String
a tag value
value
)

Tag this ParallelFlux with a key/value pair.

public final Mono<Void>

Returns:

the new Mono instance emitting the reduced value or empty if the ParallelFlux was empty
then
()

Emit an onComplete or onError signal once all values across 'rails' have been observed.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public final <
the output value type
U
>
ParallelFlux<U>

Returns:

the ParallelFlux returned by the function
transform
(Function<? super ParallelFlux<T>, ParallelFlux<U>>
the composer function from ParallelFlux (this) to another ParallelFlux
composer
)

Allows composing operators, in assembly time, on top of this ParallelFlux and returns another ParallelFlux with composed features.

public final <
the type of the resulting parallelized flux
U
>
ParallelFlux<U>

Returns:

a ParallelFlux of the composed groups
transformGroups
(Function<? super GroupedFlux<Integer, T>, ? extends Publisher<? extends U>>
the composition function to apply on each rail
composer
)

Allows composing operators off the groups (or 'rails'), as individual GroupedFlux instances keyed by the zero based rail's index.

protected final boolean

Returns:

true if the number of subscribers equals to the parallelism level
validate
(Subscriber<?>[]
the array of Subscribers
subscribers
)

Validates the number of subscribers and returns true if their number matches the parallelism level of this ParallelFlux.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait