com.twitter.common.thrift.callers
Class RetryingCaller

java.lang.Object
  extended by com.twitter.common.thrift.callers.RetryingCaller
All Implemented Interfaces:
Caller

public class RetryingCaller
extends Object

A caller that will retry calls to the wrapped caller.


Nested Class Summary
 
Nested classes/interfaces inherited from interface com.twitter.common.thrift.callers.Caller
Caller.ResultCapture, Caller.WrappedMethodCallback
 
Field Summary
static Amount<Long,Time> NONBLOCKING_TIMEOUT
           
 
Constructor Summary
RetryingCaller(Caller decoratedCall, boolean async, StatsProvider statsProvider, String serviceName, int retries, ImmutableSet<Class<? extends Exception>> retryableExceptions, boolean debug)
          Creates a new retrying caller.
 
Method Summary
 Object call(Method method, Object[] args, org.apache.thrift.async.AsyncMethodCallback callback, Amount<Long,Time> connectTimeoutOverride)
          Invokes a method on an object, using the given arguments.
protected  Object invoke(Method method, Object[] args, org.apache.thrift.async.AsyncMethodCallback callback, Caller.ResultCapture capture, Amount<Long,Time> connectTimeoutOverride)
          Convenience method for invoking the method and shunting the capture into the callback if the call is asynchronous.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NONBLOCKING_TIMEOUT

public static final Amount<Long,Time> NONBLOCKING_TIMEOUT
Constructor Detail

RetryingCaller

public RetryingCaller(Caller decoratedCall,
                      boolean async,
                      StatsProvider statsProvider,
                      String serviceName,
                      int retries,
                      ImmutableSet<Class<? extends Exception>> retryableExceptions,
                      boolean debug)
Creates a new retrying caller. The retrying caller will attempt to call invoked methods on the underlying caller at most retries times. A retry will be performed only when one of the retryableExceptions is caught.

Parameters:
decoratedCall - The caller to decorate with retries.
async - Whether the caller is asynchronous.
statsProvider - The stat provider to export retry statistics through.
serviceName - The service name that calls are being invoked on.
retries - The maximum number of retries to perform.
retryableExceptions - The exceptions that can be retried.
debug - Whether to include debugging information when retries are being performed.
Method Detail

call

public Object call(Method method,
                   Object[] args,
                   @Nullable
                   org.apache.thrift.async.AsyncMethodCallback callback,
                   @Nullable
                   Amount<Long,Time> connectTimeoutOverride)
            throws Throwable
Description copied from interface: Caller
Invokes a method on an object, using the given arguments. The method call may be asynchronous, in which case callback will be non-null.

Parameters:
method - The method being invoked.
args - The arguments to call method with.
callback - The callback to use if the method is asynchronous.
connectTimeoutOverride - Optional override for the default connection timeout.
Returns:
The return value from invoking the method.
Throws:
Throwable - Exception, as prescribed by the method's contract.

invoke

protected final Object invoke(Method method,
                              Object[] args,
                              @Nullable
                              org.apache.thrift.async.AsyncMethodCallback callback,
                              @Nullable
                              Caller.ResultCapture capture,
                              @Nullable
                              Amount<Long,Time> connectTimeoutOverride)
                       throws Throwable
Convenience method for invoking the method and shunting the capture into the callback if the call is asynchronous.

Parameters:
method - The method being invoked.
args - The arguments to call method with.
callback - The callback to use if the method is asynchronous.
capture - The result capture to notify of the call result.
connectTimeoutOverride - Optional override for the default connection timeout.
Returns:
The return value from invoking the method.
Throws:
Throwable - Exception, as prescribed by the method's contract.