com.twitter.common.util
Class RateLimitedCommandExecutor

java.lang.Object
  extended by com.twitter.common.util.RateLimitedCommandExecutor
All Implemented Interfaces:
CommandExecutor

public class RateLimitedCommandExecutor
extends Object
implements CommandExecutor

CommandExecutor that invokes queueDrainer with a best-effort mechanism to execute with a fixed interval between requests of intervalBetweenRequests.


Constructor Summary
RateLimitedCommandExecutor(ScheduledExecutorService taskExecutor, Amount<Long,Time> intervalBetweenRequests, Runnable queueDrainer, BlockingQueue<RetryingRunnable> blockingQueue)
          Create a CommandExecutor that executes enquequed tasks in the task executor with specified interval between executions.
 
Method Summary
<E extends Exception>
void
execute(String name, ExceptionalCommand<E> task, Class<E> exceptionClass, int numTries, Amount<Long,Time> retryDelay)
          Enqueue a task to be executed with retry semantics defined.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RateLimitedCommandExecutor

public RateLimitedCommandExecutor(ScheduledExecutorService taskExecutor,
                                  Amount<Long,Time> intervalBetweenRequests,
                                  Runnable queueDrainer,
                                  BlockingQueue<RetryingRunnable> blockingQueue)
Create a CommandExecutor that executes enquequed tasks in the task executor with specified interval between executions.

Parameters:
taskExecutor - executor for periodic execution of enqueued tasks.
intervalBetweenRequests - interval between requests to rate limit request rate.
queueDrainer - A runnable that is responsible for draining the queue.
blockingQueue - Queue to keep outstanding work in.
Method Detail

execute

public <E extends Exception> void execute(String name,
                                          ExceptionalCommand<E> task,
                                          Class<E> exceptionClass,
                                          int numTries,
                                          Amount<Long,Time> retryDelay)
Description copied from interface: CommandExecutor
Enqueue a task to be executed with retry semantics defined.

Specified by:
execute in interface CommandExecutor
Parameters:
name - Human readable name for this task.
task - task to execute.
exceptionClass - Concrete exception type.
numTries - num of tries in case of failure.
retryDelay - interval between retries in case of failure.