Package org.elasticsearch.action.support
Class ContextPreservingActionListener<R>
java.lang.Object
org.elasticsearch.action.support.ContextPreservingActionListener<R>
- All Implemented Interfaces:
ActionListener<R>
public final class ContextPreservingActionListener<R> extends java.lang.Object implements ActionListener<R>
Restores the given
ThreadContext.StoredContext
once the listener is invoked-
Nested Class Summary
Nested classes/interfaces inherited from interface org.elasticsearch.action.ActionListener
ActionListener.MappedActionListener<Response,MappedResponse> -
Constructor Summary
Constructors Constructor Description ContextPreservingActionListener(java.util.function.Supplier<ThreadContext.StoredContext> contextSupplier, ActionListener<R> delegate) -
Method Summary
Modifier and Type Method Description voidonFailure(java.lang.Exception e)A failure caused by an exception at some phase of the task.voidonResponse(R r)Handle action response.java.lang.StringtoString()static <R> ContextPreservingActionListener<R>wrapPreservingContext(ActionListener<R> listener, ThreadContext threadContext)Wraps the provided action listener in aContextPreservingActionListenerthat will also copy the response headers when theThreadContext.StoredContextis closedMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.elasticsearch.action.ActionListener
map
-
Constructor Details
-
ContextPreservingActionListener
public ContextPreservingActionListener(java.util.function.Supplier<ThreadContext.StoredContext> contextSupplier, ActionListener<R> delegate)
-
-
Method Details
-
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<R>
-
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<R>
-
toString
public java.lang.String toString()- Overrides:
toStringin classjava.lang.Object
-
wrapPreservingContext
public static <R> ContextPreservingActionListener<R> wrapPreservingContext(ActionListener<R> listener, ThreadContext threadContext)Wraps the provided action listener in aContextPreservingActionListenerthat will also copy the response headers when theThreadContext.StoredContextis closed
-