Interface Retry

  • All Known Implementing Classes:
    RetryImpl

    public interface Retry
    A Retry instance is thread-safe can be used to decorate multiple requests. A Retry.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Interface Description
      static interface  Retry.AsyncContext<T>  
      static class  Retry.AsyncRetryBlock<T>  
      static interface  Retry.Context<T>
      the retry context which will be used during the retry iteration to decide what can be done on error , result, on runtime error
      static interface  Retry.EventPublisher
      An EventPublisher which subscribes to the reactive stream of RetryEvents and can be used to register event consumers.
      static interface  Retry.Metrics  
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      <T> Retry.AsyncContext<T> asyncContext()
      Creates a async retry Context.
      <T> Retry.Context<T> context()
      Creates a retry Context.
      static <T> java.util.concurrent.Callable<T> decorateCallable​(Retry retry, java.util.concurrent.Callable<T> supplier)
      Creates a retryable callable.
      static <T,​R>
      io.vavr.CheckedFunction1<T,​R>
      decorateCheckedFunction​(Retry retry, io.vavr.CheckedFunction1<T,​R> function)
      Creates a retryable function.
      static io.vavr.CheckedRunnable decorateCheckedRunnable​(Retry retry, io.vavr.CheckedRunnable runnable)
      Creates a retryable runnable.
      static <T> io.vavr.CheckedFunction0<T> decorateCheckedSupplier​(Retry retry, io.vavr.CheckedFunction0<T> supplier)
      Creates a retryable supplier.
      static <T> java.util.function.Supplier<java.util.concurrent.CompletionStage<T>> decorateCompletionStage​(Retry retry, java.util.concurrent.ScheduledExecutorService scheduler, java.util.function.Supplier<java.util.concurrent.CompletionStage<T>> supplier)
      Decorates CompletionStageSupplier with Retry
      static <E extends java.lang.Exception,​T>
      java.util.function.Supplier<io.vavr.control.Either<E,​T>>
      decorateEitherSupplier​(Retry retry, java.util.function.Supplier<io.vavr.control.Either<E,​T>> supplier)
      Creates a retryable supplier.
      static <T,​R>
      java.util.function.Function<T,​R>
      decorateFunction​(Retry retry, java.util.function.Function<T,​R> function)
      Creates a retryable function.
      static java.lang.Runnable decorateRunnable​(Retry retry, java.lang.Runnable runnable)
      Creates a retryable runnable.
      static <T> java.util.function.Supplier<T> decorateSupplier​(Retry retry, java.util.function.Supplier<T> supplier)
      Creates a retryable supplier.
      static <T> java.util.function.Supplier<io.vavr.control.Try<T>> decorateTrySupplier​(Retry retry, java.util.function.Supplier<io.vavr.control.Try<T>> supplier)
      Creates a retryable supplier.
      default <T> T executeCallable​(java.util.concurrent.Callable<T> callable)
      Decorates and executes the decorated Callable.
      default <T> T executeCheckedSupplier​(io.vavr.CheckedFunction0<T> checkedSupplier)
      Decorates and executes the decorated Supplier.
      default <T> java.util.concurrent.CompletionStage<T> executeCompletionStage​(java.util.concurrent.ScheduledExecutorService scheduler, java.util.function.Supplier<java.util.concurrent.CompletionStage<T>> supplier)
      Decorates and executes the decorated CompletionStage.
      default <E extends java.lang.Exception,​T>
      io.vavr.control.Either<E,​T>
      executeEitherSupplier​(java.util.function.Supplier<io.vavr.control.Either<E,​T>> supplier)
      Decorates and executes the decorated Supplier.
      default void executeRunnable​(java.lang.Runnable runnable)
      Decorates and executes the decorated Runnable.
      default <T> T executeSupplier​(java.util.function.Supplier<T> supplier)
      Decorates and executes the decorated Supplier.
      default <T> io.vavr.control.Try<T> executeTrySupplier​(java.util.function.Supplier<io.vavr.control.Try<T>> supplier)
      Decorates and executes the decorated Supplier.
      Retry.EventPublisher getEventPublisher()
      Returns an EventPublisher can be used to register event consumers.
      Retry.Metrics getMetrics()
      Get the Metrics of this Retry instance.
      java.lang.String getName()
      Returns the ID of this Retry.
      RetryConfig getRetryConfig()
      Returns the RetryConfig of this Retry.
      io.vavr.collection.Map<java.lang.String,​java.lang.String> getTags()
      Returns an unmodifiable map with tags assigned to this Retry.
      static Retry of​(java.lang.String name, RetryConfig retryConfig)
      Creates a Retry with a custom Retry configuration.
      static Retry of​(java.lang.String name, RetryConfig retryConfig, io.vavr.collection.Map<java.lang.String,​java.lang.String> tags)
      Creates a Retry with a custom Retry configuration.
      static Retry of​(java.lang.String name, java.util.function.Supplier<RetryConfig> retryConfigSupplier)
      Creates a Retry with a custom Retry configuration.
      static Retry of​(java.lang.String name, java.util.function.Supplier<RetryConfig> retryConfigSupplier, io.vavr.collection.Map<java.lang.String,​java.lang.String> tags)
      Creates a Retry with a custom Retry configuration.
      static Retry ofDefaults​(java.lang.String name)
      Creates a Retry with default configuration.
    • Method Detail

      • of

        static Retry of​(java.lang.String name,
                        RetryConfig retryConfig)
        Creates a Retry with a custom Retry configuration.
        Parameters:
        name - the ID of the Retry
        retryConfig - a custom Retry configuration
        Returns:
        a Retry with a custom Retry configuration.
      • of

        static Retry of​(java.lang.String name,
                        RetryConfig retryConfig,
                        io.vavr.collection.Map<java.lang.String,​java.lang.String> tags)
        Creates a Retry with a custom Retry configuration.
        Parameters:
        name - the ID of the Retry
        retryConfig - a custom Retry configuration
        tags - tags to assign to the Retry
        Returns:
        a Retry with a custom Retry configuration.
      • of

        static Retry of​(java.lang.String name,
                        java.util.function.Supplier<RetryConfig> retryConfigSupplier)
        Creates a Retry with a custom Retry configuration.
        Parameters:
        name - the ID of the Retry
        retryConfigSupplier - a supplier of a custom Retry configuration
        Returns:
        a Retry with a custom Retry configuration.
      • of

        static Retry of​(java.lang.String name,
                        java.util.function.Supplier<RetryConfig> retryConfigSupplier,
                        io.vavr.collection.Map<java.lang.String,​java.lang.String> tags)
        Creates a Retry with a custom Retry configuration.
        Parameters:
        name - the ID of the Retry
        retryConfigSupplier - a supplier of a custom Retry configuration
        tags - tags to assign to the Retry
        Returns:
        a Retry with a custom Retry configuration.
      • ofDefaults

        static Retry ofDefaults​(java.lang.String name)
        Creates a Retry with default configuration.
        Parameters:
        name - the ID of the Retry
        Returns:
        a Retry with default configuration
      • decorateCompletionStage

        static <T> java.util.function.Supplier<java.util.concurrent.CompletionStage<T>> decorateCompletionStage​(Retry retry,
                                                                                                                java.util.concurrent.ScheduledExecutorService scheduler,
                                                                                                                java.util.function.Supplier<java.util.concurrent.CompletionStage<T>> supplier)
        Decorates CompletionStageSupplier with Retry
        Type Parameters:
        T - type of completion stage result
        Parameters:
        retry - the retry context
        scheduler - execution service to use to schedule retries
        supplier - completion stage supplier
        Returns:
        decorated supplier
      • decorateCheckedSupplier

        static <T> io.vavr.CheckedFunction0<T> decorateCheckedSupplier​(Retry retry,
                                                                       io.vavr.CheckedFunction0<T> supplier)
        Creates a retryable supplier.
        Type Parameters:
        T - the type of results supplied by this supplier
        Parameters:
        retry - the retry context
        supplier - the original function
        Returns:
        a retryable function
      • decorateCheckedRunnable

        static io.vavr.CheckedRunnable decorateCheckedRunnable​(Retry retry,
                                                               io.vavr.CheckedRunnable runnable)
        Creates a retryable runnable.
        Parameters:
        retry - the retry context
        runnable - the original runnable
        Returns:
        a retryable runnable
      • decorateCheckedFunction

        static <T,​R> io.vavr.CheckedFunction1<T,​R> decorateCheckedFunction​(Retry retry,
                                                                                       io.vavr.CheckedFunction1<T,​R> function)
        Creates a retryable function.
        Type Parameters:
        T - the type of the input to the function
        R - the result type of the function
        Parameters:
        retry - the retry context
        function - the original function
        Returns:
        a retryable function
      • decorateSupplier

        static <T> java.util.function.Supplier<T> decorateSupplier​(Retry retry,
                                                                   java.util.function.Supplier<T> supplier)
        Creates a retryable supplier.
        Type Parameters:
        T - the type of results supplied by this supplier
        Parameters:
        retry - the retry context
        supplier - the original function
        Returns:
        a retryable function
      • decorateEitherSupplier

        static <E extends java.lang.Exception,​T> java.util.function.Supplier<io.vavr.control.Either<E,​T>> decorateEitherSupplier​(Retry retry,
                                                                                                                                             java.util.function.Supplier<io.vavr.control.Either<E,​T>> supplier)
        Creates a retryable supplier.
        Type Parameters:
        T - the type of results supplied by this supplier
        Parameters:
        retry - the retry context
        supplier - the original function
        Returns:
        a retryable function
      • decorateTrySupplier

        static <T> java.util.function.Supplier<io.vavr.control.Try<T>> decorateTrySupplier​(Retry retry,
                                                                                           java.util.function.Supplier<io.vavr.control.Try<T>> supplier)
        Creates a retryable supplier.
        Type Parameters:
        T - the type of results supplied by this supplier
        Parameters:
        retry - the retry context
        supplier - the original function
        Returns:
        a retryable function
      • decorateCallable

        static <T> java.util.concurrent.Callable<T> decorateCallable​(Retry retry,
                                                                     java.util.concurrent.Callable<T> supplier)
        Creates a retryable callable.
        Type Parameters:
        T - the type of results supplied by this supplier
        Parameters:
        retry - the retry context
        supplier - the original function
        Returns:
        a retryable function
      • decorateRunnable

        static java.lang.Runnable decorateRunnable​(Retry retry,
                                                   java.lang.Runnable runnable)
        Creates a retryable runnable.
        Parameters:
        retry - the retry context
        runnable - the original runnable
        Returns:
        a retryable runnable
      • decorateFunction

        static <T,​R> java.util.function.Function<T,​R> decorateFunction​(Retry retry,
                                                                                   java.util.function.Function<T,​R> function)
        Creates a retryable function.
        Type Parameters:
        T - the type of the input to the function
        R - the result type of the function
        Parameters:
        retry - the retry context
        function - the original function
        Returns:
        a retryable function
      • getName

        java.lang.String getName()
        Returns the ID of this Retry.
        Returns:
        the ID of this Retry
      • context

        <T> Retry.Context<T> context()
        Creates a retry Context.
        Returns:
        the retry Context
      • asyncContext

        <T> Retry.AsyncContext<T> asyncContext()
        Creates a async retry Context.
        Returns:
        the async retry Context
      • getRetryConfig

        RetryConfig getRetryConfig()
        Returns the RetryConfig of this Retry.
        Returns:
        the RetryConfig of this Retry
      • getTags

        io.vavr.collection.Map<java.lang.String,​java.lang.String> getTags()
        Returns an unmodifiable map with tags assigned to this Retry.
        Returns:
        the tags assigned to this Retry in an unmodifiable map
      • getEventPublisher

        Retry.EventPublisher getEventPublisher()
        Returns an EventPublisher can be used to register event consumers.
        Returns:
        an EventPublisher
      • executeCheckedSupplier

        default <T> T executeCheckedSupplier​(io.vavr.CheckedFunction0<T> checkedSupplier)
                                      throws java.lang.Throwable
        Decorates and executes the decorated Supplier.
        Type Parameters:
        T - the type of results supplied by this supplier
        Parameters:
        checkedSupplier - the original Supplier
        Returns:
        the result of the decorated Supplier.
        Throws:
        java.lang.Throwable - if something goes wrong applying this function to the given arguments
      • executeSupplier

        default <T> T executeSupplier​(java.util.function.Supplier<T> supplier)
        Decorates and executes the decorated Supplier.
        Type Parameters:
        T - the type of results supplied by this supplier
        Parameters:
        supplier - the original Supplier
        Returns:
        the result of the decorated Supplier.
      • executeEitherSupplier

        default <E extends java.lang.Exception,​T> io.vavr.control.Either<E,​T> executeEitherSupplier​(java.util.function.Supplier<io.vavr.control.Either<E,​T>> supplier)
        Decorates and executes the decorated Supplier.
        Type Parameters:
        T - the type of results supplied by this supplier
        Parameters:
        supplier - the original Supplier
        Returns:
        the result of the decorated Supplier.
      • executeTrySupplier

        default <T> io.vavr.control.Try<T> executeTrySupplier​(java.util.function.Supplier<io.vavr.control.Try<T>> supplier)
        Decorates and executes the decorated Supplier.
        Type Parameters:
        T - the type of results supplied by this supplier
        Parameters:
        supplier - the original Supplier
        Returns:
        the result of the decorated Supplier.
      • executeCallable

        default <T> T executeCallable​(java.util.concurrent.Callable<T> callable)
                               throws java.lang.Exception
        Decorates and executes the decorated Callable.
        Type Parameters:
        T - the result type of callable
        Parameters:
        callable - the original Callable
        Returns:
        the result of the decorated Callable.
        Throws:
        java.lang.Exception - if unable to compute a result
      • executeRunnable

        default void executeRunnable​(java.lang.Runnable runnable)
        Decorates and executes the decorated Runnable.
        Parameters:
        runnable - the original Runnable
      • executeCompletionStage

        default <T> java.util.concurrent.CompletionStage<T> executeCompletionStage​(java.util.concurrent.ScheduledExecutorService scheduler,
                                                                                   java.util.function.Supplier<java.util.concurrent.CompletionStage<T>> supplier)
        Decorates and executes the decorated CompletionStage.
        Type Parameters:
        T - the type of results supplied by this supplier
        Parameters:
        scheduler - execution service to use to schedule retries
        supplier - the original CompletionStage
        Returns:
        the decorated CompletionStage.
      • getMetrics

        Retry.Metrics getMetrics()
        Get the Metrics of this Retry instance.
        Returns:
        the Metrics of this Retry instance