当前位置: 首页>>代码示例>>Java>>正文


Java ThreadContext.StoredContext方法代码示例

本文整理汇总了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);
            }
        }
    };
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:13,代码来源:AbstractClient.java

示例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"));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:34,代码来源:ContextPreservingActionListenerTests.java

示例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"));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:34,代码来源:ContextPreservingActionListenerTests.java

示例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);
    }
}
 
开发者ID:floragunncom,项目名称:search-guard,代码行数:39,代码来源:SearchGuardInterceptor.java

示例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);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:7,代码来源:Netty4HttpServerTransport.java

示例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);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:7,代码来源:Netty4HttpServerTransport.java

示例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;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:5,代码来源:TransportService.java

示例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);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:7,代码来源:TransportService.java

示例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);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:7,代码来源:TransportService.java

示例10: ContextPreservingListener

import org.elasticsearch.common.util.concurrent.ThreadContext; //导入方法依赖的package包/类
private ContextPreservingListener(Listener delegate, Supplier<ThreadContext.StoredContext> contextSupplier) {
    this.contextSupplier = contextSupplier;
    this.delegate = delegate;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:5,代码来源:ClusterStateObserver.java

示例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);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:7,代码来源:ClusterStateObserver.java

示例12: onClusterServiceClose

import org.elasticsearch.common.util.concurrent.ThreadContext; //导入方法依赖的package包/类
@Override
public void onClusterServiceClose() {
    try (ThreadContext.StoredContext context  = contextSupplier.get()) {
        delegate.onClusterServiceClose();
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:7,代码来源:ClusterStateObserver.java

示例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);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:7,代码来源:ClusterStateObserver.java

示例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;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:5,代码来源:ContextPreservingActionListener.java

示例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);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:7,代码来源:ContextPreservingActionListener.java


注:本文中的org.elasticsearch.common.util.concurrent.ThreadContext.StoredContext方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。