- All Known Subinterfaces:
PersistentTasksService.WaitForPersistentTaskListener<P>,RejectAwareActionListener<T>
- All Known Implementing Classes:
ChannelActionListener,ContextPreservingActionListener,CountDownActionListener,DelegatingActionListener,FinalizeSnapshotContext,GetSnapshotInfoContext,GroupedActionListener,LatchedActionListener,ListenableActionFuture,ListenableFuture,LoggingTaskListener,PlainActionFuture,RestActionListener,RestActions.NodesResponseRestListener,RestBuilderListener,RestChunkedToXContentListener,RestResponseListener,RestStatusToXContentListener,RestToXContentListener,SearchExecutionStatsCollector,SearchProgressActionListener,SnapshotShardContext,StepListener,SubscribableListener,ThreadedActionListener
public interface ActionListener<Response>
A listener for action responses or failures.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <Response> ActionListener<Response>assertOnce(ActionListener<Response> delegate) static <Response> voidcompleteWith(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>map(CheckedFunction<T, Response, Exception> fn) Creates a listener that wraps this listener, mapping response values via the given mapping function and passing along exceptions to this instance.static <T> ActionListener<T>noop()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.voidA failure caused by an exception at some phase of the task.static <Response> voidonFailure(Iterable<ActionListener<Response>> listeners, Exception failure) Notifies every given listener with the failure passed toonFailure(Exception).static <Response> voidonResponse(Iterable<ActionListener<Response>> listeners, Response response) Notifies every given listener with the response passed toonResponse(Object).voidonResponse(Response response) Handle action response.static <Response> ActionListener<Response>releaseAfter(ActionListener<Response> delegate, Releasable releaseAfter) Wraps a given listener and returns a new listener which releases the providedreleaseAfterresource when the listener is notified via either#onResponseor#onFailure.static <Response> ActionListener<Response>releasing(Releasable releasable) Creates a listener which releases the given resource on completion (whether success or failure)static <T,L extends ActionListener<T>>
voidrun(L listener, CheckedConsumer<L, Exception> action) Execute the given action in atry/catchblock which feeds all exceptions to the given listener'sonFailure(java.lang.Exception)method.static <Response> ActionListener<Response>runAfter(ActionListener<Response> delegate, Runnable runAfter) Wraps a given listener and returns a new listener which executes the providedrunAftercallback when the listener is notified via either#onResponseor#onFailure.static <Response> ActionListener<Response>runBefore(ActionListener<Response> delegate, CheckedRunnable<?> runBefore) Wraps a given listener and returns a new listener which executes the providedrunBeforecallback before the listener is notified via either#onResponseor#onFailure.static <Response> ActionListener<Response>Creates a listener that executes the given runnable on completion (whether successful or otherwise).static <Response> ActionListener<Response>Deprecated, for removal: This API element is subject to removal in a future version.static <DelegateResponse,Response extends DelegateResponse>
ActionListener<Response>wrap(ActionListener<DelegateResponse> delegate) Adds a wrapper around a listener which catches exceptions thrown by itsonResponse(Response)method and feeds them to itsonFailure(java.lang.Exception)method.static <Response> ActionListener<Response>wrap(CheckedConsumer<Response, ? extends Exception> onResponse, Consumer<Exception> onFailure) Creates a listener that executes the appropriate 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. -
noop
- Returns:
- a listener that does nothing
-
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 functionfnbut it is the responsibility ofdelegateto 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
-
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
-
releasing
Creates a listener which releases the given resource on completion (whether success or failure) -
running
Creates a listener that executes the given runnable on completion (whether successful or otherwise).- Type Parameters:
Response- the type of the response, which is ignored.- Parameters:
runnable- the runnable that will be called in event of success or failure. This must not throw.- Returns:
- a listener that executes the given runnable on completion (whether successful or otherwise).
-
wrap
Deprecated, for removal: This API element is subject to removal in a future version.in favour ofrunning(Runnable)because this implementation doesn't "wrap" exceptions fromonResponse(Response)intoonFailure(java.lang.Exception). -
wrap
static <Response> ActionListener<Response> wrap(CheckedConsumer<Response, ? extends Exception> onResponse, Consumer<Exception> onFailure) Creates a listener that executes the appropriate consumer when the response (or failure) is received. This listener is "wrapped" in the sense that an exception from theonResponseconsumer is passed into theonFailureconsumer.- Type Parameters:
Response- the type of the response- Parameters:
onResponse- the checked consumer of the response, executed when the listener is completed successfully. If it throws an exception, the exception is passed to theonFailureconsumer.onFailure- the consumer of the failure, executed when the listener is completed with an exception (or it is completed successfully but theonResponseconsumer threw an exception).- Returns:
- a listener that executes the appropriate consumer when the response (or failure) is received.
-
wrap
static <DelegateResponse,Response extends DelegateResponse> ActionListener<Response> wrap(ActionListener<DelegateResponse> delegate) Adds a wrapper around a listener which catches exceptions thrown by itsonResponse(Response)method and feeds them to itsonFailure(java.lang.Exception)method. -
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 providedrunAftercallback when the listener is notified via either#onResponseor#onFailure. -
releaseAfter
static <Response> ActionListener<Response> releaseAfter(ActionListener<Response> delegate, Releasable releaseAfter) Wraps a given listener and returns a new listener which releases the providedreleaseAfterresource when the listener is notified via either#onResponseor#onFailure. -
runBefore
static <Response> ActionListener<Response> runBefore(ActionListener<Response> delegate, CheckedRunnable<?> runBefore) Wraps a given listener and returns a new listener which executes the providedrunBeforecallback before the listener is notified via either#onResponseor#onFailure. If the callback throws an exception then it will be passed to the listener's#onFailureand its#onResponsewill 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 ofdelegateto handle its own exceptions inside `onResponse` and `onFailure`. -
assertOnce
- Returns:
- A listener which (if assertions are enabled) wraps around the given delegate and asserts that it is only called once.
-
run
Execute the given action in atry/catchblock which feeds all exceptions to the given listener'sonFailure(java.lang.Exception)method.
-
running(Runnable)because this implementation doesn't "wrap" exceptions fromonResponse(Response)intoonFailure(java.lang.Exception).