Package org.apache.avro.ipc
Class CallFuture<T>
java.lang.Object
org.apache.avro.ipc.CallFuture<T>
A Future implementation for RPCs.
-
Constructor Summary
ConstructorDescriptionCreates 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
Modifier and TypeMethodDescriptionvoid
await()
Waits for the CallFuture to complete without returning the result.void
Waits for the CallFuture to complete without returning the result.boolean
cancel
(boolean mayInterruptIfRunning) get()
getError()
Gets the error that was thrown during RPC execution.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 onget()
orget(long, TimeUnit)
.void
handleResult
(T result) Sets the RPC response, and unblocks all threads waiting onget()
orget(long, TimeUnit)
.boolean
boolean
isDone()
-
Constructor Details
-
CallFuture
public CallFuture()Creates a CallFuture. -
CallFuture
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 Details
-
handleResult
Sets the RPC response, and unblocks all threads waiting onget()
orget(long, TimeUnit)
.- Specified by:
handleResult
in interfaceCallback<T>
- Parameters:
result
- the RPC result to set.
-
handleError
Sets an error thrown during RPC execution, and unblocks all threads waiting onget()
orget(long, TimeUnit)
.- Specified by:
handleError
in interfaceCallback<T>
- Parameters:
error
- the RPC error to set.
-
getResult
Gets the value of the RPC result without blocking. Usingget()
orget(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
Gets the error that was thrown during RPC execution. Does not block. Eitherget()
orget(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) -
isCancelled
public boolean isCancelled()- Specified by:
isCancelled
in interfaceFuture<T>
-
get
- Specified by:
get
in interfaceFuture<T>
- Throws:
InterruptedException
ExecutionException
-
get
public T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException - Specified by:
get
in interfaceFuture<T>
- Throws:
InterruptedException
ExecutionException
TimeoutException
-
await
Waits for the CallFuture to complete without returning the result.- Throws:
InterruptedException
- if interrupted.
-
await
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()
-