Top Description Constructors Methods
io.reactivex.parallel

public abstract Class ParallelFlowable<T>

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

Abstract base class for Parallel publishers that take an array of Subscribers.

Use from() to start processing a regular Publisher in 'rails'. Use runOn() 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 resulting object type
R
>
R

Returns:

the converted value
as
(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 <
the collection type
C
>
ParallelFlowable<C>

Returns:

the new ParallelFlowable instance
collect
(Callable<? 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 <
the output value type
U
>
ParallelFlowable<U>

Returns:

the ParallelFlowable returned by the function
compose
(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
>
ParallelFlowable<R>

Returns:

the new ParallelFlowable 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
>
ParallelFlowable<R>

Returns:

the new ParallelFlowable 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.

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

Returns:

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

Returns:

the new ParallelFlowable 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
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 ParallelFlowable<T>

Returns:

the new ParallelFlowable instance
doAfterNext
(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 ParallelFlowable<T>

Returns:

the new ParallelFlowable instance
doAfterTerminated
(Action
the callback
onAfterTerminate
)

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

public final ParallelFlowable<T>

Returns:

the new ParallelFlowable instance
doOnCancel
(Action
the callback
onCancel
)

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

public final ParallelFlowable<T>

Returns:

the new ParallelFlowable instance
doOnComplete
(Action
the callback
onComplete
)

Run the specified Action when a 'rail' completes.

public final ParallelFlowable<T>

Returns:

the new ParallelFlowable instance
doOnError
(Consumer<Throwable>
the callback
onError
)

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

public final ParallelFlowable<T>

Returns:

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

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

public final ParallelFlowable<T>

Returns:

the new ParallelFlowable instance
doOnNext
(Consumer<? super T>
the callback
onNext
,
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 ParallelFlowable<T>

Returns:

the new ParallelFlowable instance
doOnNext
(Consumer<? super T>
the callback
onNext
,
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 ParallelFlowable<T>

Returns:

the new ParallelFlowable instance
doOnRequest
(LongConsumer
the callback
onRequest
)

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

public final ParallelFlowable<T>

Returns:

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

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

public final ParallelFlowable<T>

Returns:

the new ParallelFlowable 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 ParallelFlowable<T>

Returns:

the new ParallelFlowable instance
filter
(Predicate<? super T>
the function returning true to keep a value or false to drop a value
predicate
,
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 ParallelFlowable<T>

Returns:

the new ParallelFlowable instance
filter
(Predicate<? super T>
the function returning true to keep a value or false to drop a value
predicate
,
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
>
ParallelFlowable<R>

Returns:

the new ParallelFlowable 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
>
ParallelFlowable<R>

Returns:

the new ParallelFlowable 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
>
ParallelFlowable<R>

Returns:

the new ParallelFlowable 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
>
ParallelFlowable<R>

Returns:

the new ParallelFlowable 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.

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

Returns:

the ParallelFlowable instance
from
(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
>
ParallelFlowable<T>

Returns:

the new ParallelFlowable 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' in a round-robin fashion.

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

Returns:

the new ParallelFlowable 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 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
>
ParallelFlowable<T>

Returns:

the new ParallelFlowable instance
fromArray
(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
>
ParallelFlowable<R>

Returns:

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

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

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

Returns:

the new ParallelFlowable instance
map
(Function<? super T, ? extends R>
the mapper function turning Ts into Us.
mapper
,
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
>
ParallelFlowable<R>

Returns:

the new ParallelFlowable instance
map
(Function<? super T, ? extends R>
the mapper function turning Ts into Us.
mapper
,
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 abstract int

Returns:

the number of expected parallel Subscribers
parallelism
()

Returns the number of expected parallel Subscribers.

public final Flowable<T>

Returns:

the new Flowable instance emitting the reduced value or empty if the ParallelFlowable 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
>
ParallelFlowable<R>

Returns:

the new ParallelFlowable instance
reduce
(Callable<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 ParallelFlowable<T>

Returns:

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

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

public final ParallelFlowable<T>

Returns:

the new ParallelFlowable 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 possibly work-stealing and a given prefetch amount.

public final 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 Publisher sequence, running with a default prefetch value for the rails.

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

public final 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 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 Publisher sequence, running with a give prefetch value for the rails and delaying errors from all rails till all terminate.

public final Flowable<T>

Returns:

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

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

public final Flowable<T>

Returns:

the new Flowable instance
sorted
(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 Publisher that sequentially picks the smallest next value from the rails.

public abstract void
subscribe(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 output value type
U
>
U

Returns:

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

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

public final Flowable<List<T>>

Returns:

the new Flowable instance
toSortedList
(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 Flowable<List<T>>

Returns:

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

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 ParallelFlowable.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait