本文整理汇总了Java中org.elasticsearch.common.cache.CacheBuilder类的典型用法代码示例。如果您正苦于以下问题:Java CacheBuilder类的具体用法?Java CacheBuilder怎么用?Java CacheBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CacheBuilder类属于org.elasticsearch.common.cache包,在下文中一共展示了CacheBuilder类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: Factory
import org.elasticsearch.common.cache.CacheBuilder; //导入依赖的package包/类
/**
* This constructor will be called by guice during initialization
*
* @param node injecting the reference to current node to get access to node's client
*/
@SuppressWarnings("unchecked")
@Inject
public Factory(Node node, Settings settings) {
super(settings);
// Node is not fully initialized here
// All we can do is save a reference to it for future use
this.node = node;
// Setup lookup cache
ByteSizeValue size = settings.getAsBytesSize("nativescript.joiner.size", null);
TimeValue expire = settings.getAsTime("expire", new TimeValue(2000));
CacheBuilder cacheBuilder = CacheBuilder.newBuilder();
if (size != null) {
cacheBuilder.maximumSize(size.bytes());
}
if (expire != null) {
cacheBuilder.expireAfterAccess(expire.nanos(), TimeUnit.SECONDS);
}
cache = cacheBuilder.build();
}
开发者ID:sutoiku,项目名称:elasticsearch-native-script-joiner,代码行数:26,代码来源:JoinerScript.java
示例2: buildCache
import org.elasticsearch.common.cache.CacheBuilder; //导入依赖的package包/类
private void buildCache() {
final long sizeInBytes = MemorySizeValue
.parseBytesSizeValueOrHeapRatio(size).bytes();
final CacheBuilder<Key, BytesReference> cacheBuilder = CacheBuilder
.newBuilder().maximumWeight(sizeInBytes)
.weigher(new QueryCacheWeigher()).removalListener(this);
cacheBuilder.concurrencyLevel(16);
if (expire != null) {
cacheBuilder.expireAfterAccess(expire.millis(),
TimeUnit.MILLISECONDS);
}
cache = cacheBuilder.build();
}
开发者ID:codelibs,项目名称:elasticsearch-qrcache,代码行数:18,代码来源:QueryResultCache.java
示例3: IndicesFieldDataCache
import org.elasticsearch.common.cache.CacheBuilder; //导入依赖的package包/类
public IndicesFieldDataCache(Settings settings, IndexFieldDataCache.Listener indicesFieldDataCacheListener) {
super(settings);
this.indicesFieldDataCacheListener = indicesFieldDataCacheListener;
final long sizeInBytes = INDICES_FIELDDATA_CACHE_SIZE_KEY.get(settings).getBytes();
CacheBuilder<Key, Accountable> cacheBuilder = CacheBuilder.<Key, Accountable>builder()
.removalListener(this);
if (sizeInBytes > 0) {
cacheBuilder.setMaximumWeight(sizeInBytes).weigher(new FieldDataWeigher());
}
cache = cacheBuilder.build();
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:12,代码来源:IndicesFieldDataCache.java
示例4: IndicesRequestCache
import org.elasticsearch.common.cache.CacheBuilder; //导入依赖的package包/类
IndicesRequestCache(Settings settings) {
super(settings);
this.size = INDICES_CACHE_QUERY_SIZE.get(settings);
this.expire = INDICES_CACHE_QUERY_EXPIRE.exists(settings) ? INDICES_CACHE_QUERY_EXPIRE.get(settings) : null;
long sizeInBytes = size.getBytes();
CacheBuilder<Key, BytesReference> cacheBuilder = CacheBuilder.<Key, BytesReference>builder()
.setMaximumWeight(sizeInBytes).weigher((k, v) -> k.ramBytesUsed() + v.ramBytesUsed()).removalListener(this);
if (expire != null) {
cacheBuilder.setExpireAfterAccess(expire);
}
cache = cacheBuilder.build();
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:13,代码来源:IndicesRequestCache.java
示例5: BitsetFilterCache
import org.elasticsearch.common.cache.CacheBuilder; //导入依赖的package包/类
public BitsetFilterCache(IndexSettings indexSettings, Listener listener) {
super(indexSettings);
if (listener == null) {
throw new IllegalArgumentException("listener must not be null");
}
this.loadRandomAccessFiltersEagerly = this.indexSettings.getValue(INDEX_LOAD_RANDOM_ACCESS_FILTERS_EAGERLY_SETTING);
this.loadedFilters = CacheBuilder.<Object, Cache<Query, Value>>builder().removalListener(this).build();
this.listener = listener;
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:10,代码来源:BitsetFilterCache.java
示例6: getAndLoadIfNotPresent
import org.elasticsearch.common.cache.CacheBuilder; //导入依赖的package包/类
private BitSet getAndLoadIfNotPresent(final Query query, final LeafReaderContext context) throws IOException, ExecutionException {
final Object coreCacheReader = context.reader().getCoreCacheKey();
final ShardId shardId = ShardUtils.extractShardId(context.reader());
if (shardId != null // can't require it because of the percolator
&& indexSettings.getIndex().equals(shardId.getIndex()) == false) {
// insanity
throw new IllegalStateException("Trying to load bit set for index " + shardId.getIndex()
+ " with cache of index " + indexSettings.getIndex());
}
Cache<Query, Value> filterToFbs = loadedFilters.computeIfAbsent(coreCacheReader, key -> {
context.reader().addCoreClosedListener(BitsetFilterCache.this);
return CacheBuilder.<Query, Value>builder().build();
});
return filterToFbs.computeIfAbsent(query, key -> {
final IndexReaderContext topLevelContext = ReaderUtil.getTopLevelContext(context);
final IndexSearcher searcher = new IndexSearcher(topLevelContext);
searcher.setQueryCache(null);
final Weight weight = searcher.createNormalizedWeight(query, false);
Scorer s = weight.scorer(context);
final BitSet bitSet;
if (s == null) {
bitSet = null;
} else {
bitSet = BitSet.of(s.iterator(), context.reader().maxDoc());
}
Value value = new Value(bitSet, shardId);
listener.onCache(shardId, value.bitset);
return value;
}).bitset;
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:33,代码来源:BitsetFilterCache.java
示例7: Caches
import org.elasticsearch.common.cache.CacheBuilder; //导入依赖的package包/类
public Caches(TimeValue expAfterWrite, TimeValue expAfterAccess, ByteSizeValue maxWeight) {
this.featureCache = configCache(CacheBuilder.<CacheKey, Feature>builder(), expAfterWrite, expAfterAccess, maxWeight)
.weigher(Caches::weigther)
.removalListener((l) -> this.onRemove(l.getKey(), l.getValue()))
.build();
this.featureSetCache = configCache(CacheBuilder.<CacheKey, FeatureSet>builder(), expAfterWrite, expAfterAccess, maxWeight)
.weigher(Caches::weigther)
.removalListener((l) -> this.onRemove(l.getKey(), l.getValue()))
.build();
this.modelCache = configCache(CacheBuilder.<CacheKey, CompiledLtrModel>builder(), expAfterWrite, expAfterAccess, maxWeight)
.weigher((s, w) -> w.ramBytesUsed())
.removalListener((l) -> this.onRemove(l.getKey(), l.getValue()))
.build();
this.maxWeight = maxWeight.getBytes();
}
开发者ID:o19s,项目名称:elasticsearch-learning-to-rank,代码行数:16,代码来源:Caches.java
示例8: configCache
import org.elasticsearch.common.cache.CacheBuilder; //导入依赖的package包/类
private <K, V> CacheBuilder<K, V> configCache(CacheBuilder<K, V> builder, TimeValue expireAfterWrite,
TimeValue expireAfterAccess, ByteSizeValue maxWeight) {
if (expireAfterWrite.nanos() > 0) {
builder.setExpireAfterWrite(expireAfterWrite);
}
if (expireAfterAccess.nanos() > 0) {
builder.setExpireAfterAccess(expireAfterAccess);
}
builder.setMaximumWeight(maxWeight.getBytes());
return builder;
}
开发者ID:o19s,项目名称:elasticsearch-learning-to-rank,代码行数:12,代码来源:Caches.java
示例9: ScriptService
import org.elasticsearch.common.cache.CacheBuilder; //导入依赖的package包/类
public ScriptService(Settings settings, Environment env,
ResourceWatcherService resourceWatcherService, ScriptEngineRegistry scriptEngineRegistry,
ScriptContextRegistry scriptContextRegistry, ScriptSettings scriptSettings) throws IOException {
super(settings);
Objects.requireNonNull(scriptEngineRegistry);
Objects.requireNonNull(scriptContextRegistry);
Objects.requireNonNull(scriptSettings);
if (Strings.hasLength(settings.get(DISABLE_DYNAMIC_SCRIPTING_SETTING))) {
throw new IllegalArgumentException(DISABLE_DYNAMIC_SCRIPTING_SETTING + " is not a supported setting, replace with fine-grained script settings. \n" +
"Dynamic scripts can be enabled for all languages and all operations by replacing `script.disable_dynamic: false` with `script.inline: true` and `script.stored: true` in elasticsearch.yml");
}
this.scriptEngines = scriptEngineRegistry.getRegisteredLanguages().values();
this.scriptContextRegistry = scriptContextRegistry;
int cacheMaxSize = SCRIPT_CACHE_SIZE_SETTING.get(settings);
CacheBuilder<CacheKey, CompiledScript> cacheBuilder = CacheBuilder.builder();
if (cacheMaxSize >= 0) {
cacheBuilder.setMaximumWeight(cacheMaxSize);
}
TimeValue cacheExpire = SCRIPT_CACHE_EXPIRE_SETTING.get(settings);
if (cacheExpire.getNanos() != 0) {
cacheBuilder.setExpireAfterAccess(cacheExpire);
}
logger.debug("using script cache with max_size [{}], expire [{}]", cacheMaxSize, cacheExpire);
this.cache = cacheBuilder.removalListener(new ScriptCacheRemovalListener()).build();
Map<String, ScriptEngineService> enginesByLangBuilder = new HashMap<>();
Map<String, ScriptEngineService> enginesByExtBuilder = new HashMap<>();
for (ScriptEngineService scriptEngine : scriptEngines) {
String language = scriptEngineRegistry.getLanguage(scriptEngine.getClass());
enginesByLangBuilder.put(language, scriptEngine);
enginesByExtBuilder.put(scriptEngine.getExtension(), scriptEngine);
}
this.scriptEnginesByLang = unmodifiableMap(enginesByLangBuilder);
this.scriptEnginesByExt = unmodifiableMap(enginesByExtBuilder);
this.scriptModes = new ScriptModes(scriptSettings, settings);
// add file watcher for static scripts
scriptsDirectory = env.scriptsFile();
if (logger.isTraceEnabled()) {
logger.trace("Using scripts directory [{}] ", scriptsDirectory);
}
FileWatcher fileWatcher = new FileWatcher(scriptsDirectory);
fileWatcher.addListener(new ScriptChangesListener());
if (SCRIPT_AUTO_RELOAD_ENABLED_SETTING.get(settings)) {
// automatic reload is enabled - register scripts
resourceWatcherService.add(fileWatcher);
} else {
// automatic reload is disable just load scripts once
fileWatcher.init();
}
this.lastInlineCompileTime = System.nanoTime();
this.setMaxCompilationsPerMinute(SCRIPT_MAX_COMPILATIONS_PER_MINUTE.get(settings));
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:61,代码来源:ScriptService.java
示例10: GeoIpCache
import org.elasticsearch.common.cache.CacheBuilder; //导入依赖的package包/类
GeoIpCache(long maxSize) {
this.cache = CacheBuilder.<Integer, JsonNode>builder().setMaximumWeight(maxSize).build();
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:4,代码来源:GeoIpCache.java
示例11: UserAgentCache
import org.elasticsearch.common.cache.CacheBuilder; //导入依赖的package包/类
UserAgentCache(long cacheSize) {
cache = CacheBuilder.<CompositeCacheKey, Details>builder().setMaximumWeight(cacheSize).build();
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:4,代码来源:UserAgentCache.java
注:本文中的org.elasticsearch.common.cache.CacheBuilder类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论