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


Java ThreadContext.putHeader方法代码示例

本文整理汇总了Java中org.elasticsearch.common.util.concurrent.ThreadContext.putHeader方法的典型用法代码示例。如果您正苦于以下问题:Java ThreadContext.putHeader方法的具体用法?Java ThreadContext.putHeader怎么用?Java ThreadContext.putHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.elasticsearch.common.util.concurrent.ThreadContext的用法示例。


在下文中一共展示了ThreadContext.putHeader方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createOrGetTrial

import org.elasticsearch.common.util.concurrent.ThreadContext; //导入方法依赖的package包/类
private SearchGuardLicense createOrGetTrial(String msg) {
    long created = System.currentTimeMillis();
    ThreadContext threadContext = threadPool.getThreadContext();
    
    try(StoredContext ctx = threadContext.stashContext()) {
        threadContext.putHeader(ConfigConstants.SG_CONF_REQUEST_HEADER, "true");
        GetResponse get = client.prepareGet(searchguardIndex, "sg", "tattr").get();
        if(get.isExists()) {
            created = (long) get.getSource().get("val");
        } else {
            client.index(new IndexRequest(searchguardIndex)
            .type("sg")
            .id("tattr")
            .setRefreshPolicy(RefreshPolicy.IMMEDIATE)
            .source("{\"val\": "+System.currentTimeMillis()+"}", XContentType.JSON)).actionGet();
        }
    }
    
    return SearchGuardLicense.createTrialLicense(formatDate(created), clusterService, msg);
}
 
开发者ID:floragunncom,项目名称:search-guard,代码行数:21,代码来源:IndexBaseConfigurationRepository.java

示例2: dispatchRequest

import org.elasticsearch.common.util.concurrent.ThreadContext; //导入方法依赖的package包/类
void dispatchRequest(final RestRequest request, final RestChannel channel, final NodeClient client, ThreadContext threadContext,
                     final RestHandler handler) throws Exception {
    if (checkRequestParameters(request, channel) == false) {
        channel.sendResponse(BytesRestResponse.createSimpleErrorResponse(BAD_REQUEST, "error traces in responses are disabled."));
    } else {
        for (String key : headersToCopy) {
            String httpHeader = request.header(key);
            if (httpHeader != null) {
                threadContext.putHeader(key, httpHeader);
            }
        }

        if (handler == null) {
            if (request.method() == RestRequest.Method.OPTIONS) {
                // when we have OPTIONS request, simply send OK by default (with the Access Control Origin header which gets automatically added)

                channel.sendResponse(new BytesRestResponse(OK, BytesRestResponse.TEXT_CONTENT_TYPE, BytesArray.EMPTY));
            } else {
                final String msg = "No handler found for uri [" + request.uri() + "] and method [" + request.method() + "]";
                channel.sendResponse(new BytesRestResponse(BAD_REQUEST, msg));
            }
        } else {
            final RestHandler wrappedHandler = Objects.requireNonNull(handlerWrapper.apply(handler));
            wrappedHandler.handleRequest(request, channel, client);
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:28,代码来源:RestController.java

示例3: loadConfigurations

import org.elasticsearch.common.util.concurrent.ThreadContext; //导入方法依赖的package包/类
private Map<String, Settings> loadConfigurations(Collection<String> configTypes) {
        
        final ThreadContext threadContext = threadPool.getThreadContext();
        final Map<String, Settings> retVal = new HashMap<String, Settings>();
        //final List<Exception> exception = new ArrayList<Exception>(1);
       // final CountDownLatch latch = new CountDownLatch(1);
        
        try(StoredContext ctx = threadContext.stashContext()) {
            threadContext.putHeader(ConfigConstants.SG_CONF_REQUEST_HEADER, "true");
            
            boolean searchGuardIndexExists = clusterService.state().metaData().hasConcreteIndex(this.searchguardIndex);
            
            if(searchGuardIndexExists) {
                if(clusterService.state().metaData().index(this.searchguardIndex).mapping("config") != null) {
                    //legacy layout
                    LOGGER.debug("sg index exists and was created before ES 6 (legacy layout)");
                    retVal.putAll(validate(legacycl.loadLegacy(configTypes.toArray(new String[0]), 5, TimeUnit.SECONDS), configTypes.size()));
                } else {
                    LOGGER.debug("sg index exists and was created with ES 6 (new layout)");
                    retVal.putAll(validate(cl.load(configTypes.toArray(new String[0]), 5, TimeUnit.SECONDS), configTypes.size()));
                }
            } else {
                //wait (and use new layout)
                LOGGER.debug("sg index not exists (yet)");
                retVal.putAll(validate(cl.load(configTypes.toArray(new String[0]), 30, TimeUnit.SECONDS), configTypes.size()));
            }
            
        } catch (Exception e) {
            throw new ElasticsearchException(e);
        }
        return retVal;
}
 
开发者ID:floragunncom,项目名称:search-guard,代码行数:33,代码来源:IndexBaseConfigurationRepository.java


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