Class MultiResourceUni<R,​I>

  • Type Parameters:
    R - the type of resource
    I - the type of item emitted by the resulting Multi

    public class MultiResourceUni<R,​I>
    extends java.lang.Object
    Allows configuring a finalizer to close the resource attached to the stream. Unlike MultiResource, this version receives a () -> Uni<R>, meaning that the resource instance can be resolved asynchronously.
    See Also:
    MultiCreate.resourceFromUni(Supplier, Function)
    • Constructor Summary

      Constructors 
      Constructor Description
      MultiResourceUni​(java.util.function.Supplier<Uni<R>> resourceSupplier, java.util.function.Function<? super R,​? extends org.reactivestreams.Publisher<I>> streamSupplier)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Multi<I> withFinalizer​(java.util.function.Consumer<? super R> finalizer)
      Configures a synchronous finalizer.
      Multi<I> withFinalizer​(java.util.function.Function<? super R,​Uni<java.lang.Void>> finalizer)
      Configures an asynchronous finalizer.
      Multi<I> withFinalizer​(java.util.function.Function<? super R,​Uni<java.lang.Void>> onCompletion, java.util.function.BiFunction<? super R,​? super java.lang.Throwable,​Uni<java.lang.Void>> onFailure, java.util.function.Function<? super R,​Uni<java.lang.Void>> onCancellation)
      Configures asynchronous finalizers distinct for each event.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • MultiResourceUni

        public MultiResourceUni​(java.util.function.Supplier<Uni<R>> resourceSupplier,
                                java.util.function.Function<? super R,​? extends org.reactivestreams.Publisher<I>> streamSupplier)
    • Method Detail

      • withFinalizer

        @CheckReturnValue
        public Multi<I> withFinalizer​(java.util.function.Consumer<? super R> finalizer)
        Configures a synchronous finalizer. The given function is called when the stream completes, fails or when the subscriber cancels. If the finalizer throws an exception, this exception is propagated to the subscriber, unless it has already cancelled.
        Parameters:
        finalizer - the finalizer, must not be null
        Returns:
        the multi
      • withFinalizer

        @CheckReturnValue
        public Multi<I> withFinalizer​(java.util.function.Function<? super R,​Uni<java.lang.Void>> finalizer)
        Configures an asynchronous finalizer. The given function is called when the stream completes, fails or when the subscriber cancels. The returned Uni is flattened with the stream meaning that the subscriber gets the events fired by the Uni. If the Uni completes successfully, the subscriber gets the completion event. If the Uni fails, the subscriber gets the failure even if the resource stream completed successfully. If the Uni fails after a resource stream failure, the subscriber receives a CompositeException. If the subscribers cancels, the Uni outcome is ignored.

        If the finalizer throws an exception, this exception is propagated to the subscriber, unless it has already cancelled. If the finalizer returns null, a NullPointerException is propagated to the subscriber, unless it has already cancelled.

        Parameters:
        finalizer - the finalizer, must not be null
        Returns:
        the multi
      • withFinalizer

        @CheckReturnValue
        public Multi<I> withFinalizer​(java.util.function.Function<? super R,​Uni<java.lang.Void>> onCompletion,
                                      java.util.function.BiFunction<? super R,​? super java.lang.Throwable,​Uni<java.lang.Void>> onFailure,
                                      java.util.function.Function<? super R,​Uni<java.lang.Void>> onCancellation)
        Configures asynchronous finalizers distinct for each event. The given functions are called when the stream completes, fails or when the subscriber cancels.

        The returned Uni is flattened with the stream meaning that the subscriber gets the events fired by the Uni. If the Uni completes successfully, the subscriber gets the completion event. If the Uni fails, the subscriber gets the failure even if the resource stream completed successfully. If the Uni fails after a resource stream failure, the subscriber receives a CompositeException. If the subscribers cancels, the Uni outcome is ignored.

        If a finalizer throws an exception, this exception is propagated to the subscriber, unless it has already cancelled. If a finalizer returns null, a NullPointerException is propagated to the subscriber, unless it has already cancelled.

        Parameters:
        onCompletion - the completion finalizer called when the resource stream completes successfully. Must not be null
        onFailure - the failure finalizer called when the resource stream propagated a failure. The finalizer is called with the resource and the failure. Must not be null
        onCancellation - the cancellation finalizer called when the subscribers cancels the subscription. Must not be null.
        Returns:
        the multi