Class AbstractMulti<T>
- java.lang.Object
-
- io.smallrye.mutiny.operators.AbstractMulti<T>
-
- All Implemented Interfaces:
Multi<T>,org.reactivestreams.Publisher<T>
- Direct Known Subclasses:
AbstractMultiOperator,BroadcastProcessor,CollectionBasedMulti,ConnectableMulti,DeferredMulti,EmitterBasedMulti,EmptyMulti,FailedMulti,GeneratorBasedMulti,IntervalMulti,IterableBasedMulti,MultiConcatOp,MultiGroupByOp.GroupedUnicast,MultiOperator,MultiReferenceCount,MultiZipOp,NeverMulti,ResourceMulti,StreamBasedMulti,UnicastProcessor,UniOnItemTransformToMulti
public abstract class AbstractMulti<T> extends java.lang.Object implements Multi<T>
-
-
Constructor Summary
Constructors Constructor Description AbstractMulti()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description MultiBroadcast<T>broadcast()Makes thisMultibe able to broadcast its events (items,failure, andcompletion) to multiple subscribers.Multi<T>cache()Creates a newMultithat subscribes to this upstream and caches all of its events and replays them, to all the downstream subscribers.MultiCollect<T>collect()MultiConvert<T>convert()Converts aMultito other typesMulti<T>emitOn(java.util.concurrent.Executor executor)Produces a newMultiinvoking theonItem,onFailureandonCompletionmethods on the suppliedExecutor.MultiGroup<T>group()MultiOnEvent<T>on()Allows adding behavior when various type of events are emitted by the currentMulti(item, failure, completion) or by the subscriber (cancellation, request, subscription)MultiOnCancel<T>onCancellation()Configures actions when the subscriber cancels the subscription.MultiOnCompletion<T>onCompletion()Allows configuring the actions or continuation to execute when thisMultifires the completion event.MultiOnFailure<T>onFailure()LikeMulti.onFailure(Predicate)but applied to all failures fired by the upstream multi.MultiOnFailure<T>onFailure(java.lang.Class<? extends java.lang.Throwable> typeOfFailure)Configures a type of failure filtering the failures on which the behavior (specified with the returnedMultiOnFailure) is applied.MultiOnFailure<T>onFailure(java.util.function.Predicate<? super java.lang.Throwable> predicate)Configures a predicate filtering the failures on which the behavior (specified with the returnedMultiOnFailure) is applied.MultiOnItem<T>onItem()Configures the behavior when anitemevent is received from the thisMultiMultiOverflow<T>onOverflow()Configures the back-pressure behavior when the consumer cannot keep up with the emissions from thisMulti.MultiOnRequest<T>onRequest()Configures actions when items are being requested.MultiOnSubscribe<T>onSubscribe()Configures the action to execute when the observedMultisends aSubscription.MultiOnTerminate<T>onTermination()Configures actions when thisMultiterminates on completion, on failure or on subscriber cancellation.Multi<T>runSubscriptionOn(java.util.concurrent.Executor executor)MultiSelect<T>select()Selects items from thisMulti.MultiSkip<T>skip()Skips items from thisMulti.MultiSubscribe<T>subscribe()Configures the subscriber consuming thisMulti.voidsubscribe(MultiSubscriber<? super T> subscriber)voidsubscribe(org.reactivestreams.Subscriber<? super T> subscriber)Multi<T>toHotStream()Produces a newMultitransforming thisMultiinto a hot stream.Uni<T>toUni()MultiTransform<T>transform()Transforms the streams by skipping, selecting, or merging.
-
-
-
Method Detail
-
subscribe
public void subscribe(MultiSubscriber<? super T> subscriber)
-
subscribe
public void subscribe(org.reactivestreams.Subscriber<? super T> subscriber)
- Specified by:
subscribein interfaceorg.reactivestreams.Publisher<T>
-
onItem
public MultiOnItem<T> onItem()
Description copied from interface:MultiConfigures the behavior when anitemevent is received from the thisMulti
-
subscribe
public MultiSubscribe<T> subscribe()
Description copied from interface:MultiConfigures the subscriber consuming thisMulti.
-
toUni
public Uni<T> toUni()
Description copied from interface:MultiCreates aUnifrom thisMulti.When a subscriber subscribes to the returned
Uni, it subscribes to thisMultiand requests one item. The event emitted by thisMultiare then forwarded to theUni:- on item event, the item is fired by the produced
Uni - on failure event, the failure is fired by the produced
Uni - on completion event, a
nullitem is fired by the producesUni - any item or failure events received after the first event is dropped
If the subscription on the produced
Uniis cancelled, the subscription to the passedMultiis also cancelled. - on item event, the item is fired by the produced
-
onFailure
public MultiOnFailure<T> onFailure()
Description copied from interface:MultiLikeMulti.onFailure(Predicate)but applied to all failures fired by the upstream multi. It allows configuring the on failure behavior (recovery, retry...).
-
onFailure
public MultiOnFailure<T> onFailure(java.util.function.Predicate<? super java.lang.Throwable> predicate)
Description copied from interface:MultiConfigures a predicate filtering the failures on which the behavior (specified with the returnedMultiOnFailure) is applied.For instance, to only when an
IOExceptionis 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 typeIOException.
-
onFailure
public MultiOnFailure<T> onFailure(java.lang.Class<? extends java.lang.Throwable> typeOfFailure)
Description copied from interface:MultiConfigures a type of failure filtering the failures on which the behavior (specified with the returnedMultiOnFailure) is applied.For instance, to only when an
IOExceptionis 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 typeIOException.*
-
on
public MultiOnEvent<T> on()
Description copied from interface:MultiAllows adding behavior when various type of events are emitted by the currentMulti(item, failure, completion) or by the subscriber (cancellation, request, subscription)
-
cache
public Multi<T> cache()
Description copied from interface:MultiCreates a newMultithat subscribes to this upstream and caches all of its events and replays them, to all the downstream subscribers.
-
emitOn
public Multi<T> emitOn(java.util.concurrent.Executor executor)
Description copied from interface:MultiProduces a newMultiinvoking theonItem,onFailureandonCompletionmethods on the suppliedExecutor.Instead of receiving the
itemevent 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.
-
runSubscriptionOn
public Multi<T> runSubscriptionOn(java.util.concurrent.Executor executor)
Description copied from interface:MultiWhen a subscriber subscribes to thisMulti, execute the subscription to the upstreamMultion a thread from the given executor. As a result, theSubscriber.onSubscribe(Subscription)method will be called on this thread (except mentioned otherwise)- Specified by:
runSubscriptionOnin interfaceMulti<T>- Parameters:
executor- the executor to use, must not benull- Returns:
- a new
Multi
-
onCompletion
public MultiOnCompletion<T> onCompletion()
Description copied from interface:MultiAllows configuring the actions or continuation to execute when thisMultifires the completion event.- Specified by:
onCompletionin interfaceMulti<T>- Returns:
- the object to configure the action.
-
transform
public MultiTransform<T> transform()
Description copied from interface:MultiTransforms the streams by skipping, selecting, or merging.
-
select
public MultiSelect<T> select()
Description copied from interface:MultiSelects items from thisMulti.
-
skip
public MultiSkip<T> skip()
Description copied from interface:MultiSkips items from thisMulti.
-
onOverflow
public MultiOverflow<T> onOverflow()
Description copied from interface:MultiConfigures the back-pressure behavior when the consumer cannot keep up with the emissions from thisMulti.- Specified by:
onOverflowin interfaceMulti<T>- Returns:
- the object to configure the overflow strategy
-
onSubscribe
public MultiOnSubscribe<T> onSubscribe()
Description copied from interface:MultiConfigures the action to execute when the observedMultisends aSubscription. 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().call(sub -> Uni.createFrom(1).onItem().delayIt().by(Duration.ofSecond(1)));- Specified by:
onSubscribein interfaceMulti<T>- Returns:
- the object to configure the action to execution on subscription.
-
broadcast
public MultiBroadcast<T> broadcast()
Description copied from interface:MultiMakes thisMultibe able to broadcast its events (items,failure, andcompletion) to multiple subscribers.
-
convert
public MultiConvert<T> convert()
Description copied from interface:MultiConverts aMultito other typesExamples:
multi.convert().with(multi -> x); // Convert with a custom lambda converter- Specified by:
convertin interfaceMulti<T>- Returns:
- the object to convert an
Multiinstance - See Also:
MultiConvert
-
onTermination
public MultiOnTerminate<T> onTermination()
Description copied from interface:MultiConfigures actions when thisMultiterminates on completion, on failure or on subscriber cancellation.- Specified by:
onTerminationin interfaceMulti<T>- Returns:
- the object to configure the termination actions
-
onCancellation
public MultiOnCancel<T> onCancellation()
Description copied from interface:MultiConfigures actions when the subscriber cancels the subscription.- Specified by:
onCancellationin interfaceMulti<T>- Returns:
- the object to configure the cancellation actions
-
onRequest
public MultiOnRequest<T> onRequest()
Description copied from interface:MultiConfigures actions when items are being requested.
-
collect
public MultiCollect<T> collect()
Description copied from interface:MultiProducesUnicollecting/aggregating items from thisMulti. It allows accumulating the items emitted by thismultiinto a structure such as a into aList(MultiCollect.asList()), aMap(MultiCollect.asMap(Function), or a custom collector. When thismultisends the completion signal, the structure is emitted by the returnedUni.If this
Multiemits a failure, the producedUniproduces the same failure and the aggregated items are discarded.You can also retrieve the first and last items using
MultiCollect.first()andMultiCollect.last(). Be aware to not used method collecting items on unbounded / infiniteMulti.
-
group
public MultiGroup<T> group()
Description copied from interface:MultiProducesMultigrouping items from thisMultiinto various "form of chunks" (list,Multi). The grouping can be done linearly (MultiGroup.intoLists()andMultiGroup.intoMultis(), or based on a grouping function (MultiGroup.by(Function))
-
toHotStream
public Multi<T> toHotStream()
Description copied from interface:MultiProduces a newMultitransforming thisMultiinto a hot stream. With a hot stream, when no subscribers are present, emitted items are dropped. Late subscribers would only receive items emitted after their subscription. If the upstream has already been terminated, the termination event (failure or completion) is forwarded to the subscribers. Note that this operator consumes the upstream stream without back-pressure. It still enforces downstream back-pressure. If the subscriber is not ready to receive an item when the upstream emits an item, the subscriber gets aBackPressureFailurefailure.- Specified by:
toHotStreamin interfaceMulti<T>- Returns:
- the new multi.
-
-