com.twitter.common.util.concurrent
Class RetryingFutureTask

java.lang.Object
  extended by java.util.concurrent.FutureTask<Boolean>
      extended by com.twitter.common.util.concurrent.RetryingFutureTask
All Implemented Interfaces:
Runnable, Future<Boolean>, RunnableFuture<Boolean>
Direct Known Subclasses:
BackingOffFutureTask

public class RetryingFutureTask
extends FutureTask<Boolean>

A future task that supports retries by resubmitting itself to an ExecutorService.


Field Summary
protected  Callable<Boolean> callable
           
protected  ExecutorService executor
           
protected  int maxRetries
           
protected  int numRetries
           
 
Constructor Summary
RetryingFutureTask(ExecutorService executor, Callable<Boolean> callable, int maxRetries)
          Creates a new retrying future task that will execute a unit of work until successfully completed, or the retry limit has been reached.
 
Method Summary
protected  void retry()
          Invokes a retry of this task.
 void run()
           
 
Methods inherited from class java.util.concurrent.FutureTask
cancel, done, get, get, isCancelled, isDone, runAndReset, set, setException
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

executor

protected final ExecutorService executor

maxRetries

protected final int maxRetries

numRetries

protected int numRetries

callable

protected final Callable<Boolean> callable
Constructor Detail

RetryingFutureTask

public RetryingFutureTask(ExecutorService executor,
                          Callable<Boolean> callable,
                          int maxRetries)
Creates a new retrying future task that will execute a unit of work until successfully completed, or the retry limit has been reached.

Parameters:
executor - The executor service to resubmit the task to upon failure.
callable - The unit of work. The work is considered successful when true is returned. It may return false or throw an exception when unsueccessful.
maxRetries - The maximum number of times to retry the task.
Method Detail

retry

protected void retry()
Invokes a retry of this task.


run

public void run()
Specified by:
run in interface Runnable
Specified by:
run in interface RunnableFuture<Boolean>
Overrides:
run in class FutureTask<Boolean>