com.atlassian.bamboo.executor
Class RetryingTaskExecutor<T>

java.lang.Object
  extended by com.atlassian.bamboo.executor.RetryingTaskExecutor<T>

public class RetryingTaskExecutor<T>
extends java.lang.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
static int DEFAULT_BACK_OFF_MULTIPLIER
           
static int DEFAULT_INITIAL_RETRY_DELAY
           
static int DEFAULT_MAX_RETRIES
           
static long DEFAULT_MAX_RETRY_DELAY
           
protected  T objectToReturn
           
 
Constructor Summary
RetryingTaskExecutor()
           
RetryingTaskExecutor(int maxRetries, boolean rethrowLastException)
           
RetryingTaskExecutor(long initialRetryDelayMs, int maxRetries)
           
RetryingTaskExecutor(long initialRetryDelayMs, int maxRetries, boolean useExponentialBackOff)
           
RetryingTaskExecutor(long initialRetryDelayMs, long maxRetryDelay, int maxRetries, long backOffMultiplier, boolean useExponentialBackOff, boolean rethrowLastException)
           
 
Method Summary
 T getObjectToReturn()
           
static
<T> T
retry(java.lang.String message, int retries, long initialRetryDelayMs, java.util.concurrent.Callable<T> call)
          Shortcut method that retries the callable up to a certain number of times.
static
<T> T
retry(java.lang.String message, int retries, long initialRetryDelayMs, java.util.concurrent.Callable<T> call, com.google.common.base.Predicate<java.lang.Exception> shouldRetry)
           
 void runTask(java.util.concurrent.Callable<T> task)
           
 void runTask(java.lang.String taskName, java.util.concurrent.Callable<T> callable)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_MAX_RETRY_DELAY

public static final long DEFAULT_MAX_RETRY_DELAY
See Also:
Constant Field Values

DEFAULT_MAX_RETRIES

public static final int DEFAULT_MAX_RETRIES
See Also:
Constant Field Values

DEFAULT_INITIAL_RETRY_DELAY

public static final int DEFAULT_INITIAL_RETRY_DELAY
See Also:
Constant Field Values

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(long initialRetryDelayMs,
                            long maxRetryDelay,
                            int maxRetries,
                            long backOffMultiplier,
                            boolean useExponentialBackOff,
                            boolean rethrowLastException)

RetryingTaskExecutor

public RetryingTaskExecutor(long initialRetryDelayMs,
                            int maxRetries)

RetryingTaskExecutor

public RetryingTaskExecutor(long initialRetryDelayMs,
                            int maxRetries,
                            boolean useExponentialBackOff)

RetryingTaskExecutor

public RetryingTaskExecutor(int maxRetries,
                            boolean rethrowLastException)

RetryingTaskExecutor

public RetryingTaskExecutor()
Method Detail

runTask

public void runTask(@NotNull
                    java.util.concurrent.Callable<T> task)

runTask

public void runTask(java.lang.String taskName,
                    @NotNull
                    java.util.concurrent.Callable<T> callable)

getObjectToReturn

public T getObjectToReturn()

retry

public static <T> T retry(java.lang.String message,
                          int retries,
                          long initialRetryDelayMs,
                          java.util.concurrent.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 -
initialRetryDelayMs - in milliseconds
call -
Returns:

retry

public static <T> T retry(@NotNull
                          java.lang.String message,
                          int retries,
                          long initialRetryDelayMs,
                          @NotNull
                          java.util.concurrent.Callable<T> call,
                          @NotNull
                          com.google.common.base.Predicate<java.lang.Exception> shouldRetry)


Copyright © 2013 Atlassian Software Systems Pty Ltd. All Rights Reserved.