Class ListenableFuture<V>
java.lang.Object
org.elasticsearch.common.util.concurrent.BaseFuture<V>
org.elasticsearch.common.util.concurrent.ListenableFuture<V>
- All Implemented Interfaces:
Future<V>
,ActionListener<V>
A future implementation that allows for the result to be passed to listeners waiting for
notification. This is useful for cases where a computation is requested many times
concurrently, but really only needs to be performed a single time. Once the computation
has been performed the registered listeners will be notified by submitting a runnable
for execution in the provided
ExecutorService
. If the computation has already
been performed, a request to add a listener will simply result in execution of the listener
on the calling thread.-
Nested Class Summary
Nested classes/interfaces inherited from interface org.elasticsearch.action.ActionListener
ActionListener.Delegating<Response,DelegateResponse>, ActionListener.DelegatingActionListener<T>, ActionListener.DelegatingFailureActionListener<T,R>, ActionListener.MappedActionListener<Response,MappedResponse>, ActionListener.RunAfterActionListener<T>, ActionListener.RunBeforeActionListener<T>
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addListener(ActionListener<V> listener)
Adds a listener to this future.void
addListener(ActionListener<V> listener, ExecutorService executor, ThreadContext threadContext)
Adds a listener to this future.protected void
done(boolean ignored)
Called when theBaseFuture
is completed.void
A failure caused by an exception at some phase of the task.void
onResponse(V v)
Handle action response.Methods inherited from class org.elasticsearch.common.util.concurrent.BaseFuture
blockingAllowed, cancel, get, get, interruptTask, isCancelled, isDone, set, setException
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.elasticsearch.action.ActionListener
delegateFailure, delegateResponse, map
-
Constructor Details
-
ListenableFuture
public ListenableFuture()
-
-
Method Details
-
addListener
Adds a listener to this future. If the future has not yet completed, the listener will be notified of a response or exception on the thread completing this future. If the future has completed, the listener will be notified immediately without forking to a different thread. -
addListener
public void addListener(ActionListener<V> listener, ExecutorService executor, ThreadContext threadContext)Adds a listener to this future. If the future has not yet completed, the listener will be notified of a response or exception in a runnable submitted to the ExecutorService provided. If the future has completed, the listener will be notified immediately without forking to a different thread. It will apply the provided ThreadContext (if not null) when executing the listening. -
done
protected void done(boolean ignored)Description copied from class:BaseFuture
Called when theBaseFuture
is completed. Thesuccess
boolean indicates if theBaseFuture
was successfully completed (the value istrue
). In the cases theBaseFuture
was completed with an error or cancelled the value isfalse
.- Overrides:
done
in classBaseFuture<V>
- Parameters:
ignored
- indicates if theBaseFuture
was completed with success (true); in other cases it equals to false
-
onResponse
Description copied from interface:ActionListener
Handle action response. This response may constitute a failure or a success but it is up to the listener to make that decision.- Specified by:
onResponse
in interfaceActionListener<V>
-
onFailure
Description copied from interface:ActionListener
A failure caused by an exception at some phase of the task.- Specified by:
onFailure
in interfaceActionListener<V>
-