本文整理汇总了Java中org.elasticsearch.common.util.concurrent.ThreadContext.StoredContext方法的典型用法代码示例。如果您正苦于以下问题:Java ThreadContext.StoredContext方法的具体用法?Java ThreadContext.StoredContext怎么用?Java ThreadContext.StoredContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.elasticsearch.common.util.concurrent.ThreadContext
的用法示例。
在下文中一共展示了ThreadContext.StoredContext方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: filterWithHeader
import org.elasticsearch.common.util.concurrent.ThreadContext; //导入方法依赖的package包/类
@Override
public Client filterWithHeader(Map<String, String> headers) {
return new FilterClient(this) {
@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) {
ThreadContext threadContext = threadPool().getThreadContext();
try (ThreadContext.StoredContext ctx = threadContext.stashAndMergeHeaders(headers)) {
super.doExecute(action, request, listener);
}
}
};
}
示例2: testOriginalContextIsPreservedAfterOnResponse
import org.elasticsearch.common.util.concurrent.ThreadContext; //导入方法依赖的package包/类
public void testOriginalContextIsPreservedAfterOnResponse() throws IOException {
try (ThreadContext threadContext = new ThreadContext(Settings.EMPTY)) {
final boolean nonEmptyContext = randomBoolean();
if (nonEmptyContext) {
threadContext.putHeader("not empty", "value");
}
ContextPreservingActionListener<Void> actionListener;
try (ThreadContext.StoredContext ignore = threadContext.stashContext()) {
threadContext.putHeader("foo", "bar");
actionListener = new ContextPreservingActionListener<>(threadContext.newRestorableContext(true),
new ActionListener<Void>() {
@Override
public void onResponse(Void aVoid) {
assertEquals("bar", threadContext.getHeader("foo"));
assertNull(threadContext.getHeader("not empty"));
}
@Override
public void onFailure(Exception e) {
throw new RuntimeException("onFailure shouldn't be called", e);
}
});
}
assertNull(threadContext.getHeader("foo"));
assertEquals(nonEmptyContext ? "value" : null, threadContext.getHeader("not empty"));
actionListener.onResponse(null);
assertNull(threadContext.getHeader("foo"));
assertEquals(nonEmptyContext ? "value" : null, threadContext.getHeader("not empty"));
}
}
示例3: testOriginalContextIsPreservedAfterOnFailure
import org.elasticsearch.common.util.concurrent.ThreadContext; //导入方法依赖的package包/类
public void testOriginalContextIsPreservedAfterOnFailure() throws Exception {
try (ThreadContext threadContext = new ThreadContext(Settings.EMPTY)) {
final boolean nonEmptyContext = randomBoolean();
if (nonEmptyContext) {
threadContext.putHeader("not empty", "value");
}
ContextPreservingActionListener<Void> actionListener;
try (ThreadContext.StoredContext ignore = threadContext.stashContext()) {
threadContext.putHeader("foo", "bar");
actionListener = new ContextPreservingActionListener<>(threadContext.newRestorableContext(true),
new ActionListener<Void>() {
@Override
public void onResponse(Void aVoid) {
throw new RuntimeException("onResponse shouldn't be called");
}
@Override
public void onFailure(Exception e) {
assertEquals("bar", threadContext.getHeader("foo"));
assertNull(threadContext.getHeader("not empty"));
}
});
}
assertNull(threadContext.getHeader("foo"));
assertEquals(nonEmptyContext ? "value" : null, threadContext.getHeader("not empty"));
actionListener.onFailure(null);
assertNull(threadContext.getHeader("foo"));
assertEquals(nonEmptyContext ? "value" : null, threadContext.getHeader("not empty"));
}
}
示例4: sendRequestDecorate
import org.elasticsearch.common.util.concurrent.ThreadContext; //导入方法依赖的package包/类
public <T extends TransportResponse> void sendRequestDecorate(AsyncSender sender, Connection connection, String action,
TransportRequest request, TransportRequestOptions options, TransportResponseHandler<T> handler) {
final Map<String, String> origHeaders0 = getThreadContext().getHeaders();
final User user0 = getThreadContext().getTransient(ConfigConstants.SG_USER);
final String origin0 = getThreadContext().getTransient(ConfigConstants.SG_ORIGIN);
final Object remoteAdress0 = getThreadContext().getTransient(ConfigConstants.SG_REMOTE_ADDRESS);
try (ThreadContext.StoredContext stashedContext = getThreadContext().stashContext()) {
final RestoringTransportResponseHandler<T> restoringHandler = new RestoringTransportResponseHandler<T>(handler, stashedContext);
getThreadContext().putHeader("_sg_remotecn", cs.getClusterName().value());
if(this.settings.get("tribe.name", null) == null
&& settings.getByPrefix("tribe").size() > 0) {
getThreadContext().putHeader("_sg_header_tn", "true");
}
getThreadContext().putHeader(
Maps.filterKeys(origHeaders0, k->k!=null && (
k.equals(ConfigConstants.SG_CONF_REQUEST_HEADER)
|| k.equals(ConfigConstants.SG_ORIGIN_HEADER)
|| k.equals(ConfigConstants.SG_REMOTE_ADDRESS_HEADER)
|| k.equals(ConfigConstants.SG_USER_HEADER)
|| k.equals(ConfigConstants.SG_DLS_QUERY_HEADER)
|| k.equals(ConfigConstants.SG_FLS_FIELDS_HEADER)
|| k.startsWith("_sg_trace")
)));
ensureCorrectHeaders(remoteAdress0, user0, origin0);
if(actionTrace.isTraceEnabled()) {
getThreadContext().putHeader("_sg_trace"+System.currentTimeMillis()+"#"+UUID.randomUUID().toString(), Thread.currentThread().getName()+" IC -> "+action+" "+getThreadContext().getHeaders().entrySet().stream().filter(p->!p.getKey().startsWith("_sg_trace")).collect(Collectors.toMap(p -> p.getKey(), p -> p.getValue())));
}
sender.sendRequest(connection, action, request, options, restoringHandler);
}
}
示例5: dispatchRequest
import org.elasticsearch.common.util.concurrent.ThreadContext; //导入方法依赖的package包/类
void dispatchRequest(final RestRequest request, final RestChannel channel) {
final ThreadContext threadContext = threadPool.getThreadContext();
try (ThreadContext.StoredContext ignore = threadContext.stashContext()) {
dispatcher.dispatchRequest(request, channel, threadContext);
}
}
示例6: dispatchBadRequest
import org.elasticsearch.common.util.concurrent.ThreadContext; //导入方法依赖的package包/类
void dispatchBadRequest(final RestRequest request, final RestChannel channel, final Throwable cause) {
final ThreadContext threadContext = threadPool.getThreadContext();
try (ThreadContext.StoredContext ignore = threadContext.stashContext()) {
dispatcher.dispatchBadRequest(request, channel, threadContext, cause);
}
}
示例7: ContextRestoreResponseHandler
import org.elasticsearch.common.util.concurrent.ThreadContext; //导入方法依赖的package包/类
public ContextRestoreResponseHandler(Supplier<ThreadContext.StoredContext> contextSupplier, TransportResponseHandler<T> delegate) {
this.delegate = delegate;
this.contextSupplier = contextSupplier;
}
示例8: handleResponse
import org.elasticsearch.common.util.concurrent.ThreadContext; //导入方法依赖的package包/类
@Override
public void handleResponse(T response) {
try (ThreadContext.StoredContext ignore = contextSupplier.get()) {
delegate.handleResponse(response);
}
}
示例9: handleException
import org.elasticsearch.common.util.concurrent.ThreadContext; //导入方法依赖的package包/类
@Override
public void handleException(TransportException exp) {
try (ThreadContext.StoredContext ignore = contextSupplier.get()) {
delegate.handleException(exp);
}
}
示例10: ContextPreservingListener
import org.elasticsearch.common.util.concurrent.ThreadContext; //导入方法依赖的package包/类
private ContextPreservingListener(Listener delegate, Supplier<ThreadContext.StoredContext> contextSupplier) {
this.contextSupplier = contextSupplier;
this.delegate = delegate;
}
示例11: onNewClusterState
import org.elasticsearch.common.util.concurrent.ThreadContext; //导入方法依赖的package包/类
@Override
public void onNewClusterState(ClusterState state) {
try (ThreadContext.StoredContext context = contextSupplier.get()) {
delegate.onNewClusterState(state);
}
}
示例12: onClusterServiceClose
import org.elasticsearch.common.util.concurrent.ThreadContext; //导入方法依赖的package包/类
@Override
public void onClusterServiceClose() {
try (ThreadContext.StoredContext context = contextSupplier.get()) {
delegate.onClusterServiceClose();
}
}
示例13: onTimeout
import org.elasticsearch.common.util.concurrent.ThreadContext; //导入方法依赖的package包/类
@Override
public void onTimeout(TimeValue timeout) {
try (ThreadContext.StoredContext context = contextSupplier.get()) {
delegate.onTimeout(timeout);
}
}
示例14: ContextPreservingActionListener
import org.elasticsearch.common.util.concurrent.ThreadContext; //导入方法依赖的package包/类
public ContextPreservingActionListener(Supplier<ThreadContext.StoredContext> contextSupplier, ActionListener<R> delegate) {
this.delegate = delegate;
this.context = contextSupplier;
}
示例15: onResponse
import org.elasticsearch.common.util.concurrent.ThreadContext; //导入方法依赖的package包/类
@Override
public void onResponse(R r) {
try (ThreadContext.StoredContext ignore = context.get()) {
delegate.onResponse(r);
}
}