public abstract class AbstractUni<T> extends Object implements Uni<T>
| Constructor and Description |
|---|
AbstractUni() |
| Modifier and Type | Method and Description |
|---|---|
UniAndGroup<T> |
and()
Combines a set of
unis into a joined item. |
<T2> Uni<Tuple2<T,T2>> |
and(Uni<T2> other)
|
UniAwait<T> |
await()
Awaits (blocking the caller thread) until the item or a failure is emitted by the observed
Uni. |
Uni<T> |
cache()
Caches the events (item or failure) of this
Uni and replays it for all further UniSubscriber. |
UniConvert<T> |
convert()
Converts an
Uni to other types such as CompletionStage |
Uni<T> |
emitOn(Executor executor)
Produces a new
Uni invoking the UniSubscriber.onItem(Object) and
UniSubscriber.onFailure(Throwable) on the supplied Executor. |
UniIfNoItem<T> |
ifNoItem()
Produces a
Uni reacting when a no item event is fired by the upstream uni during the specified time
period. |
UniOnEvent<T> |
on()
Allows adding behavior when various type of events are emitted by the current
Uni (item, failure) or
by the subscriber (cancellation, subscription) |
UniOnFailure<T> |
onFailure()
Like
Uni.onFailure(Predicate) but applied to all failures fired by the upstream uni. |
UniOnFailure<T> |
onFailure(Class<? extends Throwable> typeOfFailure)
Configures a type of failure filtering the failures on which the behavior (specified with the returned
UniOnFailure) is applied. |
UniOnFailure<T> |
onFailure(Predicate<? super Throwable> predicate)
Configures a predicate filtering the failures on which the behavior (specified with the returned
UniOnFailure) is applied. |
UniOnItem<T> |
onItem()
Configures the action to execute when the observed
Uni emits the item (potentially null). |
UniOnItemOrFailure<T> |
onItemOrFailure()
Configures the action to execute when the observed
Uni emits either an item (potentially null))
or a failure. |
UniOnSubscribe<T> |
onSubscribe()
Configures the action to execute when the observed
Uni sends a UniSubscription. |
UniOnTerminate<T> |
onTermination()
Configures actions to be performed on termination, that is, on item, on failure, or when the subscriber cancels
the subscription.
|
UniOr<T> |
or()
Composes this
Uni with a set of Uni passed to
UniOr.unis(Uni[]) to produce a new Uni forwarding the first event
(item or failure). |
UniRepeat<T> |
repeat()
Allows configuring repeating behavior.
|
Uni<T> |
runSubscriptionOn(Executor executor)
|
UniSubscribe<T> |
subscribe()
Requests the
Uni to start resolving the item and allows configuring how the signals are propagated
(using a UniSubscriber, callbacks, or a CompletionStage. |
static <T> void |
subscribe(Uni<? extends T> upstream,
UniSubscriber<? super T> subscriber)
Encapsulates subscription to slightly optimized the AbstractUni case.
|
protected abstract void |
subscribing(UniSerializedSubscriber<? super T> subscriber) |
Multi<T> |
toMulti()
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitchain, combine, createFrom, eventually, eventually, flatMap, invoke, invokeUni, map, stage, subscribeAsCompletionStage, subscribeOn, then, thenprotected abstract void subscribing(UniSerializedSubscriber<? super T> subscriber)
public static <T> void subscribe(Uni<? extends T> upstream, UniSubscriber<? super T> subscriber)
T - the type of itemupstream - the upstream, must not be null (not checked)subscriber - the subscriber, must not be null (not checked)public UniSubscribe<T> subscribe()
UniUni to start resolving the item and allows configuring how the signals are propagated
(using a UniSubscriber, callbacks, or a CompletionStage. Unlike Uni.await(), this method
configures non-blocking retrieval of the item and failure.
Examples:
Uni<String> uni = ...;
Subscription sub = uni.subscribe().with( // The return subscription can be used to cancel the operation
item -> {}, // Callback calls on item
failure -> {} // Callback calls on failure
);
UniSubscriber<String> myUniSubscriber = ...
uni.subscribe().withSubscriber(myUniSubscriber); // Subscribes to the Uni with the passed subscriber
CompletableFuture future = uni.subscribe().asCompletableFuture(); // Get a CompletionStage receiving the item or failure
// Cancelling the returned future cancels the subscription.
subscribe in interface Uni<T>uni.await() for waiting (blocking the caller thread) until the resolution of the observed Uni.public UniOnItem<T> onItem()
UniUni emits the item (potentially null).
Examples:
Uni<T> uni = ...;
uni.onItem().transform(x -> ...); // Transform the item into another item (~ map)
uni.onItem().transformToUni(x -> ...); // Transform the item into a Uni (~ flatMap)
public UniIfNoItem<T> ifNoItem()
UniUni reacting when a no item event is fired by the upstream uni during the specified time
period.
This Uni detects if this Uni does not emit an item before the configured timeout.
Examples:
uni.ifNoItem().after(Duration.ofMillis(1000).fail() // Propagate a TimeOutException
uni.ifNoItem().after(Duration.ofMillis(1000).recoverWithValue("fallback") // Inject a fallback item on timeout
uni.ifNoItem().after(Duration.ofMillis(1000).on(myExecutor)... // Configure the executor calling on timeout actions
uni.ifNoItem().after(Duration.ofMillis(1000).retry().atMost(5) // Retry five times
public UniOnFailure<T> onFailure()
UniUni.onFailure(Predicate) but applied to all failures fired by the upstream uni.
It allows configuring the on failure behavior (recovery, retry...).public UniOnFailure<T> onFailure(Predicate<? super Throwable> predicate)
UniUniOnFailure) is applied.
For instance, to only when an IOException is fired as failure you can use:
uni.onFailure(IOException.class).recoverWithItem("hello")
The fallback value (hello) will only be used if the upstream uni fire a failure of type
IOException.
public UniOnFailure<T> onFailure(Class<? extends Throwable> typeOfFailure)
UniUniOnFailure) is applied.
For instance, to only when an IOException is fired as failure you can use:
uni.onFailure(IOException.class).recoverWithItem("hello")
The fallback value (hello) will only be used if the upstream uni fire a failure of type
IOException.
public UniOnSubscribe<T> onSubscribe()
UniUni sends a UniSubscription.
The downstream don't have a subscription yet. It will be passed once the configured action completes.
Example:
uni.onSubscribe().invoke(sub -> System.out.println("subscribed"));
// Delay the subscription by 1 second (or until an asynchronous action completes)
uni.onSubscribe().invokeUni(sub -> Uni.createFrom(1).onItem().delayIt().by(Duration.ofSecond(1)));
onSubscribe in interface Uni<T>public UniOnItemOrFailure<T> onItemOrFailure()
UniUni emits either an item (potentially null))
or a failure. Unlike Uni.onItem() and Uni.onFailure() the action would handle both cases in on "go".onItemOrFailure in interface Uni<T>public UniAndGroup<T> and()
Uniunis into a joined item. This item can be a Tuple or the item of a
combinator function.
If one of the combine Uni fire a failure, the other unis are cancelled, and the resulting
Uni fires the failure. If collectFailures() is called,
it waits for the completion of all the unis before propagating the failure event. If more than one
Uni failed, a CompositeException is fired, wrapping the different collected failures.
Depending on the number of participants, the produced Tuple is
different from Tuple2 to Tuple9. For more participants,
use UniAndGroup.unis(Uni[]) or
UniAndGroup.unis(Iterable).
and in interface Uni<T>Uni.all() for the equivalent static operatorpublic <T2> Uni<Tuple2<T,T2>> and(Uni<T2> other)
UniUni with the item of other into a Tuple2.
If this or other fails, the other resolution is cancelled.and in interface Uni<T>T2 - the type to pairother - the other Uni, must not be nulland for more options on the combination of items,
Uni.all() for the equivalent static operatorpublic UniOr<T> or()
UniUni with a set of Uni passed to
UniOr.unis(Uni[]) to produce a new Uni forwarding the first event
(item or failure). It behaves like the fastest of these competing unis.
The process subscribes to the set of Uni. When one of the Uni fires an item or a failure,
the event is propagated downstream. Also the other subscriptions are cancelled.
Note that the callback from the subscriber are called on the thread used to fire the winning Uni.
Use Uni.emitOn(Executor) to change the thread.
If the subscription to the returned Uni is cancelled, the subscription to the unis from the
iterable are also cancelled.
or in interface Uni<T>Uni.any for a static version of this operator, like
Uni first = Uni.any().of(uni1, uni2);public UniAwait<T> await()
UniUni.
If the observed uni fails, the failure is thrown. In the case of a checked exception, the exception is wrapped
into a CompletionException.
Examples:
Uni<T> uni = ...;
T res = uni.await().indefinitely(); // Await indefinitely until it get the item.
T res = uni.await().atMost(Duration.ofMillis(1000)); // Awaits at most 1s. After that, a TimeoutException is thrown
Optional<T> res = uni.await().asOptional().indefinitely(); // Retrieves the item as an Optional, empty if the item is null
public Uni<T> emitOn(Executor executor)
UniUni invoking the UniSubscriber.onItem(Object) and
UniSubscriber.onFailure(Throwable) on the supplied Executor.
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.
public Uni<T> runSubscriptionOn(Executor executor)
UniUni, executes the subscription to the upstream Uni on a thread
from the given executor. As a result, the UniSubscriber.onSubscribe(UniSubscription) method will be called
on this thread (except mentioned otherwise)runSubscriptionOn in interface Uni<T>executor - the executor to use, must not be nullUnipublic Uni<T> cache()
UniUni and replays it for all further UniSubscriber.public UniConvert<T> convert()
UniUni to other types such as CompletionStage
Examples:
uni.convert().toCompletionStage(); // Convert to CompletionStage using convenience method
uni.convert().with(BuiltinConverters.toCompletionStage()); // Convert to CompletionStage using BuiltInConverters
uni.convert().with(uni -> x); // Convert with a custom lambda converter
convert in interface Uni<T>Uni instanceUniConvertpublic Multi<T> toMulti()
UniMulti from this Uni.
When a subscriber subscribes to the returned Multi and request an item, it subscribes
to this Uni and the events from this Uni are propagated to the Multi:
Uni emits a non-null item - this item is propagated to the Multi
and followed with the completion eventUni emits a null item - the Multi fires the completion eventUni emits a failure, this failure event is propagated by the Multi
It's important to note that the subscription to this Uni happens when the subscriber to the produced
Multi requests items, and not at subscription time.
public UniOnEvent<T> on()
UniUni (item, failure) or
by the subscriber (cancellation, subscription)public UniOnTerminate<T> onTermination()
UnionTermination in interface Uni<T>Copyright © 2019–2020 SmallRye. All rights reserved.