Package jetbrains.buildServer.util.retry
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 withwithRetries(int, DelayListener)
method
Users are encouraged to register their own listeners to the different events related to the retrier throughRetrierEventListener
. In these events exceptions such asAbortRetriesException
andRecoverableException
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
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
Retrier.DelayStrategy
static interface
Retrier.ExceptionalRunnable
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description <T> T
execute(Callable<T> callable)
Executes the given Callable task against this retrier context.default void
execute(Retrier.ExceptionalRunnable runnable)
Executes the given task against this retrier context.<T> CompletableFuture<T>
executeAsync(Supplier<CompletableFuture<T>> futureSupplier)
Executes the given CompletableFuture supplier asynchronously against this retrier contect.Retrier
registerListener(RetrierEventListener retrier)
Registers a listener to be notified of events during task execution and retries.default <T,R>
Function<T,R>retryableMapper(Function<T,R> function)
Executes the given Callable task against this retrier context.static Retrier
withRetries(int nRetries, jetbrains.buildServer.util.retry.DelayListener delayListener)
Creates a Retrier instance with the specified number of retries.
-
-
-
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 performeddelayListener
- delay strategy for the retrier. SeeRetrier.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
-
registerListener
@NotNull Retrier registerListener(@NotNull RetrierEventListener retrier)
Registers a listener to be notified of events during task execution and retries.
These listeners are able to stop the execution of the retrier by throwing exceptions during the following methods:RetrierEventListener.beforeRetry(Callable, int)
,RetrierEventListener.onSuccess(Callable, int)
,RetrierEventListener.onFailure(Callable, int, Exception)
- Parameters:
retrier
- the listener to be registered- Returns:
- the same Retrier instance with the listener registered
-
-