Class DefaultUniEmitter<T>
- java.lang.Object
-
- io.smallrye.mutiny.operators.uni.builders.DefaultUniEmitter<T>
-
- Type Parameters:
T
- the type of item emitted by the emitter
- All Implemented Interfaces:
Cancellable
,ContextSupport
,UniEmitter<T>
,UniSubscription
,org.reactivestreams.Subscription
public class DefaultUniEmitter<T> extends java.lang.Object implements UniEmitter<T>, UniSubscription
Implementation of the Uni Emitter. This implementation makes sure:- only the first event is propagated downstream
- termination action is called only once and then drop
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
cancel()
Requests theUni
to cancel and clean up resources.void
complete(T item)
Emits theitem
event downstream with the given (potentiallynull
) item.Context
context()
Provide a context.void
fail(java.lang.Throwable failure)
Emits thefailure
event downstream with the given exception.boolean
isTerminated()
UniEmitter<T>
onTermination(java.lang.Runnable onTermination)
Attaches a @{code termination} event handler invoked when the downstreamUniSubscription
is cancelled, or when the emitter has emitted either anitem
orfailure
event.-
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
-
-
-
-
Method Detail
-
complete
public void complete(T item)
Description copied from interface:UniEmitter
Emits theitem
event downstream with the given (potentiallynull
) item.Calling this method multiple times or after the
UniEmitter.fail(Throwable)
method has no effect.- Specified by:
complete
in interfaceUniEmitter<T>
- Parameters:
item
- the item, may benull
-
fail
public void fail(java.lang.Throwable failure)
Description copied from interface:UniEmitter
Emits thefailure
event downstream with the given exception.Calling this method multiple times or after the
UniEmitter.complete(Object)
method has no effect.- Specified by:
fail
in interfaceUniEmitter<T>
- Parameters:
failure
- the exception, must not benull
-
onTermination
public UniEmitter<T> onTermination(java.lang.Runnable onTermination)
Description copied from interface:UniEmitter
Attaches a @{code termination} event handler invoked when the downstreamUniSubscription
is cancelled, or when the emitter has emitted either anitem
orfailure
event.This method allows cleanup resources once the emitter can be disposed (has reached a terminal state).
If the registration of the
onTermination
callback is done after the termination, it invokes the callback immediately.- Specified by:
onTermination
in interfaceUniEmitter<T>
- Parameters:
onTermination
- the action to run on termination, must not benull
- Returns:
- this emitter
-
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
-
isTerminated
public boolean isTerminated()
-
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
.
-
-