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 Multi<T> |
filter(Predicate<? super T> predicate)
|
default <O> Multi<O> |
flatMap(Function<? super T,? extends org.reactivestreams.Publisher<? extends O>> mapper)
|
MultiGroup<T> |
groupItems()
|
default Multi<T> |
invoke(Consumer<? super T> callback)
Produces a new
Multi invoking the given callback when an item event is fired by the upstream. |
default Multi<T> |
invokeUni(Function<? super T,? extends Uni<?>> action)
Produces a new
Multi invoking the given @{code action} when an item event is received. |
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 configuring 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. |
MultiOnSubscribe<T> |
onSubscribe()
Configures the action to execute when the observed
Multi sends a Subscription. |
MultiOnTerminate<T> |
onTermination()
Configures actions when this
Multi terminates on completion, on failure or on subscriber cancellation. |
Multi<T> |
runSubscriptionOn(Executor executor)
|
default <O> O |
stage(Function<Multi<T>,O> stage)
Allows structuring the pipeline by creating a logic separation:
|
MultiSubscribe<T> |
subscribe()
Configures the subscriber consuming this
Multi. |
default Multi<T> |
subscribeOn(Executor executor)
Deprecated.
Use
runSubscriptionOn(Executor) instead. |
default <O> O |
then(Function<Multi<T>,O> stage)
Deprecated.
use
stage(Function) |
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@Deprecated default <O> O then(Function<Multi<T>,O> stage)
stage(Function)
Multi multi = upstream
.then(m -> { ...})
.then(m -> { ...})
.then(m -> { ...})
With `then` you can structure and chain groups of processing.
default <O> O stage(Function<Multi<T>,O> stage)
Multi multi = upstream
.stage(m -> { ...})
.stage(m -> { ...})
.stage(m -> { ...})
With `stage` 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:
UniUninull 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.
UniMultiOnFailure<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 failuresMultiOnSubscribe<T> onSubscribe()
Multi sends a Subscription.
The downstream don't have a subscription yet. It will be passed once the configured action completes.
For example:
multi.onSubscribe().invoke(sub -> System.out.println("subscribed"));
// Delay the subscription by 1 second (or until an asynchronous action completes)
multi.onSubscribe().invokeUni(sub -> Uni.createFrom(1).onItem().delayIt().by(Duration.ofSecond(1)));
MultiOnFailure<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 nullMultiOnEvent<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 nullMulti@Deprecated default Multi<T> subscribeOn(Executor executor)
runSubscriptionOn(Executor) instead.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 nullMultiMulti<T> runSubscriptionOn(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 nullMultiMultiOnCompletion<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 instanceMultiConvertdefault Multi<T> filter(Predicate<? super T> predicate)
Multi with items from the upstream Multi matching the predicate.
Items that do not satisfy the predicate are discarded.
This method is a shortcut for multi.transform().byFilteringItemsWith(predicate).
predicate - a predicate, must not be nullMultidefault <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 nullMultidefault <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 nullPublisher are then merged in the
produced Multi. The flatten process may interleaved items.multi.onItem().transformToMulti(mapper).merge().default Multi<T> invoke(Consumer<? super T> callback)
Multi invoking the given callback when an item event is fired by the upstream.
Note that the received item cannot be null.
If the callback throws an exception, this exception is propagated to the downstream as failure. No more items will be consumed.
This method is a shortcut on MultiOnItem.invoke(Consumer).
callback - the callback, must not be nullMultidefault Multi<T> invokeUni(Function<? super T,? extends Uni<?>> action)
Multi invoking the given @{code action} when an item event is received. Note that
the received item cannot be null.
Unlike invoke(Consumer), the passed function returns a Uni. When the produced Uni sends
its result, the result is discarded, and the original item is forwarded downstream. If the produced
Uni fails, the failure is propagated downstream. If the action throws an exception, this exception is
propagated downstream as failure.
This method preserves the order of the items, meaning that the downstream received the items in the same order as the upstream has emitted them.
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 nullPublisher 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().transformToMulti(mapper).concatenate().
MultiOnTerminate<T> onTermination()
Multi terminates on completion, on failure or on subscriber cancellation.Copyright © 2019–2020 SmallRye. All rights reserved.