Package org.apache.avro.ipc
Class CallFuture<T>
java.lang.Object
org.apache.avro.ipc.CallFuture<T>
A Future implementation for RPCs.
-
Constructor Summary
ConstructorsConstructorDescriptionCreates 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 TypeMethodDescriptionvoidawait()Waits for the CallFuture to complete without returning the result.voidWaits for the CallFuture to complete without returning the result.booleancancel(boolean mayInterruptIfRunning) get()getError()Gets the error that was thrown during RPC execution.Gets the value of the RPC result without blocking.voidhandleError(Throwable error) Sets an error thrown during RPC execution, and unblocks all threads waiting onget()orget(long, TimeUnit).voidhandleResult(T result) Sets the RPC response, and unblocks all threads waiting onget()orget(long, TimeUnit).booleanbooleanisDone()
-
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:
handleResultin 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:
handleErrorin 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:
isCancelledin interfaceFuture<T>
-
get
- Specified by:
getin interfaceFuture<T>- Throws:
InterruptedExceptionExecutionException
-
get
public T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException - Specified by:
getin interfaceFuture<T>- Throws:
InterruptedExceptionExecutionExceptionTimeoutException
-
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()
-