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
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 thisMulti
be able to broadcast its events (items
,failure
, andcompletion
) to multiple subscribers.Multi<T>
cache()
Creates a newMulti
that 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 aMulti
to other typesMulti<T>
emitOn(java.util.concurrent.Executor executor)
Produces a newMulti
invoking theonItem
,onFailure
andonCompletion
methods on the suppliedExecutor
.MultiGroup<T>
group()
Multi<T>
log()
Log events (onSubscribe, onItem, ...) as they come from the upstream or the subscriber, and derives the identifier from the upstream operator class "simple name".Multi<T>
log(java.lang.String identifier)
Log events (onSubscribe, onItem, ...) as they come from the upstream or the subscriber.MultiOnCancel<T>
onCancellation()
Configures actions when the subscriber cancels the subscription.MultiOnCompletion<T>
onCompletion()
Allows configuring the actions or continuation to execute when thisMulti
fires 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 anitem
event is received from the thisMulti
MultiOverflow<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 observedMulti
sends aSubscription
.MultiOnSubscribe<T>
onSubscription()
Configures the action to execute when the observedMulti
sends aSubscription
.MultiOnTerminate<T>
onTermination()
Configures actions when thisMulti
terminates 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
.void
subscribe(MultiSubscriber<? super T> subscriber)
void
subscribe(org.reactivestreams.Subscriber<? super T> subscriber)
Multi<T>
toHotStream()
Produces a newMulti
transforming thisMulti
into 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:
subscribe
in interfaceorg.reactivestreams.Publisher<T>
-
onItem
public MultiOnItem<T> onItem()
Description copied from interface:Multi
Configures the behavior when anitem
event is received from the thisMulti
-
subscribe
public MultiSubscribe<T> subscribe()
Description copied from interface:Multi
Configures the subscriber consuming thisMulti
.
-
toUni
public Uni<T> toUni()
Description copied from interface:Multi
Creates aUni
from thisMulti
.When a subscriber subscribes to the returned
Uni
, it subscribes to thisMulti
and requests one item. The event emitted by thisMulti
are 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
null
item is fired by the producesUni
- any item or failure events received after the first event is dropped
If the subscription on the produced
Uni
is cancelled, the subscription to the passedMulti
is also cancelled. - on item event, the item is fired by the produced
-
onFailure
public MultiOnFailure<T> onFailure()
Description copied from interface:Multi
LikeMulti.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:Multi
Configures a predicate filtering the failures on which the behavior (specified with the returnedMultiOnFailure
) 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 typeIOException
.
-
onFailure
public MultiOnFailure<T> onFailure(java.lang.Class<? extends java.lang.Throwable> typeOfFailure)
Description copied from interface:Multi
Configures a type of failure filtering the failures on which the behavior (specified with the returnedMultiOnFailure
) 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 typeIOException
.*
-
cache
public Multi<T> cache()
Description copied from interface:Multi
Creates a newMulti
that 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:Multi
Produces a newMulti
invoking theonItem
,onFailure
andonCompletion
methods on the suppliedExecutor
.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.
-
runSubscriptionOn
public Multi<T> runSubscriptionOn(java.util.concurrent.Executor executor)
Description copied from interface:Multi
When a subscriber subscribes to thisMulti
, execute the subscription to the upstreamMulti
on a thread from the given executor. As a result, theSubscriber.onSubscribe(Subscription)
method will be called on this thread (except mentioned otherwise)- Specified by:
runSubscriptionOn
in interfaceMulti<T>
- Parameters:
executor
- the executor to use, must not benull
- Returns:
- a new
Multi
-
onCompletion
public MultiOnCompletion<T> onCompletion()
Description copied from interface:Multi
Allows configuring the actions or continuation to execute when thisMulti
fires the completion event.- Specified by:
onCompletion
in interfaceMulti<T>
- Returns:
- the object to configure the action.
-
transform
public MultiTransform<T> transform()
Description copied from interface:Multi
Transforms the streams by skipping, selecting, or merging.
-
select
public MultiSelect<T> select()
Description copied from interface:Multi
Selects items from thisMulti
.
-
skip
public MultiSkip<T> skip()
Description copied from interface:Multi
Skips items from thisMulti
.
-
onOverflow
public MultiOverflow<T> onOverflow()
Description copied from interface:Multi
Configures the back-pressure behavior when the consumer cannot keep up with the emissions from thisMulti
.- Specified by:
onOverflow
in interfaceMulti<T>
- Returns:
- the object to configure the overflow strategy
-
onSubscribe
public MultiOnSubscribe<T> onSubscribe()
Description copied from interface:Multi
Configures the action to execute when the observedMulti
sends 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:
onSubscribe
in interfaceMulti<T>
- Returns:
- the object to configure the action to execution on subscription.
-
onSubscription
public MultiOnSubscribe<T> onSubscription()
Description copied from interface:Multi
Configures the action to execute when the observedMulti
sends aSubscription
. The downstream does not have a subscription yet. It will be passed once the configured action completes.For example:
multi.onSubscription().invoke(sub -> System.out.println("subscribed")); // Delay the subscription by 1 second (or until an asynchronous action completes) multi.onSubscription().call(sub -> Uni.createFrom(1).onItem().delayIt().by(Duration.ofSecond(1)));
- Specified by:
onSubscription
in interfaceMulti<T>
- Returns:
- the object to configure the action to execution on subscription.
-
broadcast
public MultiBroadcast<T> broadcast()
Description copied from interface:Multi
Makes thisMulti
be able to broadcast its events (items
,failure
, andcompletion
) to multiple subscribers.
-
convert
public MultiConvert<T> convert()
Description copied from interface:Multi
Converts aMulti
to other typesExamples:
multi.convert().with(multi -> x); // Convert with a custom lambda converter
- Specified by:
convert
in interfaceMulti<T>
- Returns:
- the object to convert an
Multi
instance - See Also:
MultiConvert
-
onTermination
public MultiOnTerminate<T> onTermination()
Description copied from interface:Multi
Configures actions when thisMulti
terminates on completion, on failure or on subscriber cancellation.- Specified by:
onTermination
in interfaceMulti<T>
- Returns:
- the object to configure the termination actions
-
onCancellation
public MultiOnCancel<T> onCancellation()
Description copied from interface:Multi
Configures actions when the subscriber cancels the subscription.- Specified by:
onCancellation
in interfaceMulti<T>
- Returns:
- the object to configure the cancellation actions
-
onRequest
public MultiOnRequest<T> onRequest()
Description copied from interface:Multi
Configures actions when items are being requested.
-
collect
public MultiCollect<T> collect()
Description copied from interface:Multi
ProducesUni
collecting/aggregating items from thisMulti
. It allows accumulating the items emitted by thismulti
into a structure such as a into aList
(MultiCollect.asList()
), aMap
(MultiCollect.asMap(Function)
, or a custom collector. When thismulti
sends the completion signal, the structure is emitted by the returnedUni
.If this
Multi
emits a failure, the producedUni
produces 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:Multi
ProducesMulti
grouping items from thisMulti
into 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:Multi
Produces a newMulti
transforming thisMulti
into 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 aBackPressureFailure
failure.- Specified by:
toHotStream
in interfaceMulti<T>
- Returns:
- the new multi.
-
log
public Multi<T> log(java.lang.String identifier)
Description copied from interface:Multi
Log events (onSubscribe, onItem, ...) as they come from the upstream or the subscriber. Events will be logged as long as theMulti
hasn't been cancelled or terminated. Logging is framework-agnostic and can be configured in theInfrastructure
class.- Specified by:
log
in interfaceMulti<T>
- Parameters:
identifier
- an identifier of this operator to be used in log events- Returns:
- a new
Multi
- See Also:
Infrastructure.setOperatorLogger(Infrastructure.OperatorLogger)
-
log
public Multi<T> log()
Description copied from interface:Multi
Log events (onSubscribe, onItem, ...) as they come from the upstream or the subscriber, and derives the identifier from the upstream operator class "simple name". Events will be logged as long as theMulti
hasn't been cancelled or terminated. Logging is framework-agnostic and can be configured in theInfrastructure
class.- Specified by:
log
in interfaceMulti<T>
- Returns:
- a new
Multi
- See Also:
Multi.log(String)
,Infrastructure.setOperatorLogger(Infrastructure.OperatorLogger)
-
-