Package org.elasticsearch.action
Interface ActionListener<Response>
- All Known Subinterfaces:
PersistentTasksService.WaitForPersistentTaskListener<P>
,RejectAwareActionListener<T>
- All Known Implementing Classes:
ActionListener.Delegating
,ActionListener.DelegatingActionListener
,ActionListener.DelegatingFailureActionListener
,ActionListener.MappedActionListener
,ActionListener.RunAfterActionListener
,ActionListener.RunBeforeActionListener
,AdapterActionFuture
,ChannelActionListener
,ContextPreservingActionListener
,DispatchingRestToXContentListener
,GetSnapshotInfoContext
,GroupedActionListener
,LatchedActionListener
,ListenableActionFuture
,ListenableFuture
,NotifyOnceListener
,PlainActionFuture
,RestActionListener
,RestActions.NodesResponseRestListener
,RestBuilderListener
,RestResponseListener
,RestStatusToXContentListener
,RestToXContentListener
,SearchExecutionStatsCollector
,SearchProgressActionListener
,SnapshotShardContext
,StepListener
,ThreadedActionListener
public interface ActionListener<Response>
A listener for action responses or failures.
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic class
static class
static class
static class
static class
static class
-
Method Summary
Modifier and TypeMethodDescriptionstatic <Response> void
completeWith(ActionListener<Response> listener, CheckedSupplier<Response,? extends Exception> supplier)
Completes the given listener with the result from the provided supplier accordingly.default <T> ActionListener<T>
Creates a listener that delegates all exceptions it receives to another listener.default ActionListener<Response>
Creates a listener that delegates all responses it receives to this instance.default <T> ActionListener<T>
Creates a listener that wraps this listener, mapping response values via the given mapping function and passing along exceptions to this instance.static <Response> ActionListener<Response>
notifyOnce(ActionListener<Response> delegate)
Wraps a given listener and returns a new listener which makes sureonResponse(Object)
andonFailure(Exception)
of the provided listener will be called at most once.void
A failure caused by an exception at some phase of the task.static <Response> void
onFailure(Iterable<ActionListener<Response>> listeners, Exception failure)
Notifies every given listener with the failure passed toonFailure(Exception)
.static <Response> void
onResponse(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> ActionListener<Response>
runAfter(ActionListener<Response> delegate, Runnable runAfter)
Wraps a given listener and returns a new listener which executes the providedrunAfter
callback when the listener is notified via either#onResponse
or#onFailure
.static <Response> ActionListener<Response>
runBefore(ActionListener<Response> delegate, org.elasticsearch.core.CheckedRunnable<?> runBefore)
Wraps a given listener and returns a new listener which executes the providedrunBefore
callback before the listener is notified via either#onResponse
or#onFailure
.static <Response> BiConsumer<Response,Exception>
toBiConsumer(ActionListener<Response> listener)
Converts a listener to aBiConsumer
for compatibility with theCompletableFuture
api.static <Response> ActionListener<Response>
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(org.elasticsearch.core.CheckedConsumer<Response,? extends Exception> onResponse, Consumer<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 Details
-
onResponse
Handle action response. This response may constitute a failure or a success but it is up to the listener to make that decision. -
onFailure
A failure caused by an exception at some phase of the task. -
map
Creates a listener that wraps this listener, mapping response values via the given mapping function and passing along exceptions to this instance. Notice that it is considered a bug if the listener's onResponse or onFailure fails. onResponse failures will not call onFailure. If the function fails, the listener's onFailure handler will be called. The principle is that the mapped listener will handle exceptions from the mapping functionfn
but it is the responsibility ofdelegate
to handle its own exceptions inside `onResponse` and `onFailure`.- Type Parameters:
T
- Response type of the wrapped listener- Parameters:
fn
- Function to apply to listener response- Returns:
- a listener that maps the received response and then passes it to this instance
-
wrap
static <Response> ActionListener<Response> wrap(org.elasticsearch.core.CheckedConsumer<Response,? extends Exception> onResponse, Consumer<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
-
delegateResponse
default ActionListener<Response> delegateResponse(BiConsumer<ActionListener<Response>,Exception> bc)Creates a listener that delegates all responses it receives to this instance.- Parameters:
bc
- BiConsumer invoked with delegate listener and exception- Returns:
- Delegating listener
-
delegateFailure
Creates a listener that delegates all exceptions it receives to another listener.- Type Parameters:
T
- Type of the delegating listener's response- Parameters:
bc
- BiConsumer invoked with delegate listener and response- Returns:
- Delegating listener
-
wrap
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
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
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
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. -
runAfter
static <Response> ActionListener<Response> runAfter(ActionListener<Response> delegate, Runnable runAfter)Wraps a given listener and returns a new listener which executes the providedrunAfter
callback when the listener is notified via either#onResponse
or#onFailure
. -
runBefore
static <Response> ActionListener<Response> runBefore(ActionListener<Response> delegate, org.elasticsearch.core.CheckedRunnable<?> runBefore)Wraps a given listener and returns a new listener which executes the providedrunBefore
callback before the listener is notified via either#onResponse
or#onFailure
. If the callback throws an exception then it will be passed to the listener's#onFailure
and its#onResponse
will not be executed. -
notifyOnce
Wraps a given listener and returns a new listener which makes sureonResponse(Object)
andonFailure(Exception)
of the provided listener will be called at most once. -
completeWith
static <Response> void completeWith(ActionListener<Response> listener, CheckedSupplier<Response,? extends Exception> supplier)Completes the given listener with the result from the provided supplier accordingly. This method is mainly used to complete a listener with a block of synchronous code. If the supplier fails, the listener's onFailure handler will be called. It is the responsibility ofdelegate
to handle its own exceptions inside `onResponse` and `onFailure`.
-