Java 类org.apache.lucene.util.CloseableThreadLocal 实例源码

项目:elasticsearch_my    文件:Versions.java   
@Override
public void onClose(Object key) {
    CloseableThreadLocal<PerThreadIDAndVersionLookup> ctl = lookupStates.remove(key);
    if (ctl != null) {
        ctl.close();
    }
}
项目:elasticsearch_my    文件:Versions.java   
private static PerThreadIDAndVersionLookup getLookupState(LeafReader reader) throws IOException {
    Object key = reader.getCoreCacheKey();
    CloseableThreadLocal<PerThreadIDAndVersionLookup> ctl = lookupStates.get(key);
    if (ctl == null) {
        // First time we are seeing this reader's core; make a
        // new CTL:
        ctl = new CloseableThreadLocal<>();
        CloseableThreadLocal<PerThreadIDAndVersionLookup> other = lookupStates.putIfAbsent(key, ctl);
        if (other == null) {
            // Our CTL won, we must remove it when the
            // core is closed:
            reader.addCoreClosedListener(removeLookupState);
        } else {
            // Another thread beat us to it: just use
            // their CTL:
            ctl = other;
        }
    }

    PerThreadIDAndVersionLookup lookupState = ctl.get();
    if (lookupState == null) {
        lookupState = new PerThreadIDAndVersionLookup(reader);
        ctl.set(lookupState);
    }

    return lookupState;
}
项目:Elasticsearch    文件:PercolatorService.java   
@Inject
public PercolatorService(Settings settings, IndexNameExpressionResolver indexNameExpressionResolver, IndicesService indicesService,
                         PageCacheRecycler pageCacheRecycler, BigArrays bigArrays,
                         HighlightPhase highlightPhase, ClusterService clusterService,
                         AggregationPhase aggregationPhase, ScriptService scriptService,
                         MappingUpdatedAction mappingUpdatedAction) {
    super(settings);
    this.indexNameExpressionResolver = indexNameExpressionResolver;
    this.parseFieldMatcher = new ParseFieldMatcher(settings);
    this.indicesService = indicesService;
    this.pageCacheRecycler = pageCacheRecycler;
    this.bigArrays = bigArrays;
    this.clusterService = clusterService;
    this.highlightPhase = highlightPhase;
    this.aggregationPhase = aggregationPhase;
    this.scriptService = scriptService;
    this.mappingUpdatedAction = mappingUpdatedAction;
    this.sortParseElement = new SortParseElement();

    final long maxReuseBytes = settings.getAsBytesSize("indices.memory.memory_index.size_per_thread", new ByteSizeValue(1, ByteSizeUnit.MB)).bytes();
    cache = new CloseableThreadLocal<MemoryIndex>() {
        @Override
        protected MemoryIndex initialValue() {
            // TODO: should we expose payloads as an option? should offsets be turned on always?
            return new ExtendedMemoryIndex(true, false, maxReuseBytes);
        }
    };
    single = new SingleDocumentPercolatorIndex(cache);
    multi = new MultiDocumentPercolatorIndex(cache);

    percolatorTypes = new IntObjectHashMap<>(6);
    percolatorTypes.put(countPercolator.id(), countPercolator);
    percolatorTypes.put(queryCountPercolator.id(), queryCountPercolator);
    percolatorTypes.put(matchPercolator.id(), matchPercolator);
    percolatorTypes.put(queryPercolator.id(), queryPercolator);
    percolatorTypes.put(scoringPercolator.id(), scoringPercolator);
    percolatorTypes.put(topMatchingPercolator.id(), topMatchingPercolator);
}
项目:Elasticsearch    文件:Versions.java   
@Override
public void onClose(Object key) {
    CloseableThreadLocal<PerThreadIDAndVersionLookup> ctl = lookupStates.remove(key);
    if (ctl != null) {
        ctl.close();
    }
}
项目:Elasticsearch    文件:Versions.java   
private static PerThreadIDAndVersionLookup getLookupState(LeafReader reader) throws IOException {
    Object key = reader.getCoreCacheKey();
    CloseableThreadLocal<PerThreadIDAndVersionLookup> ctl = lookupStates.get(key);
    if (ctl == null) {
        // First time we are seeing this reader's core; make a
        // new CTL:
        ctl = new CloseableThreadLocal<>();
        CloseableThreadLocal<PerThreadIDAndVersionLookup> other = lookupStates.putIfAbsent(key, ctl);
        if (other == null) {
            // Our CTL won, we must remove it when the
            // core is closed:
            reader.addCoreClosedListener(removeLookupState);
        } else {
            // Another thread beat us to it: just use
            // their CTL:
            ctl = other;
        }
    }

    PerThreadIDAndVersionLookup lookupState = ctl.get();
    if (lookupState == null) {
        lookupState = new PerThreadIDAndVersionLookup(reader);
        ctl.set(lookupState);
    }

    return lookupState;
}
项目:Elasticsearch    文件:MultiDocumentPercolatorIndex.java   
MultiDocumentPercolatorIndex(CloseableThreadLocal<MemoryIndex> cache) {
    this.cache = cache;
}
项目:Elasticsearch    文件:SingleDocumentPercolatorIndex.java   
SingleDocumentPercolatorIndex(CloseableThreadLocal<MemoryIndex> cache) {
    this.cache = cache;
}