Class AbstractUni<T>

    • Constructor Detail

      • AbstractUni

        public AbstractUni()
    • Method Detail

      • subscribe

        public abstract void subscribe​(UniSubscriber<? super T> subscriber)
      • subscribe

        public static <T> void subscribe​(Uni<? extends T> upstream,
                                         UniSubscriber<? super T> subscriber)
        Encapsulates subscription to slightly optimize the AbstractUni case. In the case of AbstractUni, it avoid creating the UniSubscribe group instance.
        Type Parameters:
        T - the type of item
        Parameters:
        upstream - the upstream, must not be null (not checked)
        subscriber - the subscriber, must not be null (not checked)
      • subscribe

        public UniSubscribe<T> subscribe()
        Description copied from interface: Uni
        Requests the Uni 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.
         
         
        Specified by:
        subscribe in interface Uni<T>
        Returns:
        the object to configure the subscription.
        See Also:
        uni.await() for waiting (blocking the caller thread) until the resolution of the observed Uni.
      • onItem

        public UniOnItem<T> onItem()
        Description copied from interface: Uni
        Configures the action to execute when the observed Uni 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)
         
         
        Specified by:
        onItem in interface Uni<T>
        Returns:
        the object to configure the action to execute when an item is emitted
      • ifNoItem

        public UniIfNoItem<T> ifNoItem()
        Description copied from interface: Uni
        Produces a Uni 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

        Specified by:
        ifNoItem in interface Uni<T>
        Returns:
        the on timeout group
      • onFailure

        public UniOnFailure<T> onFailure()
        Description copied from interface: Uni
        Like Uni.onFailure(Predicate) but applied to all failures fired by the upstream uni. It allows configuring the on failure behavior (recovery, retry...).
        Specified by:
        onFailure in interface Uni<T>
        Returns:
        a UniOnFailure on which you can specify the on failure action
      • onFailure

        public UniOnFailure<T> onFailure​(java.util.function.Predicate<? super java.lang.Throwable> predicate)
        Description copied from interface: Uni
        Configures a predicate filtering the failures on which the behavior (specified with the returned UniOnFailure) 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.

        Specified by:
        onFailure in interface Uni<T>
        Parameters:
        predicate - the predicate, null means applied to all failures
        Returns:
        a UniOnFailure configured with the given predicate on which you can specify the on failure action
      • onFailure

        public UniOnFailure<T> onFailure​(java.lang.Class<? extends java.lang.Throwable> typeOfFailure)
        Description copied from interface: Uni
        Configures a type of failure filtering the failures on which the behavior (specified with the returned UniOnFailure) 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.

        Specified by:
        onFailure in interface Uni<T>
        Parameters:
        typeOfFailure - the class of exception, must not be null
        Returns:
        a UniOnFailure configured with the given predicate on which you can specify the on failure action
      • onSubscribe

        public UniOnSubscribe<T> onSubscribe()
        Description copied from interface: Uni
        Configures the action to execute when the observed Uni 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().call(sub -> Uni.createFrom(1).onItem().delayIt().by(Duration.ofSecond(1)));
         
         
        Specified by:
        onSubscribe in interface Uni<T>
        Returns:
        the object to configure the action to execution on subscription.
      • onItemOrFailure

        public UniOnItemOrFailure<T> onItemOrFailure()
        Description copied from interface: Uni
        Configures the action to execute when the observed Uni emits either an item (potentially null)) or a failure. Unlike Uni.onItem() and Uni.onFailure() the action would handle both cases in on "go".
        Specified by:
        onItemOrFailure in interface Uni<T>
        Returns:
        the object to configure the action to execute when an item is emitted or when a failure is propagated.
      • or

        public UniOr<T> or()
        Description copied from interface: Uni
        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). 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.

        Specified by:
        or in interface Uni<T>
        Returns:
        the object to enlist the participants
        See Also:
        Uni.any for a static version of this operator, like Uni first = Uni.any().of(uni1, uni2);
      • await

        public UniAwait<T> await()
        Description copied from interface: Uni
        Awaits (blocking the caller thread) until the item or a failure is emitted by the observed Uni. 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
         
         
        Specified by:
        await in interface Uni<T>
        Returns:
        the object to configure the retrieval.
      • emitOn

        public Uni<T> emitOn​(java.util.concurrent.Executor executor)
        Description copied from interface: Uni
        Produces a new Uni 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.

        Specified by:
        emitOn in interface Uni<T>
        Parameters:
        executor - the executor to use, must not be null
        Returns:
        a new Uni
      • runSubscriptionOn

        public Uni<T> runSubscriptionOn​(java.util.concurrent.Executor executor)
        Description copied from interface: Uni
        When a subscriber subscribes to this Uni, 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)
        Specified by:
        runSubscriptionOn in interface Uni<T>
        Parameters:
        executor - the executor to use, must not be null
        Returns:
        a new Uni
      • memoize

        public UniMemoize<T> memoize()
        Description copied from interface: Uni
        Configure memoization of the Uni item or failure.
        Specified by:
        memoize in interface Uni<T>
        Returns:
        the object to configure memoization
      • cache

        public Uni<T> cache()
        Description copied from interface: Uni
        Caches the events (item or failure) of this Uni and replays it for all further UniSubscriber.
        Specified by:
        cache in interface Uni<T>
        Returns:
        the new Uni. Unlike regular Uni, re-subscribing to this Uni does not re-compute the outcome but replayed the cached events.
      • convert

        public UniConvert<T> convert()
        Description copied from interface: Uni
        Converts an Uni 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
         
         
        Specified by:
        convert in interface Uni<T>
        Returns:
        the object to convert an Uni instance
        See Also:
        UniConvert
      • toMulti

        public Multi<T> toMulti()
        Description copied from interface: Uni
        Creates an instance of Multi 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:

        • if this Uni emits a non-null item - this item is propagated to the Multi and followed with the completion event
        • if this Uni emits a null item - the Multi fires the completion event
        • if this Uni 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.

        Specified by:
        toMulti in interface Uni<T>
        Returns:
        the produced Multi, never null
      • on

        public UniOnEvent<T> on()
        Description copied from interface: Uni
        Allows adding behavior when various type of events are emitted by the current Uni (item, failure) or by the subscriber (cancellation, subscription)
        Specified by:
        on in interface Uni<T>
        Returns:
        the object to configure the action to execute when events happen
      • repeat

        public UniRepeat<T> repeat()
        Description copied from interface: Uni
        Allows configuring repeating behavior. Repeating allow transforming a Uni into a Multi either a specific amount of times or indefinitely. Each time, a new subscription is attempted on the Uni. Cancelling the subscription stops the repeating behavior.
        Specified by:
        repeat in interface Uni<T>
        Returns:
        the object to configure the repeating behavior.
      • onTermination

        public UniOnTerminate<T> onTermination()
        Description copied from interface: Uni
        Configures actions to be performed on termination, that is, on item, on failure, or when the subscriber cancels the subscription.
        Specified by:
        onTermination in interface Uni<T>
        Returns:
        the object to configure the termination actions.
      • onCancellation

        public UniOnCancel<T> onCancellation()
        Description copied from interface: Uni
        Configures actions to be performed when the subscriber cancels the subscription.
        Specified by:
        onCancellation in interface Uni<T>
        Returns:
        the object to configure the cancellation actions.