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 void
onFailure(java.lang.Exception e)
A failure caused by an exception at some phase of the task.void
onResponse(R r)
Handle action response.java.lang.String
toString()
static <R> ContextPreservingActionListener<R>
wrapPreservingContext(ActionListener<R> listener, ThreadContext threadContext)
Wraps the provided action listener in aContextPreservingActionListener
that will also copy the response headers when theThreadContext.StoredContext
is closedMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods 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:ActionListener
Handle action response. This response may constitute a failure or a success but it is up to the listener to make that decision.- Specified by:
onResponse
in interfaceActionListener<R>
-
onFailure
public void onFailure(java.lang.Exception e)Description copied from interface:ActionListener
A failure caused by an exception at some phase of the task.- Specified by:
onFailure
in interfaceActionListener<R>
-
toString
public java.lang.String toString()- Overrides:
toString
in classjava.lang.Object
-
wrapPreservingContext
public static <R> ContextPreservingActionListener<R> wrapPreservingContext(ActionListener<R> listener, ThreadContext threadContext)Wraps the provided action listener in aContextPreservingActionListener
that will also copy the response headers when theThreadContext.StoredContext
is closed
-