Package io.smallrye.mutiny.helpers
Class UniCallbackSubscriber<T>
- java.lang.Object
-
- io.smallrye.mutiny.helpers.UniCallbackSubscriber<T>
-
- Type Parameters:
T- the type of item received by this subscriber
- All Implemented Interfaces:
Cancellable,UniSubscriber<T>,UniSubscription,org.reactivestreams.Subscription
public class UniCallbackSubscriber<T> extends java.lang.Object implements UniSubscriber<T>, UniSubscription
Implementation of aUniSubscriberbased on callbacks. This implementation also implementUniSubscriptionto expose thecancel()method.
-
-
Constructor Summary
Constructors Constructor Description UniCallbackSubscriber(java.util.function.Consumer<? super T> onResultCallback, java.util.function.Consumer<? super java.lang.Throwable> onFailureCallback)Creates aUniSubscriberconsuming the item and failure of aUni.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcancel()Requests theUnito cancel and clean up resources.voidonFailure(java.lang.Throwable t)Called if the computation of the item by the subscriberUnifailed.voidonItem(T x)Event handler called once the item has been computed by the subscribedUni.voidonSubscribe(UniSubscription sub)Event handler called once the subscribedUnihas taken into account the subscription.-
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
-
UniCallbackSubscriber
public UniCallbackSubscriber(java.util.function.Consumer<? super T> onResultCallback, java.util.function.Consumer<? super java.lang.Throwable> onFailureCallback)
Creates aUniSubscriberconsuming the item and failure of aUni.- Parameters:
onResultCallback- callback invoked on item event, must not benullonFailureCallback- callback invoked on failure event, must not benull
-
-
Method Detail
-
onSubscribe
public final void onSubscribe(UniSubscription sub)
Description copied from interface:UniSubscriberEvent handler called once the subscribedUnihas taken into account the subscription. TheUnihave 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:
onSubscribein interfaceUniSubscriber<T>- Parameters:
sub- the subscription allowing to cancel the computation.
- Executor: Operate on no particular executor, except if
-
onFailure
public final void onFailure(java.lang.Throwable t)
Description copied from interface:UniSubscriberCalled if the computation of the item by the subscriberUnifailed. 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:
onFailurein interfaceUniSubscriber<T>- Parameters:
t- the failure, cannot benull.
- Executor: Operate on no particular executor, except if
-
onItem
public final void onItem(T x)
Description copied from interface:UniSubscriberEvent 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:
onItemin interfaceUniSubscriber<T>- Parameters:
x- the item, may benull.
- Executor: Operate on no particular executor, except if
-
cancel
public void cancel()
Description copied from interface:UniSubscriptionRequests theUnito 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
cancellationevent upstream.- Specified by:
cancelin interfaceCancellable- Specified by:
cancelin interfaceorg.reactivestreams.Subscription- Specified by:
cancelin interfaceUniSubscription
-
-