Class MultiOnItem<T>


  • public class MultiOnItem<T>
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Constructor Description
      MultiOnItem​(Multi<T> upstream)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Multi<T> call​(java.util.function.Function<? super T,​Uni<?>> action)
      Produces a new Multi invoking the given @{code action} when an item event is received.
      Multi<T> call​(java.util.function.Supplier<Uni<?>> action)
      Produces a new Multi invoking the given @{code action} when an item event is received, but ignoring it in the callback.
      <O> Multi<O> castTo​(java.lang.Class<O> target)
      Produces an Multi emitting the item events based on the upstream events but casted to the target class.
      <O> Multi<O> disjoint()
      Takes the items from the upstream Multi that are either Publisher<O>, O[], Iterable<O> or Multi<O> and disjoint the items to obtain a Multi<O>.
      Multi<T> failWith​(java.util.function.Function<? super T,​? extends java.lang.Throwable> mapper)
      Produces a new Multi invoking the given function when the current Multi fires an item (only once).
      Multi<T> failWith​(java.util.function.Supplier<? extends java.lang.Throwable> supplier)
      Produces a new Multi invoking the given supplier when the current Uni fires an item.
      Multi<java.lang.Void> ignore()
      Ignores the passed items.
      Uni<java.lang.Void> ignoreAsUni()
      Ignores the passed items.
      Multi<T> invoke​(java.lang.Runnable callback)
      Produces a new Multi invoking the given callback when an item event is fired by the upstream.
      Multi<T> invoke​(java.util.function.Consumer<? super T> callback)
      Produces a new Multi invoking the given callback when an item event is fired by the upstream.
      Multi<T> scan​(java.util.function.BinaryOperator<T> accumulator)
      Produces a Multi that fires results coming from the reduction of the item emitted by this current Multi by the passed accumulator reduction function.
      <S> Multi<S> scan​(java.util.function.Supplier<S> initialStateProducer, java.util.function.BiFunction<S,​? super T,​S> accumulator)
      Produces a Multi that fires items coming from the reduction of the item emitted by this current Multi by the passed accumulator reduction function.
      <R> Multi<R> transform​(java.util.function.Function<? super T,​? extends R> mapper)
      Produces a new Multi invoking the given function for each item emitted by the upstream Multi.
      <O> Multi<O> transformToIterable​(java.util.function.Function<? super T,​? extends java.lang.Iterable<O>> mapper)
      On each item received from the upstream, call the given mapper.
      <O> MultiFlatten<T,​O> transformToMulti​(java.util.function.Function<? super T,​? extends org.reactivestreams.Publisher<? extends O>> mapper)
      On each item received from upstream, invoke the given mapper.
      <O> Multi<O> transformToMultiAndConcatenate​(java.util.function.Function<? super T,​? extends org.reactivestreams.Publisher<? extends O>> mapper)
      For each items emitted by the upstream, the given mapper is invoked.
      <O> Multi<O> transformToMultiAndMerge​(java.util.function.Function<? super T,​? extends org.reactivestreams.Publisher<? extends O>> mapper)
      For each items emitted by the upstream, the given mapper is invoked.
      <O> MultiFlatten<T,​O> transformToUni​(java.util.function.Function<? super T,​Uni<? extends O>> mapper)
      On each item received from upstream, invoke the given mapper.
      <O> Multi<O> transformToUniAndConcatenate​(java.util.function.Function<? super T,​Uni<? extends O>> mapper)
      For each items emitted by the upstream, the given mapper is invoked.
      <O> Multi<O> transformToUniAndMerge​(java.util.function.Function<? super T,​Uni<? extends O>> mapper)
      For each items emitted by the upstream, the given mapper is invoked.
      • Methods inherited from class java.lang.Object

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

      • MultiOnItem

        public MultiOnItem​(Multi<T> upstream)
    • Method Detail

      • transform

        @CheckReturnValue
        public <R> Multi<R> transform​(java.util.function.Function<? super T,​? extends R> mapper)
        Produces a new Multi invoking the given function for each item emitted by the upstream Multi.

        The function receives the received item as parameter, and can transform it. The returned object is sent downstream as item event.

        Type Parameters:
        R - the type of item produced by the mapper function
        Parameters:
        mapper - the mapper function, must not be null
        Returns:
        the new Multi
      • invoke

        @CheckReturnValue
        public Multi<T> invoke​(java.util.function.Consumer<? super T> callback)
        Produces a new Multi invoking the given callback when an item event is fired by the upstream. Note that the received item cannot be null.

        If the callback throws an exception, this exception is propagated to the downstream as failure. No more items will be consumed.

        Parameters:
        callback - the callback, must not be null
        Returns:
        the new Multi
      • invoke

        @CheckReturnValue
        public Multi<T> invoke​(java.lang.Runnable callback)
        Produces a new Multi invoking the given callback when an item event is fired by the upstream.

        If the callback throws an exception, this exception is propagated to the downstream as failure. No more items will be consumed.

        Parameters:
        callback - the callback, must not be null
        Returns:
        the new Multi
      • call

        @CheckReturnValue
        public Multi<T> call​(java.util.function.Function<? super T,​Uni<?>> action)
        Produces a new Multi invoking the given @{code action} when an item event is received. Note that the received item cannot be null.

        Unlike invoke(Consumer), the passed function returns a Uni. When the produced Uni sends its result, the result is discarded, and the original item is forwarded downstream. If the produced Uni fails, the failure is propagated downstream.

        If the asynchronous action throws an exception, this exception is propagated downstream.

        This method preserves the order of the items, meaning that the downstream received the items in the same order as the upstream has emitted them.

        Parameters:
        action - the function taking the item and returning a Uni, must not be null
        Returns:
        the new Multi
      • call

        @CheckReturnValue
        public Multi<T> call​(java.util.function.Supplier<Uni<?>> action)
        Produces a new Multi invoking the given @{code action} when an item event is received, but ignoring it in the callback.

        Unlike invoke(Consumer), the passed function returns a Uni. When the produced Uni sends its result, the result is discarded, and the original item is forwarded downstream. If the produced Uni fails, the failure is propagated downstream.

        If the asynchronous action throws an exception, this exception is propagated downstream.

        This method preserves the order of the items, meaning that the downstream received the items in the same order as the upstream has emitted them.

        Parameters:
        action - the function taking the item and returning a Uni, must not be null
        Returns:
        the new Multi
      • disjoint

        @CheckReturnValue
        public <O> Multi<O> disjoint()
        Takes the items from the upstream Multi that are either Publisher<O>, O[], Iterable<O> or Multi<O> and disjoint the items to obtain a Multi<O>.

        For example, Multi<[A, B, C], [D, E, F] is transformed into Multi<A, B, C, D, E, F>.

        If the items from upstream are not instances of Iterable, Publisher or array, an IllegalArgumentException is propagated downstream.

        Type Parameters:
        O - the type items contained in the upstream's items.
        Returns:
        the resulting multi
      • transformToMulti

        @CheckReturnValue
        public <O> MultiFlatten<T,​O> transformToMulti​(java.util.function.Function<? super T,​? extends org.reactivestreams.Publisher<? extends O>> mapper)
        On each item received from upstream, invoke the given mapper. This mapper return a Publisher or a Multi. The return object lets you configure the flattening process, i.e. how the items produced by the returned Publishers or Multis are propagated to the downstream.
        Type Parameters:
        O - the type of item emitted by the Multi produced by the mapper.
        Parameters:
        mapper - the mapper, must not be null, must not produce null
        Returns:
        the object to configure the flatten behavior.
      • transformToMultiAndConcatenate

        @CheckReturnValue
        public <O> Multi<O> transformToMultiAndConcatenate​(java.util.function.Function<? super T,​? extends org.reactivestreams.Publisher<? extends O>> mapper)
        For each items emitted by the upstream, the given mapper is invoked. This mapper returns a Publisher. The events emitted by the returned Publisher are propagated downstream using a concatenation, meaning that it does not interleaved the items produced by the different Publishers.

        For example, let's imagine an upstream multi {a, b, c} and a mapper emitting the 3 items with some delays between them. For example a -> {a1, a2, a3}, b -> {b1, b2, b3} and c -> {c1, c2, c3}. Using this method on the multi {a, b c} with that mapper may produce the following multi {a1, a2, a3, b1, b2, b3, c1, c2, c3}. So produced multis are concatenated.

        This operation is often called concatMap.

        If the mapper throws an exception, the failure is propagated downstream. No more items will be emitted. If one of the produced Publisher propagates a failure, the failure is propagated downstream and no more items will be emitted.

        Type Parameters:
        O - the type of item emitted by the Multi produced by the mapper.
        Parameters:
        mapper - the mapper, must not be null, must not produce null
        Returns:
        the resulting multi
      • transformToMultiAndMerge

        @CheckReturnValue
        public <O> Multi<O> transformToMultiAndMerge​(java.util.function.Function<? super T,​? extends org.reactivestreams.Publisher<? extends O>> mapper)
        For each items emitted by the upstream, the given mapper is invoked. This mapper returns a Publisher. The events emitted by the returned Publisher are propagated using a merge, meaning that it may interleave events produced by the different Publishers.

        For example, let's imagine an upstream multi {a, b, c} and a mapper emitting the 3 items with some delays between them. For example a -> {a1, a2, a3}, b -> {b1, b2, b3} and c -> {c1, c2, c3}. Using this method on the multi {a, b c} with that mapper may produce the following multi {a1, b1, a2, c1, b2, c2, a3, b3, c3}. So the items from the produced multis are interleaved and are emitted as soon as they are emitted (respecting the downstream request).

        This operation is often called flatMap.

        If the mapper throws an exception, the failure is propagated downstream. No more items will be emitted. If one of the produced Publisher propagates a failure, the failure is propagated downstream and no more items will be emitted.

        Type Parameters:
        O - the type of item emitted by the Multi produced by the mapper.
        Parameters:
        mapper - the mapper, must not be null, must not produce null
        Returns:
        the resulting multi
      • transformToIterable

        @CheckReturnValue
        public <O> Multi<O> transformToIterable​(java.util.function.Function<? super T,​? extends java.lang.Iterable<O>> mapper)
        On each item received from the upstream, call the given mapper. The mapper returns an Iterable. The items from the returned Iterable are propagated downstream (one by one). As Iterable is a synchronous construct, this method concatenates the items produced by the different returns iterables.
        Type Parameters:
        O - the type of item contained by the Iterable produced by the mapper.
        Parameters:
        mapper - the mapper, must not be null, must not produce null
        Returns:
        the object to configure the flatten behavior.
      • transformToUni

        @CheckReturnValue
        public <O> MultiFlatten<T,​O> transformToUni​(java.util.function.Function<? super T,​Uni<? extends O>> mapper)
        On each item received from upstream, invoke the given mapper. This mapper return Uni<T>. The return object lets you configure the flattening process, i.e. how the items produced by the returned Unis are propagated to the downstream.
        Type Parameters:
        O - the type of item emitted by the Multi produced by the mapper.
        Parameters:
        mapper - the mapper, must not be null, must not produce null
        Returns:
        the object to configure the flatten behavior.
      • transformToUniAndConcatenate

        @CheckReturnValue
        public <O> Multi<O> transformToUniAndConcatenate​(java.util.function.Function<? super T,​Uni<? extends O>> mapper)
        For each items emitted by the upstream, the given mapper is invoked. This mapper returns a Uni. The events emitted by the returned Uni are emitted downstream. Items emitted by the returned Unis are emitted downstream using a concatenation, meaning that the returned Multi contains the items in the same order as the upstream.

        For example, let's imagine an upstream multi {a, b, c} and a mapper emitting 1 items. This emission may be delayed for various reasons. For example a -> a1 without delay, b -> b1 after some delay and c -> c1 without delay. Using this method on the multi {a, b c} with that mapper would produce the following multi {a1, b1, c1}. Indeed, even if c1 could be emitted before b1, this method preserves the order. So the items from the produced unis are concatenated.

        This operation is often called concatMapSingle.

        If the mapper throws an exception, the failure is propagated downstream. No more items will be emitted. If one of the produced Uni propagates a failure, the failure is propagated downstream and no more items will be emitted.

        Type Parameters:
        O - the type of item emitted by the Multi produced by the mapper.
        Parameters:
        mapper - the mapper, must not be null, must not produce null
        Returns:
        the resulting multi
      • transformToUniAndMerge

        @CheckReturnValue
        public <O> Multi<O> transformToUniAndMerge​(java.util.function.Function<? super T,​Uni<? extends O>> mapper)
        For each items emitted by the upstream, the given mapper is invoked. This mapper returns a Uni. The events emitted by the returned Uni are emitted downstream. Items emitted by the returned Unis are emitted downstream using a merge, meaning that it may interleave events produced by the different Uni.

        For example, let's imagine an upstream multi {a, b, c} and a mapper emitting 1 items. This emission may be delayed for various reasons. For example a -> a1 without delay, b -> b1 after some delay and c -> c1 without delay. Using this method on the multi {a, b c} with that mapper would produce the following multi {a1, c1, b1}. Indeed, the b1 item is emitted after c1. So the items from the produced unis are interleaved and are emitted as soon as they are emitted (respecting the downstream request).

        This operation is often called flatMapSingle.

        If the mapper throws an exception, the failure is propagated downstream. No more items will be emitted. If one of the produced Uni propagates a failure, the failure is propagated downstream and no more items will be emitted.

        Type Parameters:
        O - the type of item emitted by the Multi produced by the mapper.
        Parameters:
        mapper - the mapper, must not be null, must not produce null
        Returns:
        the resulting multi
      • ignore

        @CheckReturnValue
        public Multi<java.lang.Void> ignore()
        Ignores the passed items. The resulting Multi will only be notified when the stream completes or fails.
        Returns:
        the new multi
      • ignoreAsUni

        @CheckReturnValue
        public Uni<java.lang.Void> ignoreAsUni()
        Ignores the passed items. The resulting Uni will only be completed with null when the stream completes or with a failure if the upstream emits a failure..
        Returns:
        the new Uni
      • castTo

        @CheckReturnValue
        public <O> Multi<O> castTo​(java.lang.Class<O> target)
        Produces an Multi emitting the item events based on the upstream events but casted to the target class.
        Type Parameters:
        O - the type of item emitted by the produced uni
        Parameters:
        target - the target class
        Returns:
        the new Multi
      • scan

        @CheckReturnValue
        public <S> Multi<S> scan​(java.util.function.Supplier<S> initialStateProducer,
                                 java.util.function.BiFunction<S,​? super T,​S> accumulator)
        Produces a Multi that fires items coming from the reduction of the item emitted by this current Multi by the passed accumulator reduction function. The produced multi emits the intermediate results.

        Unlike scan(BinaryOperator), this operator uses the value produced by the initialStateProducer as first value.

        Type Parameters:
        S - the type of item emitted by the produced Multi. It's the type returned by the accumulator operation.
        Parameters:
        initialStateProducer - the producer called to provides the initial value passed to the accumulator operation.
        accumulator - the reduction BiFunction, the resulting Multi emits the results of this method. The method is called for every item emitted by this Multi.
        Returns:
        the produced Multi
      • scan

        @CheckReturnValue
        public Multi<T> scan​(java.util.function.BinaryOperator<T> accumulator)
        Produces a Multi that fires results coming from the reduction of the item emitted by this current Multi by the passed accumulator reduction function. The produced multi emits the intermediate results.

        Unlike scan(Supplier, BiFunction), this operator doesn't take an initial value but takes the first item emitted by this Multi as initial value.

        Parameters:
        accumulator - the reduction BiFunction, the resulting Multi emits the results of this method. The method is called for every item emitted by this Multi.
        Returns:
        the produced Multi
      • failWith

        @CheckReturnValue
        public Multi<T> failWith​(java.util.function.Function<? super T,​? extends java.lang.Throwable> mapper)
        Produces a new Multi invoking the given function when the current Multi fires an item (only once). The function transforms the received item into a failure that will be fired by the produced Multi. For asynchronous composition, see transformToUni(Function)}.

        The upstream subscription is cancelled after the emission of the first item, as a failure is propagated downstream.

        Parameters:
        mapper - the mapper function, must not be null, must not return null
        Returns:
        the new Multi
      • failWith

        @CheckReturnValue
        public Multi<T> failWith​(java.util.function.Supplier<? extends java.lang.Throwable> supplier)
        Produces a new Multi invoking the given supplier when the current Uni fires an item. The supplier produce the received item into a failure that will be fired by the produced Multi.

        The upstream subscription is cancelled after the emission of the first item, as a failure is propagated downstream.

        Parameters:
        supplier - the supplier to produce the failure, must not be null, must not produce null
        Returns:
        the new Multi