Class UniRetry<T>


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

      Constructors 
      Constructor Description
      UniRetry​(Uni<T> upstream, java.util.function.Predicate<? super java.lang.Throwable> onFailurePredicate)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Uni<T> atMost​(long numberOfAttempts)
      Produces a Uni resubscribing to the current Uni at most numberOfAttempts time, until it gets an item (potentially null).
      Uni<T> expireAt​(long expireAt)
      Produces a Uni resubscribing to the current Uni until expireAt time or until it gets an item (potentially null).
      Uni<T> expireIn​(long expireIn)
      Produces a Uni resubscribing to the current Uni until expireIn time or until it gets an item (potentially null).
      Uni<T> indefinitely()
      Produces a Uni resubscribing to the current Uni until it gets an item (potentially null) On every failure, it re-subscribes, indefinitely.
      Uni<T> until​(java.util.function.Predicate<? super java.lang.Throwable> predicate)
      Produces a Uni resubscribing to the current Uni until the given predicate returns false.
      Uni<T> when​(java.util.function.Function<Multi<java.lang.Throwable>,​? extends org.reactivestreams.Publisher<?>> whenStreamFactory)
      Produces a Uni resubscribing to the current Uni when the Publisher produced by the given method emits an item.
      UniRetry<T> withBackOff​(java.time.Duration initialBackOff)
      Configures a back-off delay between to attempt to re-subscribe.
      UniRetry<T> withBackOff​(java.time.Duration initialBackOff, java.time.Duration maxBackOff)
      Configures a back-off delay between to attempt to re-subscribe.
      UniRetry<T> withJitter​(double jitter)
      Configures the random factor when using back-off.
      • Methods inherited from class java.lang.Object

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

      • UniRetry

        public UniRetry​(Uni<T> upstream,
                        java.util.function.Predicate<? super java.lang.Throwable> onFailurePredicate)
    • Method Detail

      • indefinitely

        @CheckReturnValue
        public Uni<T> indefinitely()
        Produces a Uni resubscribing to the current Uni until it gets an item (potentially null) On every failure, it re-subscribes, indefinitely.
        Returns:
        the Uni
      • atMost

        @CheckReturnValue
        public Uni<T> atMost​(long numberOfAttempts)
        Produces a Uni resubscribing to the current Uni at most numberOfAttempts time, until it gets an item (potentially null). On every failure, it re-subscribes.

        If the number of attempt is reached, the last failure is propagated.

        Parameters:
        numberOfAttempts - the number of attempt, must be greater than zero
        Returns:
        a new Uni retrying at most numberOfAttempts times to subscribe to the current Uni until it gets an item. When the number of attempt is reached, the last failure is propagated. If the back-off has been configured, a delay is introduced between the attempts.
      • expireAt

        @CheckReturnValue
        public Uni<T> expireAt​(long expireAt)
        Produces a Uni resubscribing to the current Uni until expireAt time or until it gets an item (potentially null). On every failure, it re-subscribes.

        If expiration time is passed, the last failure is propagated. Backoff must be configured.

        Parameters:
        expireAt - absolute time in millis that specifies when to give up
        Returns:
        a new Uni retrying to subscribe to the current Uni until it gets an item or until expiration expireAt. When the expiration is reached, the last failure is propagated.
        Throws:
        java.lang.IllegalArgumentException - if back off not configured,
      • expireIn

        @CheckReturnValue
        public Uni<T> expireIn​(long expireIn)
        Produces a Uni resubscribing to the current Uni until expireIn time or until it gets an item (potentially null). On every failure, it re-subscribes.

        If expiration time is passed, the last failure is propagated. Backoff must be configured.

        Parameters:
        expireIn - relative time in millis that specifies when to give up
        Returns:
        a new Uni retrying to subscribe to the current Uni until it gets an item or until expiration expireIn. When the expiration is reached, the last failure is propagated.
        Throws:
        java.lang.IllegalArgumentException - if back off not configured,
      • until

        @CheckReturnValue
        public Uni<T> until​(java.util.function.Predicate<? super java.lang.Throwable> predicate)
        Produces a Uni resubscribing to the current Uni until the given predicate returns false. The predicate is called with the failure emitted by the current Uni.
        Parameters:
        predicate - the predicate that determines if a re-subscription may happen in case of a specific failure, must not be null. If the predicate returns true for the given failure, a re-subscription is attempted.
        Returns:
        the new Uni instance
      • when

        @CheckReturnValue
        public Uni<T> when​(java.util.function.Function<Multi<java.lang.Throwable>,​? extends org.reactivestreams.Publisher<?>> whenStreamFactory)
        Produces a Uni resubscribing to the current Uni when the Publisher produced by the given method emits an item. As atMost(long), on every failure, it re-subscribes. However, a delay is introduced before re-subscribing. The re-subscription happens when the produced streams emits an item. If this stream fails, the produced Uni propagates a failure. It the streams completes, the produced Uni propagates null.
        Parameters:
        whenStreamFactory - the function used to produce the stream triggering the re-subscription, must not be null, must not produce null
        Returns:
        a new Uni retrying re-subscribing to the current Multi when the companion stream, produced by whenStreamFactory emits an item.
      • withBackOff

        @CheckReturnValue
        public UniRetry<T> withBackOff​(java.time.Duration initialBackOff)
        Configures a back-off delay between to attempt to re-subscribe. A random factor (jitter) is applied to increase the delay when several failures happen.
        Parameters:
        initialBackOff - the initial back-off duration, must not be null, must not be negative.
        Returns:
        this object to configure the retry policy.
      • withBackOff

        @CheckReturnValue
        public UniRetry<T> withBackOff​(java.time.Duration initialBackOff,
                                       java.time.Duration maxBackOff)
        Configures a back-off delay between to attempt to re-subscribe. A random factor (jitter) is applied to increase he delay when several failures happen. The max delays is maxBackOff.
        Parameters:
        initialBackOff - the initial back-off duration, must not be null, must not be negative.
        maxBackOff - the max back-off duration, must not be null, must not be negative.
        Returns:
        this object to configure the retry policy.
      • withJitter

        @CheckReturnValue
        public UniRetry<T> withJitter​(double jitter)
        Configures the random factor when using back-off. By default, it's set to 0.5.
        Parameters:
        jitter - the jitter. Must be in [0.0, 1.0]
        Returns:
        this object to configure the retry policy.