Top Description Constructors Methods
io.reactivex.rxjava3.parallel

public abstract Class ParallelFlowable<T>

extends Object
Class Inheritance
Known Direct Subclasses
io.reactivex.rxjava3.internal.jdk8.ParallelFlatMapStream, io.reactivex.rxjava3.internal.jdk8.ParallelMapOptional, io.reactivex.rxjava3.internal.jdk8.ParallelMapTryOptional, io.reactivex.rxjava3.internal.operators.parallel.ParallelCollect, io.reactivex.rxjava3.internal.operators.parallel.ParallelConcatMap, io.reactivex.rxjava3.internal.operators.parallel.ParallelDoOnNextTry, io.reactivex.rxjava3.internal.operators.parallel.ParallelFilter, io.reactivex.rxjava3.internal.operators.parallel.ParallelFilterTry, io.reactivex.rxjava3.internal.operators.parallel.ParallelFlatMap, io.reactivex.rxjava3.internal.operators.parallel.ParallelFlatMapIterable, io.reactivex.rxjava3.internal.operators.parallel.ParallelFromArray, io.reactivex.rxjava3.internal.operators.parallel.ParallelFromPublisher, io.reactivex.rxjava3.internal.operators.parallel.ParallelMap, io.reactivex.rxjava3.internal.operators.parallel.ParallelMapTry, io.reactivex.rxjava3.internal.operators.parallel.ParallelPeek, io.reactivex.rxjava3.internal.operators.parallel.ParallelReduce, io.reactivex.rxjava3.internal.operators.parallel.ParallelRunOn
Type Parameters
<T>
the value type
Imports
java.util.*, java.util.stream.*, org.reactivestreams.*, io.reactivex.rxjava3.annotations.*, io.reactivex.rxjava3.core.*, io.reactivex.rxjava3.exceptions.MissingBackpressureException, io.reactivex.rxjava3.functions.*, io.reactivex.rxjava3.internal.functions.*, io.reactivex.rxjava3.internal.jdk8.*, io.reactivex.rxjava3.internal.operators.parallel.*, io.reactivex.rxjava3.internal.subscriptions.EmptySubscription, io.reactivex.rxjava3.internal.util.*, io.reactivex.rxjava3.plugins.RxJavaPlugins

Abstract base class for parallel publishing of events signaled to an array of Subscribers.

Use from(Publisher) to start processing a regular Publisher in 'rails'. Use runOn(Scheduler) to introduce where each 'rail' should run on thread-vise. Use sequential() to merge the sources back into a single Flowable.

History: 2.0.5 - experimental; 2.1 - beta

Since
2.2

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public final <
the collection type
C
>
@NonNull ParallelFlowable<C>

Returns:

the new ParallelFlowable instance
collect
(@NonNull Supplier<? extends C>
the supplier of the collection in each rail
collectionSupplier
,
@NonNull 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 <
the accumulator type
A
,
the output value type
R
>
@NonNull Flowable<R>

Returns:

the new Flowable instance emitting the collected value.
collect
(@NonNull Collector<T, A, R>
the Collector instance
collector
)

Reduces all values within a 'rail' and across 'rails' with a callbacks of the given Collector into one Flowable containing a single value.

public final <
the output value type
U
>
@NonNull ParallelFlowable<U>

Returns:

the ParallelFlowable returned by the function
compose
(@NonNull ParallelTransformer<T, U>
the composer function from ParallelFlowable (this) to another ParallelFlowable
composer
)

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

public final <
the result type
R
>
@NonNull ParallelFlowable<R>

Returns:

the new ParallelFlowable instance
concatMap
(@NonNull Function<? super T, @NonNull ? 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
>
@NonNull ParallelFlowable<R>

Returns:

the new ParallelFlowable instance
concatMap
(@NonNull Function<? super T, @NonNull ? 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.

public final <
the result type
R
>
@NonNull ParallelFlowable<R>

Returns:

the new ParallelFlowable instance
concatMapDelayError
(@NonNull Function<? super T, @NonNull ? extends Publisher<? extends R>>
the function to map each rail's value into a Publisher
mapper
,
boolean
if true, all errors from the upstream and inner Publishers are delayed till all of them terminate, if false, the error is emitted when an inner Publisher terminates. source and the inner Publishers (immediate, boundary, end)
tillTheEnd
)

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

public final <
the result type
R
>
@NonNull ParallelFlowable<R>

Returns:

the new ParallelFlowable instance
concatMapDelayError
(@NonNull Function<? super T, @NonNull ? 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
,
boolean
if true, all errors from the upstream and inner Publishers are delayed till all of them terminate, if false, the error is emitted when an inner Publisher terminates.
tillTheEnd
)

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

public final @NonNull ParallelFlowable<T>

Returns:

the new ParallelFlowable instance
doAfterNext
(@NonNull Consumer<? super T>
the callback
onAfterNext
)

Call the specified consumer with the current element passing through any 'rail' after it has been delivered to downstream within the rail.

public final @NonNull ParallelFlowable<T>

Returns:

the new ParallelFlowable instance
doAfterTerminated
(@NonNull Action
the callback
onAfterTerminate
)

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

public final @NonNull ParallelFlowable<T>

Returns:

the new ParallelFlowable instance
doOnCancel
(@NonNull Action
the callback
onCancel
)

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

public final @NonNull ParallelFlowable<T>

Returns:

the new ParallelFlowable instance
doOnComplete
(@NonNull Action
the callback
onComplete
)

Run the specified Action when a 'rail' completes.

public final @NonNull ParallelFlowable<T>

Returns:

the new ParallelFlowable instance
doOnError
(@NonNull Consumer<? super Throwable>
the callback
onError
)

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

public final @NonNull ParallelFlowable<T>

Returns:

the new ParallelFlowable instance
doOnNext
(@NonNull Consumer<? super T>
the callback
onNext
)

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

public final @NonNull ParallelFlowable<T>

Returns:

the new ParallelFlowable instance
doOnNext
(@NonNull Consumer<? super T>
the callback
onNext
,
@NonNull ParallelFailureHandling
the enumeration that defines how to handle errors thrown from the onNext consumer
errorHandler
)

Call the specified consumer with the current element passing through any 'rail' and handles errors based on the given ParallelFailureHandling enumeration value.

public final @NonNull ParallelFlowable<T>

Returns:

the new ParallelFlowable instance
doOnNext
(@NonNull Consumer<? super T>
the callback
onNext
,
@NonNull BiFunction<? super Long, ? super Throwable, ParallelFailureHandling>
the function called with the current repeat count and failure Throwable and should return one of the ParallelFailureHandling enumeration values to indicate how to proceed.
errorHandler
)

Call the specified consumer with the current element passing through any 'rail' and handles errors based on the returned value by the handler function.

public final @NonNull ParallelFlowable<T>

Returns:

the new ParallelFlowable instance
doOnRequest
(@NonNull LongConsumer
the callback
onRequest
)

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

public final @NonNull ParallelFlowable<T>

Returns:

the new ParallelFlowable instance
doOnSubscribe
(@NonNull Consumer<? super Subscription>
the callback
onSubscribe
)

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

public final @NonNull ParallelFlowable<T>

Returns:

the new ParallelFlowable instance
filter
(@NonNull 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 @NonNull ParallelFlowable<T>

Returns:

the new ParallelFlowable instance
filter
(@NonNull Predicate<? super T>
the function returning true to keep a value or false to drop a value
predicate
,
@NonNull ParallelFailureHandling
the enumeration that defines how to handle errors thrown from the predicate
errorHandler
)

Filters the source values on each 'rail' and handles errors based on the given ParallelFailureHandling enumeration value.

public final @NonNull ParallelFlowable<T>

Returns:

the new ParallelFlowable instance
filter
(@NonNull Predicate<? super T>
the function returning true to keep a value or false to drop a value
predicate
,
@NonNull BiFunction<? super Long, ? super Throwable, ParallelFailureHandling>
the function called with the current repeat count and failure Throwable and should return one of the ParallelFailureHandling enumeration values to indicate how to proceed.
errorHandler
)

Filters the source values on each 'rail' and handles errors based on the returned value by the handler function.

public final <
the result type
R
>
@NonNull ParallelFlowable<R>

Returns:

the new ParallelFlowable instance
flatMap
(@NonNull Function<? super T, @NonNull ? 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
>
@NonNull ParallelFlowable<R>

Returns:

the new ParallelFlowable instance
flatMap
(@NonNull Function<? super T, @NonNull ? 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
>
@NonNull ParallelFlowable<R>

Returns:

the new ParallelFlowable instance
flatMap
(@NonNull Function<? super T, @NonNull ? 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
>
@NonNull ParallelFlowable<R>

Returns:

the new ParallelFlowable instance
flatMap
(@NonNull Function<? super T, @NonNull ? 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.

public final <
the type of item emitted by the resulting Iterable
U
>
@NonNull ParallelFlowable<U>

Returns:

the new ParallelFlowable instance
flatMapIterable
(@NonNull Function<? super T, @NonNull ? extends Iterable<? extends U>>
a function that returns an Iterable sequence of values for when given an item emitted by the source ParallelFlowable
mapper
)

Returns a ParallelFlowable that merges each item emitted by the source on each rail with the values in an Iterable corresponding to that item that is generated by a selector.

public final <
the type of item emitted by the resulting Iterable
U
>
@NonNull ParallelFlowable<U>

Returns:

the new ParallelFlowable instance
flatMapIterable
(@NonNull Function<? super T, @NonNull ? extends Iterable<? extends U>>
a function that returns an Iterable sequence of values for when given an item emitted by the source ParallelFlowable
mapper
,
int
the number of elements to prefetch from each upstream rail
bufferSize
)

Returns a ParallelFlowable that merges each item emitted by the source ParallelFlowable with the values in an Iterable corresponding to that item that is generated by a selector.

public final <
the element type of the Streams and the result
R
>
@NonNull ParallelFlowable<R>

Returns:

the new ParallelFlowable instance
flatMapStream
(@NonNull Function<? super T, @NonNull ? extends Stream<? extends R>>
the function that receives an upstream item and should return a Stream whose elements will be emitted to the downstream
mapper
)

Maps each upstream item on each rail into a Stream and emits the Stream's items to the downstream in a sequential fashion.

public final <
the element type of the Streams and the result
R
>
@NonNull ParallelFlowable<R>

Returns:

the new ParallelFlowable instance
flatMapStream
(@NonNull Function<? super T, @NonNull ? extends Stream<? extends R>>
the function that receives an upstream item and should return a Stream whose elements will be emitted to the downstream
mapper
,
int
the number of upstream items to request upfront, then 75% of this amount after each 75% upstream items received
prefetch
)

Maps each upstream item of each rail into a Stream and emits the Stream's items to the downstream in a sequential fashion.

public static <
the value type
T
>
@NonNull ParallelFlowable<T>

Returns:

the new ParallelFlowable instance
from
(@NonNull Publisher<? extends T>
the source Publisher
source
)

Take a Publisher and prepare to consume it on multiple 'rails' (number of CPUs) in a round-robin fashion.

public static <
the value type
T
>
@NonNull ParallelFlowable<T>

Returns:

the new ParallelFlowable instance
from
(@NonNull 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' in a round-robin fashion.

public static <
the value type
T
>
@NonNull ParallelFlowable<T>

Returns:

the new ParallelFlowable instance
from
(@NonNull Publisher<? extends T>
the source Publisher
source
,
int
the number of parallel rails
parallelism
,
int
the number of values to prefetch from the source the source until there is a rail ready to process it.
prefetch
)

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

public static <
the value type
T
>
@NonNull ParallelFlowable<T>

Returns:

the new ParallelFlowable instance
fromArray
(@NonNull Publisher<T>...
the array of publishers
publishers
)

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

public final <
the output value type
R
>
@NonNull ParallelFlowable<R>

Returns:

the new ParallelFlowable instance
map
(@NonNull Function<? super T, ? extends R>
the mapper function turning Ts into Rs.
mapper
)

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

public final <
the output value type
R
>
@NonNull ParallelFlowable<R>

Returns:

the new ParallelFlowable instance
map
(@NonNull Function<? super T, ? extends R>
the mapper function turning Ts into Rs.
mapper
,
@NonNull ParallelFailureHandling
the enumeration that defines how to handle errors thrown from the mapper function
errorHandler
)

Maps the source values on each 'rail' to another value and handles errors based on the given ParallelFailureHandling enumeration value.

public final <
the output value type
R
>
@NonNull ParallelFlowable<R>

Returns:

the new ParallelFlowable instance
map
(@NonNull Function<? super T, ? extends R>
the mapper function turning Ts into Rs.
mapper
,
@NonNull BiFunction<? super Long, ? super Throwable, ParallelFailureHandling>
the function called with the current repeat count and failure Throwable and should return one of the ParallelFailureHandling enumeration values to indicate how to proceed.
errorHandler
)

Maps the source values on each 'rail' to another value and handles errors based on the returned value by the handler function.

public final <
the output value type
R
>
@NonNull ParallelFlowable<R>

Returns:

the new ParallelFlowable instance
mapOptional
(@NonNull Function<? super T, @NonNull Optional<? extends R>>
the mapper function turning Ts into optional of Rs.
mapper
)

Maps the source values on each 'rail' to an optional and emits its value if any.

public final <
the output value type
R
>
@NonNull ParallelFlowable<R>

Returns:

the new ParallelFlowable instance
mapOptional
(@NonNull Function<? super T, @NonNull Optional<? extends R>>
the mapper function turning Ts into optional of Rs.
mapper
,
@NonNull ParallelFailureHandling
the enumeration that defines how to handle errors thrown from the mapper function
errorHandler
)

Maps the source values on each 'rail' to an optional and emits its value if any and handles errors based on the given ParallelFailureHandling enumeration value.

public final <
the output value type
R
>
@NonNull ParallelFlowable<R>

Returns:

the new ParallelFlowable instance
mapOptional
(@NonNull Function<? super T, @NonNull Optional<? extends R>>
the mapper function turning Ts into optional of Rs.
mapper
,
@NonNull BiFunction<? super Long, ? super Throwable, ParallelFailureHandling>
the function called with the current repeat count and failure Throwable and should return one of the ParallelFailureHandling enumeration values to indicate how to proceed.
errorHandler
)

Maps the source values on each 'rail' to an optional and emits its value if any and handles errors based on the returned value by the handler function.

public abstract int

Returns:

the number of expected parallel Subscribers
parallelism
()

Returns the number of expected parallel Subscribers.

public final @NonNull Flowable<T>

Returns:

the new Flowable instance emitting the reduced value or empty if the current ParallelFlowable is empty
reduce
(@NonNull 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 one Flowable sequence.

public final <
the reduced output type
R
>
@NonNull ParallelFlowable<R>

Returns:

the new ParallelFlowable instance
reduce
(@NonNull Supplier<R>
the supplier for the initial value
initialSupplier
,
@NonNull 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 @NonNull ParallelFlowable<T>

Returns:

the new ParallelFlowable instance
runOn
(@NonNull Scheduler
the scheduler to use
scheduler
)

Specifies where each 'rail' will observe its incoming values, specified via a Scheduler, with no work-stealing and default prefetch amount.

public final @NonNull ParallelFlowable<T>

Returns:

the new ParallelFlowable instance
runOn
(@NonNull 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, specified via a Scheduler, with possibly work-stealing and a given prefetch amount.

public final @NonNull Flowable<T>

Returns:

the new Flowable instance
sequential
()

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

public final @NonNull Flowable<T>

Returns:

the new Flowable 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 Flowable sequence, running with a give prefetch value for the rails.

public final @NonNull Flowable<T>

Returns:

the new Flowable instance
sequentialDelayError
()

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

public final @NonNull Flowable<T>

Returns:

the new Flowable instance
sequentialDelayError
(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 Flowable sequence, running with a give prefetch value for the rails and delaying errors from all rails till all terminate.

public final @NonNull Flowable<T>

Returns:

the new Flowable instance
sorted
(@NonNull Comparator<? super T>
the comparator to use
comparator
)

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

public final @NonNull Flowable<T>

Returns:

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

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

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

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

public final <
the resulting object type
R
>
R

Returns:

the converted value
to
(@NonNull ParallelFlowableConverter<T, R>
the function that receives the current ParallelFlowable instance and returns a value
converter
)

Calls the specified converter function during assembly time and returns its resulting value.

public final @NonNull Flowable<List<T>>

Returns:

the new Flowable instance
toSortedList
(@NonNull Comparator<? super T>
the comparator to compare elements
comparator
)

Sorts the 'rails' according to the comparator and returns a full sorted List as a Flowable.

public final @NonNull Flowable<@NonNull List<T>>

Returns:

the new Flowable instance
toSortedList
(@NonNull 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 Flowable.

protected final boolean

Returns:

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

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

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait