com.twitter.common.thrift.callers
Class DeadlineCaller

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

public class DeadlineCaller
extends Object

A caller that imposes a time deadline on the underlying caller. If the underlying calls fail to meet the deadline TTimeoutException is thrown. If the executor service rejects execution of a task, TResourceExhaustedException is thrown.


Nested Class Summary
 
Nested classes/interfaces inherited from interface com.twitter.common.thrift.callers.Caller
Caller.ResultCapture, Caller.WrappedMethodCallback
 
Constructor Summary
DeadlineCaller(Caller decoratedCaller, boolean async, ExecutorService executorService, Amount<Long,Time> timeout)
          Creates a new deadline 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
 

Constructor Detail

DeadlineCaller

public DeadlineCaller(Caller decoratedCaller,
                      boolean async,
                      ExecutorService executorService,
                      Amount<Long,Time> timeout)
Creates a new deadline caller.

Parameters:
decoratedCaller - The caller to decorate with a deadline.
async - Whether the caller is asynchronous.
executorService - The executor service to use for performing calls.
timeout - The timeout by which the underlying call should complete in.
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.