Package com.atlassian.bamboo.executor
Class RetryingTaskExecutor<T>
- java.lang.Object
-
- com.atlassian.bamboo.executor.RetryingTaskExecutor<T>
-
public class RetryingTaskExecutor<T> extends Object
Helper class that allows you to easily run a task that is likely to fail multiple times. It will attempt to rerun the task using a backing off algorithm or constant time. By default backing off is used with 1000ms initial delay and 10 max retries. Delays are capped at 60s per run. The last attempt will be at least 4 minutes after the first call.
-
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_BACK_OFF_MULTIPLIER
static Duration
DEFAULT_INITIAL_RETRY_DELAY
static int
DEFAULT_MAX_RETRIES
static Duration
DEFAULT_MAX_RETRY_DELAY
protected T
objectToReturn
-
Constructor Summary
Constructors Constructor Description RetryingTaskExecutor()
RetryingTaskExecutor(int maxRetries, boolean rethrowLastException)
RetryingTaskExecutor(long initialRetryDelayMs, int maxRetries)
Deprecated.since 6.1, useRetryingTaskExecutor(Duration, int)
RetryingTaskExecutor(long initialRetryDelayMs, int maxRetries, boolean useExponentialBackOff)
Deprecated.since 6.1, useRetryingTaskExecutor(Duration, int, boolean)
RetryingTaskExecutor(long initialRetryDelayMs, long maxRetryDelay, int maxRetries, long backOffMultiplier, boolean useExponentialBackOff, boolean rethrowLastException)
Deprecated.RetryingTaskExecutor(Duration initialRetryDelay, int maxRetries)
RetryingTaskExecutor(Duration initialRetryDelay, int maxRetries, boolean useExponentialBackOff)
RetryingTaskExecutor(Duration initialRetryDelay, Duration maxRetryDelay, int maxRetries, long backOffMultiplier, boolean useExponentialBackOff, boolean rethrowLastException)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description T
getObjectToReturn()
static Duration
randomInitialDelay()
static <T> T
retry(@NotNull String message, int retries, long initialRetryDelayMs, @NotNull Callable<T> call, com.google.common.base.Predicate<Exception> shouldRetry)
Deprecated.since 6.1 useretry(String, int, Duration, Callable, Predicate)
static <T> T
retry(@NotNull String message, int retries, Duration initialRetryDelay, @NotNull Callable<T> call, @NotNull Predicate<Exception> shouldRetry)
static <T> T
retry(String message, int retries, long initialRetryDelayMs, Callable<T> call)
Deprecated.since 6.1 useretry(String, int, Duration, Callable)
static <T> T
retry(String message, int retries, Duration initialRetryDelay, Callable<T> call)
Shortcut method that retries the callable up to a certain number of times.void
runTask(@NotNull Callable<T> task)
void
runTask(String taskName, @NotNull Callable<T> callable)
-
-
-
Field Detail
-
DEFAULT_MAX_RETRY_DELAY
public static final Duration DEFAULT_MAX_RETRY_DELAY
-
DEFAULT_MAX_RETRIES
public static final int DEFAULT_MAX_RETRIES
- See Also:
- Constant Field Values
-
DEFAULT_INITIAL_RETRY_DELAY
public static final Duration DEFAULT_INITIAL_RETRY_DELAY
-
DEFAULT_BACK_OFF_MULTIPLIER
public static final int DEFAULT_BACK_OFF_MULTIPLIER
- See Also:
- Constant Field Values
-
objectToReturn
protected volatile T objectToReturn
-
-
Constructor Detail
-
RetryingTaskExecutor
public RetryingTaskExecutor(Duration initialRetryDelay, Duration maxRetryDelay, int maxRetries, long backOffMultiplier, boolean useExponentialBackOff, boolean rethrowLastException)
-
RetryingTaskExecutor
public RetryingTaskExecutor(Duration initialRetryDelay, int maxRetries)
-
RetryingTaskExecutor
public RetryingTaskExecutor(int maxRetries, boolean rethrowLastException)
-
RetryingTaskExecutor
public RetryingTaskExecutor(Duration initialRetryDelay, int maxRetries, boolean useExponentialBackOff)
-
RetryingTaskExecutor
public RetryingTaskExecutor()
-
RetryingTaskExecutor
@Deprecated public RetryingTaskExecutor(long initialRetryDelayMs, long maxRetryDelay, int maxRetries, long backOffMultiplier, boolean useExponentialBackOff, boolean rethrowLastException)
Deprecated.
-
RetryingTaskExecutor
@Deprecated public RetryingTaskExecutor(long initialRetryDelayMs, int maxRetries)
Deprecated.since 6.1, useRetryingTaskExecutor(Duration, int)
-
RetryingTaskExecutor
@Deprecated public RetryingTaskExecutor(long initialRetryDelayMs, int maxRetries, boolean useExponentialBackOff)
Deprecated.since 6.1, useRetryingTaskExecutor(Duration, int, boolean)
-
-
Method Detail
-
getObjectToReturn
public T getObjectToReturn()
-
retry
@Deprecated public static <T> T retry(String message, int retries, long initialRetryDelayMs, Callable<T> call)
Deprecated.since 6.1 useretry(String, int, Duration, Callable)
-
retry
public static <T> T retry(String message, int retries, Duration initialRetryDelay, Callable<T> call)
Shortcut method that retries the callable up to a certain number of times. The retry will rethrow the last exception it catches.- Type Parameters:
T
- what object to return- Parameters:
message
-retries
-initialRetryDelay
-call
-- Returns:
-
retry
@Deprecated public static <T> T retry(@NotNull @NotNull String message, int retries, long initialRetryDelayMs, @NotNull @NotNull Callable<T> call, @NotNull com.google.common.base.Predicate<Exception> shouldRetry)
Deprecated.since 6.1 useretry(String, int, Duration, Callable, Predicate)
-
retry
public static <T> T retry(@NotNull @NotNull String message, int retries, Duration initialRetryDelay, @NotNull @NotNull Callable<T> call, @NotNull @NotNull Predicate<Exception> shouldRetry)
-
randomInitialDelay
public static Duration randomInitialDelay()
-
-