Interface Retrier


  • public interface Retrier
    The Retrier interface provides a way to execute tasks with the ability to retry and handle failures.
    All usages of the Retrier API should start with withRetries(int, DelayListener) method
    Users are encouraged to register their own listeners to the different events related to the retrier through RetrierEventListener. In these events exceptions such as AbortRetriesException and RecoverableException can be thrown to manipulate the current process.
    Example usage:
     {@code
     Retrier.withRetries(retriesNum, Retrier.DelayStrategy.linearBackOff(retryDelay))
                       .registerListener(new LoggingRetrierListener(logger))
                       .registerListener(
                         new AbortingListener(SSLException.class, UnknownHostException.class, SocketException.class, IOException.class, InterruptedException.class) {
    Since:
    2024.07
    • Method Detail

      • withRetries

        static Retrier withRetries​(int nRetries,
                                   jetbrains.buildServer.util.retry.DelayListener delayListener)
        Creates a Retrier instance with the specified number of retries.
        Parameters:
        nRetries - the number of retries to be performed
        delayListener - delay strategy for the retrier. See Retrier.DelayStrategy on how to instantiate them
        Returns:
        a Retrier instance
        Throws:
        IllegalArgumentException - if nRetries is a negative number
      • execute

        <T> T execute​(@NotNull
                      Callable<T> callable)
        Executes the given Callable task against this retrier context.
        Type Parameters:
        T - the type of the result returned by the task
        Parameters:
        callable - the task to be executed
        Returns:
        the result returned by the task
      • executeAsync

        <T> CompletableFuture<T> executeAsync​(@NotNull
                                              Supplier<CompletableFuture<T>> futureSupplier)
        Executes the given CompletableFuture supplier asynchronously against this retrier contect.
        Type Parameters:
        T - the type of the result returned by the CompletableFuture
        Parameters:
        futureSupplier - the supplier that provides the CompletableFuture
        Returns:
        a CompletableFuture that represents the result of the execution
      • execute

        default void execute​(@NotNull
                             Retrier.ExceptionalRunnable runnable)
        Executes the given task against this retrier context.
        Parameters:
        runnable - the task to be executed
      • retryableMapper

        @NotNull
        default <T,​R> Function<T,​R> retryableMapper​(@NotNull
                                                                Function<T,​R> function)
        Executes the given Callable task against this retrier context.
        Type Parameters:
        T -
        R -
        Parameters:
        function - the task to be executed
        Returns:
        the result returned by the task