Package io.smallrye.mutiny.subscription
Class UniSerializedSubscriber<T>
- java.lang.Object
-
- io.smallrye.mutiny.subscription.UniSerializedSubscriber<T>
-
- All Implemented Interfaces:
Cancellable
,ContextSupport
,UniSubscriber<T>
,UniSubscription
,org.reactivestreams.Subscription
public class UniSerializedSubscriber<T> extends java.lang.Object implements UniSubscriber<T>, UniSubscription
An implementation ofUniSubscriber
andUniSubscription
making sure event handlers are only called once.
-
-
Constructor Summary
Constructors Constructor Description UniSerializedSubscriber(AbstractUni<T> upstream, UniSubscriber<? super T> subscriber)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
cancel()
Requests theUni
to cancel and clean up resources.Context
context()
Provide a context.void
onFailure(java.lang.Throwable throwable)
Called if the computation of the item by the subscriberUni
failed.void
onItem(T item)
Event handler called once the item has been computed by the subscribedUni
.void
onSubscribe(UniSubscription subscription)
Event handler called once the subscribedUni
has taken into account the subscription.static <T> void
subscribe(AbstractUni<T> source, UniSubscriber<? super T> subscriber)
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.smallrye.mutiny.subscription.UniSubscription
request
-
-
-
-
Constructor Detail
-
UniSerializedSubscriber
public UniSerializedSubscriber(AbstractUni<T> upstream, UniSubscriber<? super T> subscriber)
-
-
Method Detail
-
subscribe
public static <T> void subscribe(AbstractUni<T> source, UniSubscriber<? super T> subscriber)
-
context
public Context context()
Description copied from interface:ContextSupport
Provide a context.Since calls to this method shall only be triggered when a Mutiny pipeline uses a
withContext
operator, there is no need in general for caching the context value in a field of the implementing class. Exceptions include operators that have cross-subscriber semantics such as memoizers or broadcasters.This method is expected to be called once per
withContext
operator.- Specified by:
context
in interfaceContextSupport
- Returns:
- the context, must not be
null
.
-
onSubscribe
public void onSubscribe(UniSubscription subscription)
Description copied from interface:UniSubscriber
Event handler called once the subscribedUni
has taken into account the subscription. TheUni
have triggered the computation of the item. IMPORTANT:UniSubscriber.onItem(Object)
andUniSubscriber.onFailure(Throwable)
would not be called before the invocation of this method.- Executor: Operate on no particular executor, except if
Uni.runSubscriptionOn(Executor)
has been called - Exception: Throwing an exception cancels the subscription,
UniSubscriber.onItem(Object)
andUniSubscriber.onFailure(Throwable)
won't be called
- Specified by:
onSubscribe
in interfaceUniSubscriber<T>
- Parameters:
subscription
- the subscription allowing to cancel the computation.
- Executor: Operate on no particular executor, except if
-
onItem
public void onItem(T item)
Description copied from interface:UniSubscriber
Event handler called once the item has been computed by the subscribedUni
. IMPORTANT: this method will be only called once per subscription. IfUniSubscriber.onFailure(Throwable)
is called, this method won't be called.- Executor: Operate on no particular executor, except if
Uni.emitOn(java.util.concurrent.Executor)
has been called - Exception: Throwing an exception cancels the subscription.
- Specified by:
onItem
in interfaceUniSubscriber<T>
- Parameters:
item
- the item, may benull
.
- Executor: Operate on no particular executor, except if
-
onFailure
public void onFailure(java.lang.Throwable throwable)
Description copied from interface:UniSubscriber
Called if the computation of the item by the subscriberUni
failed. IMPORTANT: this method will be only called once per subscription. IfUniSubscriber.onItem(Object)
is called, this method won't be called.- Executor: Operate on no particular executor, except if
Uni.emitOn(java.util.concurrent.Executor)
has been called - Exception: Throwing an exception cancels the subscription.
- Specified by:
onFailure
in interfaceUniSubscriber<T>
- Parameters:
throwable
- the failure, cannot benull
.
- Executor: Operate on no particular executor, except if
-
cancel
public void cancel()
Description copied from interface:UniSubscription
Requests theUni
to cancel and clean up resources. If the item is retrieved after cancellation, it is not forwarded to the subscriber. If the cancellation happens after the delivery of the item, this call is ignored.Calling this method, emits the
cancellation
event upstream.- Specified by:
cancel
in interfaceCancellable
- Specified by:
cancel
in interfaceorg.reactivestreams.Subscription
- Specified by:
cancel
in interfaceUniSubscription
-
-