Class ListenableFuture<V>
java.lang.Object
org.elasticsearch.common.util.concurrent.BaseFuture<V>
org.elasticsearch.common.util.concurrent.ListenableFuture<V>
- All Implemented Interfaces:
java.util.concurrent.Future<V>,ActionListener<V>
public final class ListenableFuture<V> extends BaseFuture<V> implements 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.-
Constructor Summary
Constructors Constructor Description ListenableFuture() -
Method Summary
Modifier and Type Method Description voidaddListener(ActionListener<V> listener, java.util.concurrent.ExecutorService executor)Adds a listener to this future.voidaddListener(ActionListener<V> listener, java.util.concurrent.ExecutorService executor, ThreadContext threadContext)Adds a listener to this future.protected voiddone()voidonFailure(java.lang.Exception e)A failure caused by an exception at some phase of the task.voidonResponse(V v)Handle action response.Methods inherited from class org.elasticsearch.common.util.concurrent.BaseFuture
blockingAllowed, cancel, get, get, interruptTask, isCancelled, isDone, set, setException
-
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 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. -
addListener
public void addListener(ActionListener<V> listener, java.util.concurrent.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()- Overrides:
donein classBaseFuture<V>
-
onResponse
Description copied from interface:ActionListenerHandle action response. This response may constitute a failure or a success but it is up to the listener to make that decision.- Specified by:
onResponsein interfaceActionListener<V>
-
onFailure
public void onFailure(java.lang.Exception e)Description copied from interface:ActionListenerA failure caused by an exception at some phase of the task.- Specified by:
onFailurein interfaceActionListener<V>
-