@Override public <Request extends ActionRequest, Response extends ActionResponse> void apply(Task task, final String action, Request request, ActionListener<Response> listener, ActionFilterChain<Request, Response> chain) { try (StoredContext ctx = threadContext.newStoredContext(true)){ org.apache.logging.log4j.ThreadContext.clearAll(); apply0(task, action, request, listener, chain); } }
private ContextPreservingAbstractRunnable(AbstractRunnable in) { creatorsContext = newStoredContext(false); this.in = in; }
private ContextPreservingRunnable(Runnable in) { ctx = newStoredContext(false); this.in = in; }
final ThreadContext.StoredContext sgContext = getThreadContext().newStoredContext(false);
/** * Same as {@link #newRestorableContext(boolean)} but wraps an existing context to restore. * @param storedContext the context to restore */ public Supplier<StoredContext> wrapRestorable(StoredContext storedContext) { return () -> { StoredContext context = newStoredContext(false); storedContext.restore(); return context; }; }
/** * Returns a supplier that gathers a {@link #newStoredContext(boolean)} and restores it once the * returned supplier is invoked. The context returned from the supplier is a stored version of the * suppliers callers context that should be restored once the originally gathered context is not needed anymore. * For instance this method should be used like this: * * <pre> * Supplier<ThreadContext.StoredContext> restorable = context.newRestorableContext(true); * new Thread() { * public void run() { * try (ThreadContext.StoredContext ctx = restorable.get()) { * // execute with the parents context and restore the threads context afterwards * } * } * * }.start(); * </pre> * * @param preserveResponseHeaders if set to <code>true</code> the response headers of the restore thread will be preserved. * @return a restorable context supplier */ public Supplier<StoredContext> newRestorableContext(boolean preserveResponseHeaders) { return wrapRestorable(newStoredContext(preserveResponseHeaders)); }
ThreadContext.StoredContext storedContext = threadContext.newStoredContext(true); Consumer<Boolean> contextPreservingListener = forced -> { try (ThreadContext.StoredContext ignore = threadContext.stashContext()) {
private ContextPreservingRunnable(Runnable in) { ctx = newStoredContext(false); this.in = in; }
private ContextPreservingRunnable(Runnable in) { ctx = newStoredContext(false); this.in = in; }
private ContextPreservingAbstractRunnable(AbstractRunnable in) { creatorsContext = newStoredContext(false); this.in = in; }
private ContextPreservingAbstractRunnable(AbstractRunnable in) { creatorsContext = newStoredContext(false); this.in = in; }
private ContextPreservingAbstractRunnable(AbstractRunnable in) { creatorsContext = newStoredContext(false); this.in = in; }
private ContextPreservingRunnable(Runnable in) { ctx = newStoredContext(false); this.in = in; }
/** * Same as {@link #newRestorableContext(boolean)} but wraps an existing context to restore. * @param storedContext the context to restore */ public Supplier<StoredContext> wrapRestorable(StoredContext storedContext) { return () -> { StoredContext context = newStoredContext(false); storedContext.restore(); return context; }; }
/** * Same as {@link #newRestorableContext(boolean)} but wraps an existing context to restore. * @param storedContext the context to restore */ public Supplier<StoredContext> wrapRestorable(StoredContext storedContext) { return () -> { StoredContext context = newStoredContext(false); storedContext.restore(); return context; }; }
/** * Same as {@link #newRestorableContext(boolean)} but wraps an existing context to restore. * @param storedContext the context to restore */ public Supplier<StoredContext> wrapRestorable(StoredContext storedContext) { return () -> { StoredContext context = newStoredContext(false); storedContext.restore(); return context; }; }
/** * Returns a supplier that gathers a {@link #newStoredContext(boolean)} and restores it once the * returned supplier is invoked. The context returned from the supplier is a stored version of the * suppliers callers context that should be restored once the originally gathered context is not needed anymore. * For instance this method should be used like this: * * <pre> * Supplier<ThreadContext.StoredContext> restorable = context.newRestorableContext(true); * new Thread() { * public void run() { * try (ThreadContext.StoredContext ctx = restorable.get()) { * // execute with the parents context and restore the threads context afterwards * } * } * * }.start(); * </pre> * * @param preserveResponseHeaders if set to <code>true</code> the response headers of the restore thread will be preserved. * @return a restorable context supplier */ public Supplier<StoredContext> newRestorableContext(boolean preserveResponseHeaders) { return wrapRestorable(newStoredContext(preserveResponseHeaders)); }
/** * Returns a supplier that gathers a {@link #newStoredContext(boolean)} and restores it once the * returned supplier is invoked. The context returned from the supplier is a stored version of the * suppliers callers context that should be restored once the originally gathered context is not needed anymore. * For instance this method should be used like this: * * <pre> * Supplier<ThreadContext.StoredContext> restorable = context.newRestorableContext(true); * new Thread() { * public void run() { * try (ThreadContext.StoredContext ctx = restorable.get()) { * // execute with the parents context and restore the threads context afterwards * } * } * * }.start(); * </pre> * * @param preserveResponseHeaders if set to <code>true</code> the response headers of the restore thread will be preserved. * @return a restorable context supplier */ public Supplier<StoredContext> newRestorableContext(boolean preserveResponseHeaders) { return wrapRestorable(newStoredContext(preserveResponseHeaders)); }
@Override public <Request extends ActionRequest, Response extends ActionResponse> void apply(Task task, final String action, Request request, ActionListener<Response> listener, ActionFilterChain<Request, Response> chain) { try (StoredContext ctx = threadContext.newStoredContext(true)){ org.apache.logging.log4j.ThreadContext.clearAll(); apply0(task, action, request, listener, chain); } }
void retry(Exception failure) { assert failure != null; if (observer.isTimedOut()) { // we running as a last attempt after a timeout has happened. don't retry onFailure(failure); return; } final ThreadContext.StoredContext context = threadPool.getThreadContext().newStoredContext(true); observer.waitForNextChange(new ClusterStateObserver.Listener() { @Override public void onNewClusterState(ClusterState state) { context.close(); run(); } @Override public void onClusterServiceClose() { onFailure(new NodeClosedException(clusterService.localNode())); } @Override public void onTimeout(TimeValue timeout) { context.close(); // Try one more time... run(); } }); }