Package org.elasticsearch.action
Interface ActionListener<Response>
-
- All Known Subinterfaces:
PersistentTasksService.WaitForPersistentTaskListener<P>
- All Known Implementing Classes:
AdapterActionFuture
,ContextPreservingActionListener
,DelegatingActionListener
,GroupedActionListener
,LatchedActionListener
,ListenableFuture
,NotifyOnceListener
,PlainActionFuture
,PlainListenableActionFuture
,RestActionListener
,RestActions.NodesResponseRestListener
,RestBuilderListener
,RestResponseListener
,RestStatusToXContentListener
,RestToXContentListener
,SearchExecutionStatsCollector
,ThreadedActionListener
public interface ActionListener<Response>
A listener for action responses or failures.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description void
onFailure(java.lang.Exception e)
A failure caused by an exception at some phase of the task.static <Response> void
onFailure(java.lang.Iterable<ActionListener<Response>> listeners, java.lang.Exception failure)
Notifies every given listener with the failure passed toonFailure(Exception)
.static <Response> void
onResponse(java.lang.Iterable<ActionListener<Response>> listeners, Response response)
Notifies every given listener with the response passed toonResponse(Object)
.void
onResponse(Response response)
Handle action response.static <Response> java.util.function.BiConsumer<Response,java.lang.Throwable>
toBiConsumer(ActionListener<Response> listener)
Converts a listener to aBiConsumer
for compatibility with theCompletableFuture
api.static <Response> ActionListener<Response>
wrap(java.lang.Runnable runnable)
Creates a listener that listens for a response (or failure) and executes the corresponding runnable when the response (or failure) is received.static <Response> ActionListener<Response>
wrap(CheckedConsumer<Response,? extends java.lang.Exception> onResponse, java.util.function.Consumer<java.lang.Exception> onFailure)
Creates a listener that listens for a response (or failure) and executes the corresponding consumer when the response (or failure) is received.
-
-
-
Method Detail
-
onResponse
void onResponse(Response response)
Handle action response. This response may constitute a failure or a success but it is up to the listener to make that decision.
-
onFailure
void onFailure(java.lang.Exception e)
A failure caused by an exception at some phase of the task.
-
wrap
static <Response> ActionListener<Response> wrap(CheckedConsumer<Response,? extends java.lang.Exception> onResponse, java.util.function.Consumer<java.lang.Exception> onFailure)
Creates a listener that listens for a response (or failure) and executes the corresponding consumer when the response (or failure) is received.- Type Parameters:
Response
- the type of the response- Parameters:
onResponse
- the checked consumer of the response, when the listener receives oneonFailure
- the consumer of the failure, when the listener receives one- Returns:
- a listener that listens for responses and invokes the consumer when received
-
wrap
static <Response> ActionListener<Response> wrap(java.lang.Runnable runnable)
Creates a listener that listens for a response (or failure) and executes the corresponding runnable when the response (or failure) is received.- Type Parameters:
Response
- the type of the response- Parameters:
runnable
- the runnable that will be called in event of success or failure- Returns:
- a listener that listens for responses and invokes the runnable when received
-
toBiConsumer
static <Response> java.util.function.BiConsumer<Response,java.lang.Throwable> toBiConsumer(ActionListener<Response> listener)
Converts a listener to aBiConsumer
for compatibility with theCompletableFuture
api.- Type Parameters:
Response
- the type of the response- Parameters:
listener
- that will be wrapped- Returns:
- a bi consumer that will complete the wrapped listener
-
onResponse
static <Response> void onResponse(java.lang.Iterable<ActionListener<Response>> listeners, Response response)
Notifies every given listener with the response passed toonResponse(Object)
. If a listener itself throws an exception the exception is forwarded toonFailure(Exception)
. If in turnonFailure(Exception)
fails all remaining listeners will be processed and the caught exception will be re-thrown.
-
onFailure
static <Response> void onFailure(java.lang.Iterable<ActionListener<Response>> listeners, java.lang.Exception failure)
Notifies every given listener with the failure passed toonFailure(Exception)
. If a listener itself throws an exception all remaining listeners will be processed and the caught exception will be re-thrown.
-
-