public interface Multi<T>
extends org.reactivestreams.Publisher<T>
Modifier and Type | Method and Description |
---|---|
MultiBroadcast<T> |
broadcast()
Makes this
Multi be able to broadcast its events (items , failure , and completion )
to multiple subscribers. |
Multi<T> |
cache()
Creates a new
Multi that subscribes to this upstream and caches all of its events and replays them, to
all the downstream subscribers. |
MultiCollect<T> |
collectItems()
|
default <O> Multi<O> |
concatMap(Function<? super T,? extends org.reactivestreams.Publisher<? extends O>> mapper)
|
MultiConvert<T> |
convert()
Converts a
Multi to other types |
static MultiCreateBy |
createBy()
|
static MultiCreate |
createFrom() |
Multi<T> |
emitOn(Executor executor)
|
default <O> Multi<O> |
flatMap(Function<? super T,? extends org.reactivestreams.Publisher<? extends O>> mapper)
|
MultiGroup<T> |
groupItems()
|
default <O> Multi<O> |
map(Function<? super T,? extends O> mapper)
|
MultiOnEvent<T> |
on()
Allows adding behavior when various type of events are emitted by the current
Multi (item, failure,
completion) or by the subscriber (cancellation, request, subscription) |
MultiOnCompletion<T> |
onCompletion()
Allows configures the actions or continuation to execute when this
Multi fires the completion event. |
MultiOnFailure<T> |
onFailure()
Like
onFailure(Predicate) but applied to all failures fired by the upstream multi. |
MultiOnFailure<T> |
onFailure(Class<? extends Throwable> typeOfFailure)
Configures a type of failure filtering the failures on which the behavior (specified with the returned
MultiOnFailure ) is applied. |
MultiOnFailure<T> |
onFailure(Predicate<? super Throwable> predicate)
Configures a predicate filtering the failures on which the behavior (specified with the returned
MultiOnFailure ) is applied. |
MultiOnItem<T> |
onItem()
Configures the behavior when an
item event is received from the this Multi |
MultiOverflow<T> |
onOverflow()
Configures the back-pressure behavior when the consumer cannot keep up with the emissions from this
Multi . |
MultiSubscribe<T> |
subscribe()
Configures the subscriber consuming this
Multi . |
Multi<T> |
subscribeOn(Executor executor)
|
default <O> O |
then(Function<Multi<T>,O> stage)
Allows structuring the pipeline by creating a logic separation:
|
Uni<T> |
toUni()
|
MultiTransform<T> |
transform()
Transforms the streams by skipping, selecting, or merging.
|
static MultiCreate createFrom()
static MultiCreateBy createBy()
Multi
by merging, concatenating or associating items from others Multi
and Publisher
.MultiSubscribe<T> subscribe()
Multi
.MultiOnItem<T> onItem()
item
event is received from the this Multi
default <O> O then(Function<Multi<T>,O> stage)
Multi multi = upstream
.then(m -> { ...})
.then(m -> { ...})
.then(m -> { ...})
With `then` you can structure and chain groups of processing.
Uni<T> toUni()
Uni
from this Multi
.
When a subscriber subscribes to the returned Uni
, it subscribes to this Multi
and requests one
item. The event emitted by this Multi
are then forwarded to the Uni
:
Uni
Uni
null
item is fired by the produces Uni
If the subscription on the produced Uni
is cancelled, the subscription to the passed Multi
is
also cancelled.
Uni
MultiOnFailure<T> onFailure()
onFailure(Predicate)
but applied to all failures fired by the upstream multi.
It allows configuring the on failure behavior (recovery, retry...).MultiOnFailure<T> onFailure(Predicate<? super Throwable> predicate)
MultiOnFailure
) is applied.
For instance, to only when an IOException
is fired as failure you can use:
multi.onFailure(IOException.class).recoverWithItem("hello")
The fallback value (hello
) will only be used if the upstream multi fires a failure of type
IOException
.
predicate
- the predicate, null
means applied to all failuresMultiOnFailure<T> onFailure(Class<? extends Throwable> typeOfFailure)
MultiOnFailure
) is applied.
For instance, to only when an IOException
is fired as failure you can use:
multi.onFailure(IOException.class).recoverWithItem("hello")
The fallback value (hello
) will only be used if the upstream multi fire a failure of type
IOException
.*
typeOfFailure
- the class of exception, must not be null
MultiOnEvent<T> on()
Multi
(item, failure,
completion) or by the subscriber (cancellation, request, subscription)Multi<T> cache()
Multi
that subscribes to this upstream and caches all of its events and replays them, to
all the downstream subscribers.MultiCollect<T> collectItems()
Multi
or Uni
collecting items from this Multi
. You can accumulate the items
into a List
(MultiCollect.asList()
), Map
(MultiCollect.asMap(Function)
...
You can also retrieve the first and list items using MultiCollect.first()
and MultiCollect.last()
.
MultiGroup<T> groupItems()
Multi
grouping items from this Multi
into various "form of chunks" (list, Multi
).
The grouping can be done linearly (MultiGroup.intoLists()
and MultiGroup.intoMultis()
, or based
on a grouping function (MultiGroup.by(Function)
)Multi<T> emitOn(Executor executor)
Multi
invoking the onItem
, onFailure
and onCompletion
methods
on the supplied Executor
.
Instead of receiving the item
event on the thread firing the event, this method influences the
threading context to switch to a thread from the given executor. Same behavior for failure and completion.
Note that the subscriber is guaranteed to never be called concurrently.
executor
- the executor to use, must not be null
Multi
Multi<T> subscribeOn(Executor executor)
Multi
, execute the subscription to the upstream Multi
on a
thread from the given executor. As a result, the Subscriber.onSubscribe(Subscription)
method will be called
on this thread (except mentioned otherwise)executor
- the executor to use, must not be null
Multi
MultiOnCompletion<T> onCompletion()
Multi
fires the completion event.MultiTransform<T> transform()
MultiOverflow<T> onOverflow()
Multi
.MultiBroadcast<T> broadcast()
Multi
be able to broadcast its events (items
, failure
, and completion
)
to multiple subscribers.MultiConvert<T> convert()
Multi
to other types
Examples:
multi.convert().with(multi -> x); // Convert with a custom lambda converter
Multi
instanceMultiConvert
default <O> Multi<O> map(Function<? super T,? extends O> mapper)
Multi
invoking the given function for each item emitted by the upstream Multi
.
The function receives the received item as parameter, and can transform it. The returned object is sent
downstream as item
event.
This method is a shortcut for multi.onItem().apply(mapper)
.
O
- the type of item produced by the mapper functionmapper
- the mapper function, must not be null
Multi
default <O> Multi<O> flatMap(Function<? super T,? extends org.reactivestreams.Publisher<? extends O>> mapper)
Multi
containing the items from Publisher
produced by the mapper
for each
item emitted by this Multi
.
The operation behaves as follows:
Multi
, the mapper is called and produces a Publisher
(potentially a Multi
). The mapper must not return null
Publisher
are then merged in the
produced Multi
. The flatten process may interleaved items.multi.onItem().producePublisher(mapper).merge()
.default <O> Multi<O> concatMap(Function<? super T,? extends org.reactivestreams.Publisher<? extends O>> mapper)
Multi
containing the items from Publisher
produced by the mapper
for each
item emitted by this Multi
.
The operation behaves as follows:
Multi
, the mapper is called and produces a Publisher
(potentially a Multi
). The mapper must not return null
Publisher
are then concatenated in the
produced Multi
. The flatten process makes sure that the items are not interleaved.
This method is equivalent to multi.onItem().producePublisher(mapper).concatenate()
.
Copyright © 2019–2020 SmallRye. All rights reserved.