org.apache.avro.ipc
Class CallFuture<T>

java.lang.Object
  extended by org.apache.avro.ipc.CallFuture<T>
All Implemented Interfaces:
Future<T>, Callback<T>

public class CallFuture<T>
extends Object
implements Future<T>, Callback<T>

A Future implementation for RPCs.


Constructor Summary
CallFuture()
          Creates a CallFuture.
CallFuture(Callback<T> chainedCallback)
          Creates a CallFuture with a chained Callback which will be invoked when this CallFuture's Callback methods are invoked.
 
Method Summary
 void await()
          Waits for the CallFuture to complete without returning the result.
 void await(long timeout, TimeUnit unit)
          Waits for the CallFuture to complete without returning the result.
 boolean cancel(boolean mayInterruptIfRunning)
           
 T get()
           
 T get(long timeout, TimeUnit unit)
           
 Throwable getError()
          Gets the error that was thrown during RPC execution.
 T getResult()
          Gets the value of the RPC result without blocking.
 void handleError(Throwable error)
          Sets an error thrown during RPC execution, and unblocks all threads waiting on get() or get(long, TimeUnit).
 void handleResult(T result)
          Sets the RPC response, and unblocks all threads waiting on get() or get(long, TimeUnit).
 boolean isCancelled()
           
 boolean isDone()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CallFuture

public CallFuture()
Creates a CallFuture.


CallFuture

public CallFuture(Callback<T> chainedCallback)
Creates a CallFuture with a chained Callback which will be invoked when this CallFuture's Callback methods are invoked.

Parameters:
chainedCallback - the chained Callback to set.
Method Detail

handleResult

public void handleResult(T result)
Sets the RPC response, and unblocks all threads waiting on get() or get(long, TimeUnit).

Specified by:
handleResult in interface Callback<T>
Parameters:
result - the RPC result to set.

handleError

public void handleError(Throwable error)
Sets an error thrown during RPC execution, and unblocks all threads waiting on get() or get(long, TimeUnit).

Specified by:
handleError in interface Callback<T>
Parameters:
error - the RPC error to set.

getResult

public T getResult()
Gets the value of the RPC result without blocking. Using get() or get(long, TimeUnit) is usually preferred because these methods block until the result is available or an error occurs.

Returns:
the value of the response, or null if no result was returned or the RPC has not yet completed.

getError

public Throwable getError()
Gets the error that was thrown during RPC execution. Does not block. Either get() or get(long, TimeUnit) should be called first because these methods block until the RPC has completed.

Returns:
the RPC error that was thrown, or null if no error has occurred or if the RPC has not yet completed.

cancel

public boolean cancel(boolean mayInterruptIfRunning)
Specified by:
cancel in interface Future<T>

isCancelled

public boolean isCancelled()
Specified by:
isCancelled in interface Future<T>

get

public T get()
      throws InterruptedException,
             ExecutionException
Specified by:
get in interface Future<T>
Throws:
InterruptedException
ExecutionException

get

public T get(long timeout,
             TimeUnit unit)
      throws InterruptedException,
             ExecutionException,
             TimeoutException
Specified by:
get in interface Future<T>
Throws:
InterruptedException
ExecutionException
TimeoutException

await

public void await()
           throws InterruptedException
Waits for the CallFuture to complete without returning the result.

Throws:
InterruptedException - if interrupted.

await

public void await(long timeout,
                  TimeUnit unit)
           throws InterruptedException,
                  TimeoutException
Waits for the CallFuture to complete without returning the result.

Parameters:
timeout - the maximum time to wait.
unit - the time unit of the timeout argument.
Throws:
InterruptedException - if interrupted.
TimeoutException - if the wait timed out.

isDone

public boolean isDone()
Specified by:
isDone in interface Future<T>


Copyright © 2011 The Apache Software Foundation. All Rights Reserved.