/** * Wraps the provided action listener in a {@link ContextPreservingActionListener} that will * also copy the response headers when the {@link ThreadContext.StoredContext} is closed */ public static <R> ContextPreservingActionListener<R> wrapPreservingContext(ActionListener<R> listener, ThreadContext threadContext) { return new ContextPreservingActionListener<>(threadContext.newRestorableContext(true), listener); } }
final Supplier<ThreadContext.StoredContext> supplier = threadContext.newRestorableContext(true); try (ThreadContext.StoredContext ignore = threadContext.stashContext()) { threadContext.markAsSystemContext();
listener = new ContextPreservingListener(listener, contextHolder.newRestorableContext(false)); if (observingContext.get() != null) { throw new ElasticsearchException("already waiting for a cluster state change");
@Override protected < Request extends ActionRequest, Response extends ActionResponse, RequestBuilder extends ActionRequestBuilder<Request, Response, RequestBuilder>> void doExecute( Action<Request, Response, RequestBuilder> action, Request request, ActionListener<Response> listener) { final Supplier<ThreadContext.StoredContext> supplier = in().threadPool().getThreadContext().newRestorableContext(false); try (ThreadContext.StoredContext ignore = in().threadPool().getThreadContext().stashWithOrigin(origin)) { super.doExecute(action, request, new ContextPreservingActionListener<>(supplier, listener)); } } }
synchronized (this) { if (queuedBlockOperations > 0) { final Supplier<StoredContext> contextSupplier = threadPool.getThreadContext().newRestorableContext(false); final ActionListener<Releasable> wrappedListener; if (executorOnDelay != null) {
ThreadContext threadContext = threadPool.getThreadContext(); TransportService.ContextRestoreResponseHandler<ClusterStateResponse> responseHandler = new TransportService .ContextRestoreResponseHandler<>(threadContext.newRestorableContext(false), new SniffClusterStateResponseHandler(connection, listener, seedNodes, cancellableThreads));
Supplier<ThreadContext.StoredContext> storedContextSupplier = threadPool.getThreadContext().newRestorableContext(true); ContextRestoreResponseHandler<T> responseHandler = new ContextRestoreResponseHandler<>(storedContextSupplier, handler);
/** * Wraps the provided action listener in a {@link ContextPreservingActionListener} that will * also copy the response headers when the {@link ThreadContext.StoredContext} is closed */ public static <R> ContextPreservingActionListener<R> wrapPreservingContext(ActionListener<R> listener, ThreadContext threadContext) { return new ContextPreservingActionListener<>(threadContext.newRestorableContext(true), listener); } }
/** * Wraps the provided action listener in a {@link ContextPreservingActionListener} that will * also copy the response headers when the {@link ThreadContext.StoredContext} is closed */ public static <R> ContextPreservingActionListener<R> wrapPreservingContext(ActionListener<R> listener, ThreadContext threadContext) { return new ContextPreservingActionListener<>(threadContext.newRestorableContext(true), listener); } }
/** * Wraps the provided action listener in a {@link ContextPreservingActionListener} that will * also copy the response headers when the {@link ThreadContext.StoredContext} is closed */ public static <R> ContextPreservingActionListener<R> wrapPreservingContext(ActionListener<R> listener, ThreadContext threadContext) { return new ContextPreservingActionListener<>(threadContext.newRestorableContext(true), listener); } }
final Supplier<ThreadContext.StoredContext> supplier = threadContext.newRestorableContext(true); try (ThreadContext.StoredContext ignore = threadContext.stashContext()) { threadContext.markAsSystemContext();
final Supplier<ThreadContext.StoredContext> supplier = threadContext.newRestorableContext(true); try (ThreadContext.StoredContext ignore = threadContext.stashContext()) { threadContext.markAsSystemContext();
listener = new ContextPreservingListener(listener, contextHolder.newRestorableContext(false)); if (observingContext.get() != null) { throw new ElasticsearchException("already waiting for a cluster state change");
delayedOperations = new ArrayList<>(); final Supplier<StoredContext> contextSupplier = threadPool.getThreadContext().newRestorableContext(false); if (executorOnDelay != null) { delayedOperations.add(
/** * Cancels a locally running task using the Task Manager API */ void sendCancelRequest(final long taskId, final String reason, final ActionListener<CancelTasksResponse> listener) { CancelTasksRequest request = new CancelTasksRequest(); request.setTaskId(new TaskId(clusterService.localNode().getId(), taskId)); request.setReason(reason); try { final ThreadContext threadContext = client.threadPool().getThreadContext(); final Supplier<ThreadContext.StoredContext> supplier = threadContext.newRestorableContext(false); try (ThreadContext.StoredContext ignore = stashWithOrigin(threadContext, PERSISTENT_TASK_ORIGIN)) { client.admin().cluster().cancelTasks(request, new ContextPreservingActionListener<>(supplier, listener)); } } catch (Exception e) { listener.onFailure(e); } }
/** * Executes an asynchronous persistent task action using the client. * <p> * The origin is set in the context and the listener is wrapped to ensure the proper context is restored */ private <Req extends ActionRequest, Resp extends PersistentTaskResponse, Builder extends ActionRequestBuilder<Req, Resp, Builder>> void execute(final Req request, final Action<Req, Resp, Builder> action, final ActionListener<PersistentTask<?>> listener) { try { final ThreadContext threadContext = client.threadPool().getThreadContext(); final Supplier<ThreadContext.StoredContext> supplier = threadContext.newRestorableContext(false); try (ThreadContext.StoredContext ignore = stashWithOrigin(threadContext, PERSISTENT_TASK_ORIGIN)) { client.execute(action, request, new ContextPreservingActionListener<>(supplier, ActionListener.wrap(r -> listener.onResponse(r.getTask()), listener::onFailure))); } } catch (Exception e) { listener.onFailure(e); } }
/** * Cancels a locally running task using the Task Manager API */ void sendCancelRequest(final long taskId, final String reason, final ActionListener<CancelTasksResponse> listener) { CancelTasksRequest request = new CancelTasksRequest(); request.setTaskId(new TaskId(clusterService.localNode().getId(), taskId)); request.setReason(reason); try { final ThreadContext threadContext = client.threadPool().getThreadContext(); final Supplier<ThreadContext.StoredContext> supplier = threadContext.newRestorableContext(false); try (ThreadContext.StoredContext ignore = stashWithOrigin(threadContext, PERSISTENT_TASK_ORIGIN)) { client.admin().cluster().cancelTasks(request, new ContextPreservingActionListener<>(supplier, listener)); } } catch (Exception e) { listener.onFailure(e); } }
synchronized (this) { if (queuedBlockOperations > 0) { final Supplier<StoredContext> contextSupplier = threadPool.getThreadContext().newRestorableContext(false); final ActionListener<Releasable> wrappedListener; if (executorOnDelay != null) {
/** * Executes an asynchronous persistent task action using the client. * <p> * The origin is set in the context and the listener is wrapped to ensure the proper context is restored */ private <Req extends ActionRequest, Resp extends PersistentTaskResponse, Builder extends ActionRequestBuilder<Req, Resp, Builder>> void execute(final Req request, final Action<Req, Resp, Builder> action, final ActionListener<PersistentTask<?>> listener) { try { final ThreadContext threadContext = client.threadPool().getThreadContext(); final Supplier<ThreadContext.StoredContext> supplier = threadContext.newRestorableContext(false); try (ThreadContext.StoredContext ignore = stashWithOrigin(threadContext, PERSISTENT_TASK_ORIGIN)) { client.execute(action, request, new ContextPreservingActionListener<>(supplier, ActionListener.wrap(r -> listener.onResponse(r.getTask()), listener::onFailure))); } } catch (Exception e) { listener.onFailure(e); } }
synchronized (this) { if (queuedBlockOperations > 0) { final Supplier<StoredContext> contextSupplier = threadPool.getThreadContext().newRestorableContext(false); final ActionListener<Releasable> wrappedListener; if (executorOnDelay != null) {