Class MultiRetry<T>

java.lang.Object
io.smallrye.mutiny.groups.MultiRetry<T>

public class MultiRetry<T> extends Object
  • Constructor Details

  • Method Details

    • withExecutor

      @CheckReturnValue public MultiRetry<T> withExecutor(ScheduledExecutorService executor)
      Define a scheduled executor other than Infrastructure.getDefaultWorkerPool() for the time-aware retry policies (e.g., {withBackOff(Duration)}.
      Parameters:
      executor - the scheduled executor, must not be null
      Returns:
      this instance
    • indefinitely

      @CheckReturnValue public Multi<T> indefinitely()
      Produces a Multi resubscribing to the current Multi until it gets a items followed by a completion events.

      On every failure, it re-subscribes, indefinitely.

      Returns:
      the Multi
    • atMost

      @CheckReturnValue public Multi<T> atMost(long numberOfAttempts)
      Produces a Multi resubscribing to the current Multi at most numberOfAttempts time, until it gets items followed by the completion event. 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 Multi retrying at most numberOfAttempts times to subscribe to the current Multi until it gets an item. When the number of attempt is reached, the last failure is propagated.
    • expireAt

      @CheckReturnValue public Multi<T> expireAt(long expireAt)
      Produces a Multi resubscribing to the current Multi until expireAt time or until it gets items followed by the completion event. 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 Multi retrying to subscribe to the current Multi until it gets an item or until expiration expireAt. When the expiration is reached, the last failure is propagated.
      Throws:
      IllegalArgumentException - if back off not configured,
    • expireIn

      @CheckReturnValue public Multi<T> expireIn(long expireIn)
      Produces a Multi resubscribing to the current Multi until expireIn time or until it gets items followed by the completion event. 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 Multi retrying to subscribe to the current Multi until it gets an item or until expiration expireIn. When the expiration is reached, the last failure is propagated.
      Throws:
      IllegalArgumentException - if back off not configured,
    • until

      @CheckReturnValue public Multi<T> until(Predicate<? super Throwable> predicate)
      Produces a Multi resubscribing to the current Multi until the given predicate returns false. The predicate is called with the failure emitted by the current Multi.
      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 Multi instance
    • when

      @CheckReturnValue public Multi<T> when(Function<Multi<Throwable>,? extends Flow.Publisher<?>> whenStreamFactory)
      Produces a Multi resubscribing to the current Multi when the Flow.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 downstream gets a failure. It the streams completes, the downstream completes.
      Parameters:
      whenStreamFactory - the function used to produce the stream triggering the re-subscription, must not be null, must not produce null
      Returns:
      a new Multi retrying re-subscribing to the current Multi when the companion stream, produced by whenStreamFactory emits an item.
    • withBackOff

      @CheckReturnValue public MultiRetry<T> withBackOff(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 MultiRetry<T> withBackOff(Duration initialBackOff, 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 MultiRetry<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.