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
,ContextSupport
,UniSubscriber<T>
,UniSubscription
,org.reactivestreams.Subscription
public class UniCallbackSubscriber<T> extends java.lang.Object implements UniSubscriber<T>, UniSubscription
Implementation of aUniSubscriber
based on callbacks. This implementation also implementUniSubscription
to 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, Context context)
Creates aUniSubscriber
consuming the item and failure of aUni
.
-
Method Summary
All 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 t)
Called if the computation of the item by the subscriberUni
failed.void
onItem(T x)
Event handler called once the item has been computed by the subscribedUni
.void
onSubscribe(UniSubscription sub)
Event handler called once the subscribedUni
has 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, Context context)
Creates aUniSubscriber
consuming the item and failure of aUni
.- Parameters:
onResultCallback
- callback invoked on item event, must not benull
onFailureCallback
- callback invoked on failure event, must not benull
context
- the subscriber context, must not benull
-
-
Method Detail
-
onSubscribe
public final void onSubscribe(UniSubscription sub)
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:
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: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:
t
- the failure, cannot benull
.
- Executor: Operate on no particular executor, except if
-
onItem
public final void onItem(T x)
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:
x
- the item, may 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
-
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
.
-
-