-
- Type Parameters:
T
- item type
- All Superinterfaces:
Flow.Publisher<T>
,Subscribable<T>
- All Known Subinterfaces:
Content
- All Known Implementing Classes:
ConcatPublisher
,MessageBodyReadableContent
,MultiFromOutputStream
,MultiTappedPublisher
,OutputStreamMulti
public interface Multi<T> extends Subscribable<T>
Represents aFlow.Publisher
emitting zero or more items, optionally followed by an error or completion.- See Also:
Single
-
-
Method Summary
All Methods Static Methods Instance Methods Default Methods Deprecated Methods Modifier and Type Method Description default <U> Single<U>
collect(Collector<T,U> collector)
default <U> Single<U>
collect(Supplier<? extends U> collectionSupplier, BiConsumer<U,T> accumulator)
default Single<List<T>>
collectList()
default <A,R>
Single<R>collectStream(Collector<T,A,R> collector)
Collects up upstream items with the help of a the callbacks of aCollector
.default <U> Multi<U>
compose(Function<? super Multi<T>,? extends Flow.Publisher<? extends U>> composer)
Apply the givencomposer
function to the currentMulti
instance and return aMulti
wrapping the returnedFlow.Publisher
of this function.static <T> Multi<T>
concat(Flow.Publisher<T> firstMulti, Flow.Publisher<T> secondMulti)
Concat streams to one.static <T> Multi<T>
concat(Flow.Publisher<T> firstPublisher, Flow.Publisher<T> secondPublisher, Flow.Publisher<T>... morePublishers)
Concat streams to one.static <T> Multi<T>
concatArray(Flow.Publisher<T>... publishers)
Concatenates an array of sourceFlow.Publisher
s by relaying items in order, non-overlappingly, one after the other finishes.static <T> Multi<T>
create(Single<T> single)
static <T> Multi<T>
create(Iterable<T> iterable)
Create aMulti
instance that publishes the given iterable.static <T> Multi<T>
create(CompletionStage<T> completionStage)
Wrap a CompletionStage into a Multi and signal its outcome non-blockingly.static <T> Multi<T>
create(CompletionStage<T> completionStage, boolean nullMeansEmpty)
Wrap a CompletionStage into a Multi and signal its outcome non-blockingly.static <T> Multi<T>
create(Flow.Publisher<T> source)
Create aMulti
instance wrapped around the given publisher.static <T> Multi<T>
create(Stream<T> stream)
default Multi<T>
defaultIfEmpty(Supplier<? extends T> supplier)
Signals the default item supplied by specified supplier if the upstream is empty.default Multi<T>
defaultIfEmpty(T defaultItem)
Signals the default item if the upstream is empty.static <T> Multi<T>
defer(Supplier<? extends Flow.Publisher<? extends T>> supplier)
Call the given supplier function for each individual downstream Subscriber to return a Flow.Publisher to subscribe to.default Multi<T>
distinct()
Filter out all duplicates.default Multi<T>
dropWhile(Predicate<? super T> predicate)
Drop the longest prefix of elements from this stream that satisfy the given predicate.static <T> Multi<T>
empty()
Get aMulti
instance that completes immediately.static <T> Multi<T>
error(Throwable error)
Create aMulti
instance that reports the given exception to its subscriber(s).default Multi<T>
filter(Predicate<? super T> predicate)
Filter stream items with provided predicate.default Single<T>
first()
default <U> Multi<U>
flatMap(Function<? super T,? extends Flow.Publisher<? extends U>> publisherMapper)
Transform item with supplied function and flatten resultingFlow.Publisher
to downstream.default <U> Multi<U>
flatMap(Function<? super T,? extends Flow.Publisher<? extends U>> mapper, long maxConcurrency, boolean delayErrors, long prefetch)
Transform item with supplied function and flatten resultingFlow.Publisher
to downstream while limiting the maximum number of concurrent innerFlow.Publisher
s and their in-flight item count, optionally aggregating and delaying all errors until all sources terminate.default <U> Multi<U>
flatMapCompletionStage(Function<? super T,? extends CompletionStage<? extends U>> mapper)
Transform item with supplied function and flatten resultingCompletionStage
results to downstream.default <U> Multi<U>
flatMapIterable(Function<? super T,? extends Iterable<? extends U>> iterableMapper)
Transform item with supplied function and flatten resultingIterable
to downstream.default <U> Multi<U>
flatMapIterable(Function<? super T,? extends Iterable<? extends U>> iterableMapper, int prefetch)
Transform item with supplied function and flatten resultingIterable
to downstream.default <U> Multi<U>
flatMapOptional(Function<? super T,Optional<? extends U>> mapper)
Transform item with supplied function and flatten resultingOptional
to downstream as one item if present or nothing if empty.default Single<Void>
forEach(Consumer<? super T> consumer)
Terminal stage, invokes provided consumer for every item in the stream.static <T> Multi<T>
from(Single<T> single)
Deprecated.usecreate(io.helidon.common.reactive.Single)
insteadstatic <T> Multi<T>
from(Iterable<T> iterable)
Deprecated.usecreate(java.lang.Iterable)
insteadstatic <T> Multi<T>
from(CompletionStage<T> completionStage)
Deprecated.usecreate(java.util.concurrent.CompletionStage)
insteadstatic <T> Multi<T>
from(CompletionStage<T> completionStage, boolean nullMeansEmpty)
Deprecated.static <T> Multi<T>
from(Flow.Publisher<T> source)
Deprecated.usecreate(java.util.concurrent.Flow.Publisher)
insteadstatic <T> Multi<T>
from(Stream<T> stream)
Deprecated.usecreate(java.util.stream.Stream)
insteaddefault Multi<T>
ifEmpty(Runnable ifEmpty)
Executes givenRunnable
when stream is finished without value(empty stream).default Single<Void>
ignoreElements()
Terminal stage, ignore all items and complete returnedSingle<Void>
successfully or exceptionally.static Multi<Long>
interval(long initialDelay, long period, TimeUnit unit, ScheduledExecutorService executor)
Signal 0L after an initial delay, then 1L, 2L and so on periodically to the downstream.static Multi<Long>
interval(long period, TimeUnit unit, ScheduledExecutorService executor)
Signal 0L, 1L and so on periodically to the downstream.static <T> Multi<T>
just(Collection<T> items)
Create aMulti
instance that publishes the given items to a single subscriber.static <T> Multi<T>
just(T... items)
Create aMulti
instance that publishes the given items to a single subscriber.default Multi<T>
limit(long limit)
Limit stream to allow only specified number of items to pass.default Multi<T>
log()
Log all signalsonSubscribe
,onNext
,onError
,onComplete
,cancel
andrequest
coming to and from preceding operator.default Multi<T>
log(Level level)
Log all signalsonSubscribe
,onNext
,onError
,onComplete
,cancel
andrequest
coming to and from preceding operator.default Multi<T>
log(Level level, boolean trace)
Log all signalsonSubscribe
,onNext
,onError
,onComplete
,cancel
andrequest
coming to and from preceding operator.default Multi<T>
log(Level level, String loggerName)
Log all signalsonSubscribe
,onNext
,onError
,onComplete
,cancel
andrequest
coming to and from preceding operator.default <U> Multi<U>
map(Function<? super T,? extends U> mapper)
static <T> Multi<T>
never()
Get aMulti
instance that never completes.default Multi<T>
observeOn(Executor executor)
Re-emit the upstream's signals to the downstream on the given executor's thread using a default buffer size of 32 and errors skipping ahead of items.default Multi<T>
observeOn(Executor executor, int bufferSize, boolean delayError)
Re-emit the upstream's signals to the downstream on the given executor's thread.default Multi<T>
onCancel(Runnable onCancel)
Executes givenRunnable
when a cancel signal is received.default Multi<T>
onComplete(Runnable onComplete)
Executes givenRunnable
when onComplete signal is received.default Multi<T>
onCompleteResume(T item)
Resume stream from single item if onComplete signal is intercepted.default Multi<T>
onCompleteResumeWith(Flow.Publisher<? extends T> publisher)
Resume stream from supplied publisher if onComplete signal is intercepted.default Multi<T>
onError(Consumer<? super Throwable> onErrorConsumer)
Executes givenRunnable
when onError signal is received.default Multi<T>
onErrorResume(Function<? super Throwable,? extends T> onError)
Function
providing one item to be submitted as onNext in case of onError signal is received.default Multi<T>
onErrorResumeWith(Function<? super Throwable,? extends Flow.Publisher<? extends T>> onError)
Resume stream from supplied publisher if onError signal is intercepted.default Multi<T>
onTerminate(Runnable onTerminate)
Executes givenRunnable
when any of signals onComplete, onCancel or onError is received.default Multi<T>
peek(Consumer<? super T> consumer)
Invoke provided consumer for every item in stream.static Multi<Integer>
range(int start, int count)
Emits a range of ever increasing integers.static Multi<Long>
rangeLong(long start, long count)
Emits a range of ever increasing longs.default Single<T>
reduce(BiFunction<T,T,T> reducer)
Combine subsequent items via a callback function and emit the final value result as a Single.default <R> Single<R>
reduce(Supplier<? extends R> supplier, BiFunction<R,T,R> reducer)
Combine every upstream item with an accumulator value to produce a new accumulator value and emit the final accumulator value as a Single.default Multi<T>
retry(long count)
Retry a failing upstream at most the given number of times before giving up.default Multi<T>
retry(BiPredicate<? super Throwable,? super Long> predicate)
Retry a failing upstream if the predicate returns true.default <U> Multi<T>
retryWhen(BiFunction<? super Throwable,? super Long,? extends Flow.Publisher<U>> whenFunction)
Retry a failing upstream when the given function returns a publisher that signals an item.static <T> Multi<T>
singleton(T item)
Create aMulti
that emits a pre-existing item and then completes.default Multi<T>
skip(long skip)
Skip first n items, all the others are emitted.default Multi<T>
switchIfEmpty(Flow.Publisher<T> other)
Switch to the other publisher if the upstream is empty.default <U> Multi<T>
takeUntil(Flow.Publisher<U> other)
Relay upstream items until the other source signals an item or completes.default Multi<T>
takeWhile(Predicate<? super T> predicate)
Take the longest prefix of elements from this stream that satisfy the given predicate.default Multi<T>
timeout(long timeout, TimeUnit unit, ScheduledExecutorService executor)
Signals aTimeoutException
if the upstream doesn't signal the next item, error or completion within the specified time.default Multi<T>
timeout(long timeout, TimeUnit unit, ScheduledExecutorService executor, Flow.Publisher<T> fallback)
Switches to a fallback single if the upstream doesn't signal the next item, error or completion within the specified time.static Multi<Long>
timer(long time, TimeUnit unit, ScheduledExecutorService executor)
Signal 0L and complete the sequence after the given time elapsed.default <U> U
to(Function<? super Multi<T>,? extends U> converter)
Apply the givenconverter
function to the currentMulti
instance and return the value returned by this function.-
Methods inherited from interface java.util.concurrent.Flow.Publisher
subscribe
-
Methods inherited from interface io.helidon.common.reactive.Subscribable
subscribe, subscribe, subscribe, subscribe
-
-
-
-
Method Detail
-
concat
static <T> Multi<T> concat(Flow.Publisher<T> firstMulti, Flow.Publisher<T> secondMulti)
Concat streams to one.- Type Parameters:
T
- item type- Parameters:
firstMulti
- first streamsecondMulti
- second stream- Returns:
- Multi
-
concat
@SafeVarargs static <T> Multi<T> concat(Flow.Publisher<T> firstPublisher, Flow.Publisher<T> secondPublisher, Flow.Publisher<T>... morePublishers)
Concat streams to one.- Type Parameters:
T
- item type- Parameters:
firstPublisher
- first streamsecondPublisher
- second streammorePublishers
- more publishers to concat- Returns:
- Multi
-
concatArray
@SafeVarargs static <T> Multi<T> concatArray(Flow.Publisher<T>... publishers)
Concatenates an array of sourceFlow.Publisher
s by relaying items in order, non-overlappingly, one after the other finishes.- Type Parameters:
T
- item type- Parameters:
publishers
- more publishers to concat- Returns:
- Multi
-
defer
static <T> Multi<T> defer(Supplier<? extends Flow.Publisher<? extends T>> supplier)
Call the given supplier function for each individual downstream Subscriber to return a Flow.Publisher to subscribe to.- Type Parameters:
T
- the element type of the sequence- Parameters:
supplier
- the callback to return a Flow.Publisher for each Subscriber- Returns:
- Multi
- Throws:
NullPointerException
- ifsupplier
isnull
-
empty
static <T> Multi<T> empty()
Get aMulti
instance that completes immediately.- Type Parameters:
T
- item type- Returns:
- Multi
-
error
static <T> Multi<T> error(Throwable error)
Create aMulti
instance that reports the given exception to its subscriber(s). The exception is reported by invokingFlow.Subscriber.onError(java.lang.Throwable)
whenFlow.Publisher.subscribe(Subscriber)
is called.- Type Parameters:
T
- item type- Parameters:
error
- exception to hold- Returns:
- Multi
- Throws:
NullPointerException
- if error isnull
-
from
@Deprecated static <T> Multi<T> from(CompletionStage<T> completionStage)
Deprecated.usecreate(java.util.concurrent.CompletionStage)
insteadWrap a CompletionStage into a Multi and signal its outcome non-blockingly.A null result from the CompletionStage will yield a
NullPointerException
signal.- Type Parameters:
T
- the element type of the stage and result- Parameters:
completionStage
- the CompletionStage to- Returns:
- Multi
- See Also:
create(CompletionStage, boolean)
-
from
@Deprecated static <T> Multi<T> from(CompletionStage<T> completionStage, boolean nullMeansEmpty)
Deprecated.Wrap a CompletionStage into a Multi and signal its outcome non-blockingly.- Type Parameters:
T
- the element type of the stage and result- Parameters:
completionStage
- the CompletionStage tonullMeansEmpty
- if true, a null result is interpreted to be an empty sequence if false, the resulting sequence fails withNullPointerException
- Returns:
- Multi
-
from
@Deprecated static <T> Multi<T> from(Iterable<T> iterable)
Deprecated.usecreate(java.lang.Iterable)
insteadCreate aMulti
instance that publishes the given iterable.- Type Parameters:
T
- item type- Parameters:
iterable
- iterable to publish- Returns:
- Multi
- Throws:
NullPointerException
- if iterable isnull
-
from
@Deprecated static <T> Multi<T> from(Flow.Publisher<T> source)
Deprecated.usecreate(java.util.concurrent.Flow.Publisher)
insteadCreate aMulti
instance wrapped around the given publisher.- Type Parameters:
T
- item type- Parameters:
source
- source publisher- Returns:
- Multi
- Throws:
NullPointerException
- if source isnull
-
from
@Deprecated static <T> Multi<T> from(Single<T> single)
Deprecated.usecreate(io.helidon.common.reactive.Single)
instead- Type Parameters:
T
- item type- Parameters:
single
- sourceSingle
publisher- Returns:
- Multi
- Throws:
NullPointerException
- if source isnull
-
from
@Deprecated static <T> Multi<T> from(Stream<T> stream)
Deprecated.usecreate(java.util.stream.Stream)
insteadCreate aMulti
instance that publishes the givenStream
.Note that Streams can be only consumed once, therefore, the returned Multi will signal
IllegalStateException
if multiple subscribers try to consume it.The operator calls
BaseStream.close()
when the stream finishes, fails or the flow gets canceled. To avoid closing the stream automatically, it is recommended to turn theStream
into anIterable
viaBaseStream.iterator()
and usecreate(Iterable)
:Stream<T> stream = ... Multi<T> multi = Multi.create(stream::iterator);
- Type Parameters:
T
- item type- Parameters:
stream
- the Stream to publish- Returns:
- Multi
- Throws:
NullPointerException
- ifstream
isnull
-
create
static <T> Multi<T> create(CompletionStage<T> completionStage)
Wrap a CompletionStage into a Multi and signal its outcome non-blockingly.A null result from the CompletionStage will yield a
NullPointerException
signal.- Type Parameters:
T
- the element type of the stage and result- Parameters:
completionStage
- the CompletionStage to- Returns:
- Multi
- See Also:
create(CompletionStage, boolean)
-
create
static <T> Multi<T> create(CompletionStage<T> completionStage, boolean nullMeansEmpty)
Wrap a CompletionStage into a Multi and signal its outcome non-blockingly.- Type Parameters:
T
- the element type of the stage and result- Parameters:
completionStage
- the CompletionStage tonullMeansEmpty
- if true, a null result is interpreted to be an empty sequence if false, the resulting sequence fails withNullPointerException
- Returns:
- Multi
-
create
static <T> Multi<T> create(Iterable<T> iterable)
Create aMulti
instance that publishes the given iterable.- Type Parameters:
T
- item type- Parameters:
iterable
- iterable to publish- Returns:
- Multi
- Throws:
NullPointerException
- if iterable isnull
-
create
static <T> Multi<T> create(Flow.Publisher<T> source)
Create aMulti
instance wrapped around the given publisher.- Type Parameters:
T
- item type- Parameters:
source
- source publisher- Returns:
- Multi
- Throws:
NullPointerException
- if source isnull
-
create
static <T> Multi<T> create(Single<T> single)
- Type Parameters:
T
- item type- Parameters:
single
- sourceSingle
publisher- Returns:
- Multi
- Throws:
NullPointerException
- if source isnull
-
create
static <T> Multi<T> create(Stream<T> stream)
Create aMulti
instance that publishes the givenStream
.Note that Streams can be only consumed once, therefore, the returned Multi will signal
IllegalStateException
if multiple subscribers try to consume it.The operator calls
BaseStream.close()
when the stream finishes, fails or the flow gets canceled. To avoid closing the stream automatically, it is recommended to turn theStream
into anIterable
viaBaseStream.iterator()
and usecreate(Iterable)
:Stream<T> stream = ... Multi<T> multi = Multi.create(stream::iterator);
- Type Parameters:
T
- item type- Parameters:
stream
- the Stream to publish- Returns:
- Multi
- Throws:
NullPointerException
- ifstream
isnull
-
interval
static Multi<Long> interval(long period, TimeUnit unit, ScheduledExecutorService executor)
Signal 0L, 1L and so on periodically to the downstream.Note that if the downstream applies backpressure, subsequent values may be delivered instantly upon further requests from the downstream.
- Parameters:
period
- the initial and in-between timeunit
- the time unitexecutor
- the scheduled executor to use for the periodic emission- Returns:
- Multi
- Throws:
NullPointerException
- ifunit
orexecutor
isnull
-
interval
static Multi<Long> interval(long initialDelay, long period, TimeUnit unit, ScheduledExecutorService executor)
Signal 0L after an initial delay, then 1L, 2L and so on periodically to the downstream.Note that if the downstream applies backpressure, subsequent values may be delivered instantly upon further requests from the downstream.
- Parameters:
initialDelay
- the time before signaling 0Lperiod
- the in-between wait time for values 1L, 2L and so onunit
- the time unitexecutor
- the scheduled executor to use for the periodic emission- Returns:
- Multi
- Throws:
NullPointerException
- ifunit
orexecutor
isnull
-
just
static <T> Multi<T> just(Collection<T> items)
Create aMulti
instance that publishes the given items to a single subscriber.- Type Parameters:
T
- item type- Parameters:
items
- items to publish- Returns:
- Multi
- Throws:
NullPointerException
- ifitems
isnull
-
just
@SafeVarargs static <T> Multi<T> just(T... items)
Create aMulti
instance that publishes the given items to a single subscriber.- Type Parameters:
T
- item type- Parameters:
items
- items to publish- Returns:
- Multi
- Throws:
NullPointerException
- ifitems
isnull
-
never
static <T> Multi<T> never()
Get aMulti
instance that never completes.- Type Parameters:
T
- item type- Returns:
- Multi
-
range
static Multi<Integer> range(int start, int count)
Emits a range of ever increasing integers.- Parameters:
start
- the initial integer valuecount
- the number of integers to emit- Returns:
- Multi
- Throws:
IllegalArgumentException
- ifcount
is negative
-
rangeLong
static Multi<Long> rangeLong(long start, long count)
Emits a range of ever increasing longs.- Parameters:
start
- the initial long valuecount
- the number of longs to emit- Returns:
- Multi
- Throws:
IllegalArgumentException
- ifcount
is negative
-
singleton
static <T> Multi<T> singleton(T item)
Create aMulti
that emits a pre-existing item and then completes.- Type Parameters:
T
- the type of the item- Parameters:
item
- the item to emit.- Returns:
- Multi
- Throws:
NullPointerException
- ifitem
isnull
-
timer
static Multi<Long> timer(long time, TimeUnit unit, ScheduledExecutorService executor)
Signal 0L and complete the sequence after the given time elapsed.- Parameters:
time
- the time to wait before signaling 0L and completionunit
- the unit of timeexecutor
- the executor to run the waiting on- Returns:
- Multi
- Throws:
NullPointerException
- ifunit
orexecutor
isnull
-
collect
default <U> Single<U> collect(Collector<T,U> collector)
- Type Parameters:
U
- collector container type- Parameters:
collector
- collector to use- Returns:
- Single
- Throws:
NullPointerException
- if collector isnull
-
collect
default <U> Single<U> collect(Supplier<? extends U> collectionSupplier, BiConsumer<U,T> accumulator)
Collect the items of thisMulti
into a collection provided via aSupplier
and mutated by aBiConsumer
callback.- Type Parameters:
U
- the type of the collection and result- Parameters:
collectionSupplier
- theSupplier
that is called for each incomingFlow.Subscriber
to create a fresh collection to collect items intoaccumulator
- theBiConsumer
that receives the collection and the current item to put in- Returns:
- Single
- Throws:
NullPointerException
- ifcollectionSupplier
orcombiner
isnull
-
collectStream
default <A,R> Single<R> collectStream(Collector<T,A,R> collector)
Collects up upstream items with the help of a the callbacks of aCollector
.- Type Parameters:
A
- the accumulator typeR
- the result type- Parameters:
collector
- the collector whosesupplier()
,accumulator()
andfinisher()
callbacks are used for collecting upstream items into a final form.- Returns:
- Single
- Throws:
NullPointerException
- ifcollector
isnull
-
compose
default <U> Multi<U> compose(Function<? super Multi<T>,? extends Flow.Publisher<? extends U>> composer)
Apply the givencomposer
function to the currentMulti
instance and return aMulti
wrapping the returnedFlow.Publisher
of this function.Note that the
composer
function is executed upon calling this method immediately and not when the resulting sequence gets subscribed to.- Type Parameters:
U
- the output element type- Parameters:
composer
- the function that receives the currentMulti
instance and should return aFlow.Publisher
to be wrapped into aMultie
to be returned by the method- Returns:
- Multi
- Throws:
NullPointerException
- ifcomposer
isnull
-
defaultIfEmpty
default Multi<T> defaultIfEmpty(T defaultItem)
Signals the default item if the upstream is empty.- Specified by:
defaultIfEmpty
in interfaceSubscribable<T>
- Parameters:
defaultItem
- the item to signal if the upstream is empty- Returns:
- Multi
- Throws:
NullPointerException
- ifdefaultItem
isnull
-
defaultIfEmpty
default Multi<T> defaultIfEmpty(Supplier<? extends T> supplier)
Signals the default item supplied by specified supplier if the upstream is empty.- Specified by:
defaultIfEmpty
in interfaceSubscribable<T>
- Parameters:
supplier
- of the default value- Returns:
- Multi
- Throws:
NullPointerException
- ifsupplier
isnull
-
dropWhile
default Multi<T> dropWhile(Predicate<? super T> predicate)
Drop the longest prefix of elements from this stream that satisfy the given predicate. As long as predicate returns true, items from upstream are NOT sent to downstream but being dropped, predicate is never called again after it returns false for the first time.- Parameters:
predicate
- predicate to filter stream with- Returns:
- Multi
-
filter
default Multi<T> filter(Predicate<? super T> predicate)
Filter stream items with provided predicate.- Parameters:
predicate
- predicate to filter stream with- Returns:
- Multi
-
flatMap
default <U> Multi<U> flatMap(Function<? super T,? extends Flow.Publisher<? extends U>> publisherMapper)
Transform item with supplied function and flatten resultingFlow.Publisher
to downstream.- Specified by:
flatMap
in interfaceSubscribable<T>
- Type Parameters:
U
- output item type- Parameters:
publisherMapper
-Function
receiving item as parameter and returningFlow.Publisher
- Returns:
- Multi
-
flatMap
default <U> Multi<U> flatMap(Function<? super T,? extends Flow.Publisher<? extends U>> mapper, long maxConcurrency, boolean delayErrors, long prefetch)
Transform item with supplied function and flatten resultingFlow.Publisher
to downstream while limiting the maximum number of concurrent innerFlow.Publisher
s and their in-flight item count, optionally aggregating and delaying all errors until all sources terminate.- Type Parameters:
U
- output item type- Parameters:
mapper
-Function
receiving item as parameter and returningFlow.Publisher
maxConcurrency
- the maximum number of inner sources to rundelayErrors
- if true, any error from the main and inner sources are aggregated and delayed until all of them terminateprefetch
- the number of items to request upfront from the inner sources, then request 75% more after 75% has been delivered- Returns:
- Multi
-
flatMapCompletionStage
default <U> Multi<U> flatMapCompletionStage(Function<? super T,? extends CompletionStage<? extends U>> mapper)
Transform item with supplied function and flatten resultingCompletionStage
results to downstream. As reactive streams forbids null values, error signal withNullPointerException
is sent to downstream when CompletionStage result is null.- Type Parameters:
U
- output item type- Parameters:
mapper
-Function
receiving item as parameter and returningCompletionStage
- Returns:
- Multi
- Throws:
NullPointerException
- if mapper isnull
-
flatMapIterable
default <U> Multi<U> flatMapIterable(Function<? super T,? extends Iterable<? extends U>> iterableMapper)
Transform item with supplied function and flatten resultingIterable
to downstream.- Specified by:
flatMapIterable
in interfaceSubscribable<T>
- Type Parameters:
U
- output item type- Parameters:
iterableMapper
-Function
receiving item as parameter and returningIterable
- Returns:
- Multi
-
flatMapIterable
default <U> Multi<U> flatMapIterable(Function<? super T,? extends Iterable<? extends U>> iterableMapper, int prefetch)
Transform item with supplied function and flatten resultingIterable
to downstream.
-
flatMapOptional
default <U> Multi<U> flatMapOptional(Function<? super T,Optional<? extends U>> mapper)
Transform item with supplied function and flatten resultingOptional
to downstream as one item if present or nothing if empty.
-
limit
default Multi<T> limit(long limit)
Limit stream to allow only specified number of items to pass.- Parameters:
limit
- with expected number of items to be produced- Returns:
- Multi
-
map
default <U> Multi<U> map(Function<? super T,? extends U> mapper)
- Specified by:
map
in interfaceSubscribable<T>
- Type Parameters:
U
- mapped item type- Parameters:
mapper
- mapper- Returns:
- Multi
- Throws:
NullPointerException
- if mapper isnull
-
observeOn
default Multi<T> observeOn(Executor executor)
Re-emit the upstream's signals to the downstream on the given executor's thread using a default buffer size of 32 and errors skipping ahead of items.- Specified by:
observeOn
in interfaceSubscribable<T>
- Parameters:
executor
- the executor to signal the downstream from.- Returns:
- Multi
- Throws:
NullPointerException
- ifexecutor
isnull
- See Also:
observeOn(Executor, int, boolean)
-
observeOn
default Multi<T> observeOn(Executor executor, int bufferSize, boolean delayError)
Re-emit the upstream's signals to the downstream on the given executor's thread.- Parameters:
executor
- the executor to signal the downstream from.bufferSize
- the number of items to prefetch and buffer at a timedelayError
- iftrue
, errors are emitted after items, iffalse
, errors may cut ahead of items during emission- Returns:
- Multi
- Throws:
NullPointerException
- ifexecutor
isnull
-
onCancel
default Multi<T> onCancel(Runnable onCancel)
Executes givenRunnable
when a cancel signal is received.- Specified by:
onCancel
in interfaceSubscribable<T>
- Parameters:
onCancel
-Runnable
to be executed.- Returns:
- Multi
-
onComplete
default Multi<T> onComplete(Runnable onComplete)
Executes givenRunnable
when onComplete signal is received.- Specified by:
onComplete
in interfaceSubscribable<T>
- Parameters:
onComplete
-Runnable
to be executed.- Returns:
- Multi
-
onError
default Multi<T> onError(Consumer<? super Throwable> onErrorConsumer)
Executes givenRunnable
when onError signal is received.- Specified by:
onError
in interfaceSubscribable<T>
- Parameters:
onErrorConsumer
-Consumer
to be executed.- Returns:
- Multi
-
onErrorResume
default Multi<T> onErrorResume(Function<? super Throwable,? extends T> onError)
Function
providing one item to be submitted as onNext in case of onError signal is received.- Specified by:
onErrorResume
in interfaceSubscribable<T>
- Parameters:
onError
- Function receivingThrowable
as argument and producing one item to resume stream with.- Returns:
- Multi
-
onErrorResumeWith
default Multi<T> onErrorResumeWith(Function<? super Throwable,? extends Flow.Publisher<? extends T>> onError)
Resume stream from supplied publisher if onError signal is intercepted.- Specified by:
onErrorResumeWith
in interfaceSubscribable<T>
- Parameters:
onError
- supplier of new stream publisher- Returns:
- Multi
-
onCompleteResume
default Multi<T> onCompleteResume(T item)
Resume stream from single item if onComplete signal is intercepted. Effectively do anappend
to the stream.- Specified by:
onCompleteResume
in interfaceSubscribable<T>
- Parameters:
item
- one item to resume stream with- Returns:
- Multi
-
onCompleteResumeWith
default Multi<T> onCompleteResumeWith(Flow.Publisher<? extends T> publisher)
Resume stream from supplied publisher if onComplete signal is intercepted.- Specified by:
onCompleteResumeWith
in interfaceSubscribable<T>
- Parameters:
publisher
- new stream publisher- Returns:
- Multi
-
onTerminate
default Multi<T> onTerminate(Runnable onTerminate)
Executes givenRunnable
when any of signals onComplete, onCancel or onError is received.- Specified by:
onTerminate
in interfaceSubscribable<T>
- Parameters:
onTerminate
-Runnable
to be executed.- Returns:
- Multi
-
ifEmpty
default Multi<T> ifEmpty(Runnable ifEmpty)
Executes givenRunnable
when stream is finished without value(empty stream).- Parameters:
ifEmpty
-Runnable
to be executed.- Returns:
- Multi
-
peek
default Multi<T> peek(Consumer<? super T> consumer)
Invoke provided consumer for every item in stream.- Specified by:
peek
in interfaceSubscribable<T>
- Parameters:
consumer
- consumer to be invoked- Returns:
- Multi
-
log
default Multi<T> log()
Log all signalsonSubscribe
,onNext
,onError
,onComplete
,cancel
andrequest
coming to and from preceding operator.- Returns:
- Multi
-
log
default Multi<T> log(Level level)
Log all signalsonSubscribe
,onNext
,onError
,onComplete
,cancel
andrequest
coming to and from preceding operator.- Parameters:
level
- a logging level value- Returns:
- Multi
-
log
default Multi<T> log(Level level, String loggerName)
Log all signalsonSubscribe
,onNext
,onError
,onComplete
,cancel
andrequest
coming to and from preceding operator.- Parameters:
level
- a logging level valueloggerName
- custom logger name- Returns:
- Multi
-
log
default Multi<T> log(Level level, boolean trace)
Log all signalsonSubscribe
,onNext
,onError
,onComplete
,cancel
andrequest
coming to and from preceding operator.Enabled trace option has a negative impact on performance and should NOT be used in production.
- Parameters:
level
- a logging level valuetrace
- if true position of operator is looked up from stack and logged- Returns:
- Multi
-
reduce
default Single<T> reduce(BiFunction<T,T,T> reducer)
Combine subsequent items via a callback function and emit the final value result as a Single.If the upstream is empty, the resulting Single is also empty. If the upstream contains only one item, the reducer function is not invoked and the resulting Single will have only that single item.
- Parameters:
reducer
- the function called with the first value or the previous result, the current upstream value and should return a new value- Returns:
- Single
-
reduce
default <R> Single<R> reduce(Supplier<? extends R> supplier, BiFunction<R,T,R> reducer)
Combine every upstream item with an accumulator value to produce a new accumulator value and emit the final accumulator value as a Single.- Type Parameters:
R
- the accumulator and result type- Parameters:
supplier
- the function to return the initial accumulator value for each incoming Subscriberreducer
- the function that receives the current accumulator value, the current upstream value and should return a new accumulator value- Returns:
- Single
-
retry
default Multi<T> retry(long count)
Retry a failing upstream at most the given number of times before giving up.- Specified by:
retry
in interfaceSubscribable<T>
- Parameters:
count
- the number of times to retry; 0 means no retry at all- Returns:
- Multi
- Throws:
IllegalArgumentException
- ifcount
is negative- See Also:
retryWhen(BiFunction)
-
retry
default Multi<T> retry(BiPredicate<? super Throwable,? super Long> predicate)
Retry a failing upstream if the predicate returns true.- Specified by:
retry
in interfaceSubscribable<T>
- Parameters:
predicate
- the predicate that receives the latest failureThrowable
the number of times the retry happened so far (0-based) and should returntrue
to retry the upstream again orfalse
to signal the latest failure- Returns:
- Multi
- Throws:
NullPointerException
- ifpredicate
isnull
- See Also:
retryWhen(BiFunction)
-
retryWhen
default <U> Multi<T> retryWhen(BiFunction<? super Throwable,? super Long,? extends Flow.Publisher<U>> whenFunction)
Retry a failing upstream when the given function returns a publisher that signals an item.If the publisher returned by the function completes, the repetition stops and this Multi is completed. If the publisher signals an error, the repetition stops and this Multi will signal this error.
- Specified by:
retryWhen
in interfaceSubscribable<T>
- Type Parameters:
U
- the element type of the retry-signal sequence- Parameters:
whenFunction
- the function that receives the latest failureThrowable
the number of times the retry happened so far (0-based) and should return aFlow.Publisher
that should signal an item to retry again, complete to stop and complete this Multi or signal an error to have this Multi emit that error as well.- Returns:
- Multi
- Throws:
NullPointerException
- ifwhenFunction
isnull
-
skip
default Multi<T> skip(long skip)
Skip first n items, all the others are emitted.- Parameters:
skip
- number of items to be skipped- Returns:
- Multi
-
switchIfEmpty
default Multi<T> switchIfEmpty(Flow.Publisher<T> other)
Switch to the other publisher if the upstream is empty.- Parameters:
other
- the publisher to switch to if the upstream is empty.- Returns:
- Multi
- Throws:
NullPointerException
- ifother
isnull
-
takeUntil
default <U> Multi<T> takeUntil(Flow.Publisher<U> other)
Relay upstream items until the other source signals an item or completes.- Specified by:
takeUntil
in interfaceSubscribable<T>
- Type Parameters:
U
- the element type of the other sequence- Parameters:
other
- the other sequence to signal the end of the main sequence- Returns:
- Multi
- Throws:
NullPointerException
- ifother
isnull
-
takeWhile
default Multi<T> takeWhile(Predicate<? super T> predicate)
Take the longest prefix of elements from this stream that satisfy the given predicate. As long as predicate returns true, items from upstream are sent to downstream, when predicate returns false stream is completed.- Parameters:
predicate
- predicate to filter stream with- Returns:
- Multi
-
timeout
default Multi<T> timeout(long timeout, TimeUnit unit, ScheduledExecutorService executor)
Signals aTimeoutException
if the upstream doesn't signal the next item, error or completion within the specified time.- Specified by:
timeout
in interfaceSubscribable<T>
- Parameters:
timeout
- the time to wait for the upstream to signalunit
- the time unitexecutor
- the executor to use for waiting for the upstream signal- Returns:
- Multi
- Throws:
NullPointerException
- ifunit
orexecutor
isnull
-
timeout
default Multi<T> timeout(long timeout, TimeUnit unit, ScheduledExecutorService executor, Flow.Publisher<T> fallback)
Switches to a fallback single if the upstream doesn't signal the next item, error or completion within the specified time.- Parameters:
timeout
- the time to wait for the upstream to signalunit
- the time unitexecutor
- the executor to use for waiting for the upstream signalfallback
- the Single to switch to if the upstream doesn't signal in time- Returns:
- Multi
- Throws:
NullPointerException
- ifunit
,executor
orfallback
isnull
-
to
default <U> U to(Function<? super Multi<T>,? extends U> converter)
Apply the givenconverter
function to the currentMulti
instance and return the value returned by this function.Note that the
converter
function is executed upon calling this method immediately and not when the resulting sequence gets subscribed to.- Type Parameters:
U
- the output type- Parameters:
converter
- the function that receives the currentMulti
instance and should return a value to be returned by the method- Returns:
- the value returned by the function
- Throws:
NullPointerException
- ifconverter
isnull
-
forEach
default Single<Void> forEach(Consumer<? super T> consumer)
Terminal stage, invokes provided consumer for every item in the stream.- Parameters:
consumer
- consumer to be invoked for each item- Returns:
- Single completed when the stream terminates
-
-