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 givenThreadContext.StoredContext
once the listener is invoked
-
-
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.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
-
-
-
Constructor Detail
-
ContextPreservingActionListener
public ContextPreservingActionListener(java.util.function.Supplier<ThreadContext.StoredContext> contextSupplier, ActionListener<R> delegate)
-
-
Method Detail
-
onResponse
public void onResponse(R r)
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>
-
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
-
-