本文整理汇总了Java中com.googlecode.concurrentlinkedhashmap.EvictionListener类的典型用法代码示例。如果您正苦于以下问题:Java EvictionListener类的具体用法?Java EvictionListener怎么用?Java EvictionListener使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
EvictionListener类属于com.googlecode.concurrentlinkedhashmap包,在下文中一共展示了EvictionListener类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: SerializingCache
import com.googlecode.concurrentlinkedhashmap.EvictionListener; //导入依赖的package包/类
private SerializingCache(long capacity, Weigher<RefCountedMemory> weigher, ISerializer<V> serializer)
{
this.serializer = serializer;
EvictionListener<K,RefCountedMemory> listener = new EvictionListener<K, RefCountedMemory>()
{
public void onEviction(K k, RefCountedMemory mem)
{
mem.unreference();
}
};
this.map = new ConcurrentLinkedHashMap.Builder<K, RefCountedMemory>()
.weigher(weigher)
.maximumWeightedCapacity(capacity)
.concurrencyLevel(DEFAULT_CONCURENCY_LEVEL)
.listener(listener)
.build();
}
示例2: init
import com.googlecode.concurrentlinkedhashmap.EvictionListener; //导入依赖的package包/类
/**
* 初始化
* @param name
* @param entityCacheSize
* @param concurrencyLevel
*/
public void init(String name, int entityCacheSize, int concurrencyLevel) {
this.name = name;
this.evictions = new ConcurrentReferenceHashMap<Object, Object>(ReferenceType.STRONG, ReferenceType.WEAK);
this.store = new ConcurrentLinkedHashMap.Builder<Object, ValueWrapper>()
.maximumWeightedCapacity(entityCacheSize > 0 ? entityCacheSize : DEFAULT_MAX_CAPACITY_OF_ENTITY_CACHE)
.concurrencyLevel(concurrencyLevel).listener(new EvictionListener<Object, ValueWrapper>() {
@Override
public void onEviction(Object key, ValueWrapper value) {
if (value.get() != null) {
evictions.put(key, value.get());
}
}
}).build();
}
示例3: DeepPagingCache
import com.googlecode.concurrentlinkedhashmap.EvictionListener; //导入依赖的package包/类
public DeepPagingCache(long maxEntriesForDeepPaging) {
_hits = Metrics.newMeter(new MetricName(ORG_APACHE_BLUR, DEEP_PAGING_CACHE, HIT), HIT, TimeUnit.SECONDS);
_misses = Metrics.newMeter(new MetricName(ORG_APACHE_BLUR, DEEP_PAGING_CACHE, MISS), MISS, TimeUnit.SECONDS);
_evictions = Metrics.newMeter(new MetricName(ORG_APACHE_BLUR, DEEP_PAGING_CACHE, EVICTION), EVICTION,
TimeUnit.SECONDS);
_lruCache = new ConcurrentLinkedHashMap.Builder<DeepPageKeyPlusPosition, DeepPageContainer>()
.maximumWeightedCapacity(maxEntriesForDeepPaging)
.listener(new EvictionListener<DeepPageKeyPlusPosition, DeepPageContainer>() {
@Override
public void onEviction(DeepPageKeyPlusPosition key, DeepPageContainer value) {
_positionCache.remove(key);
_evictions.mark();
}
}).build();
Metrics.newGauge(new MetricName(ORG_APACHE_BLUR, DEEP_PAGING_CACHE, SIZE), new Gauge<Long>() {
@Override
public Long value() {
return _lruCache.weightedSize();
}
});
_positionCache = new ConcurrentSkipListMap<DeepPageKeyPlusPosition, DeepPageContainer>();
}
示例4: SerializingCache
import com.googlecode.concurrentlinkedhashmap.EvictionListener; //导入依赖的package包/类
public SerializingCache(int capacity, ICompactSerializer3<V> serializer, String tableName, String cfName)
{
this.serializer = serializer;
EvictionListener<K,FreeableMemory> listener = new EvictionListener<K, FreeableMemory>()
{
public void onEviction(K k, FreeableMemory mem)
{
mem.unreference();
}
};
this.map = new ConcurrentLinkedHashMap.Builder<K, FreeableMemory>()
.weigher(Weighers.<FreeableMemory>singleton())
.initialCapacity(capacity)
.maximumWeightedCapacity(capacity)
.concurrencyLevel(DEFAULT_CONCURENCY_LEVEL)
.listener(listener)
.build();
}
示例5: MessagesRegistry
import com.googlecode.concurrentlinkedhashmap.EvictionListener; //导入依赖的package包/类
public MessagesRegistry(int initialCapacity, int maxCapacity, int concurrencyLevel, @Nullable EvictionListener<Sha256Hash, Entry<T>> evictionListener) {
final ConcurrentLinkedHashMap.Builder<Sha256Hash, Entry<T>> builder = new ConcurrentLinkedHashMap.Builder<Sha256Hash, Entry<T>>()
.concurrencyLevel(concurrencyLevel)
.initialCapacity(initialCapacity)
.maximumWeightedCapacity(maxCapacity)
.weigher(Weighers.entrySingleton());
if (evictionListener != null) {
builder.listener(evictionListener);
}
cache = builder.build();
}
示例6: BlockCache
import com.googlecode.concurrentlinkedhashmap.EvictionListener; //导入依赖的package包/类
public BlockCache(Metrics metrics, boolean directAllocation,
long totalMemory, int slabSize, int blockSize) {
this.metrics = metrics;
numberOfBlocksPerBank = slabSize / blockSize;
int numberOfBanks = (int) (totalMemory / slabSize);
banks = new ByteBuffer[numberOfBanks];
locks = new BlockLocks[numberOfBanks];
lockCounters = new AtomicInteger[numberOfBanks];
maxEntries = (numberOfBlocksPerBank * numberOfBanks) - 1;
for (int i = 0; i < numberOfBanks; i++) {
if (directAllocation) {
banks[i] = ByteBuffer.allocateDirect(numberOfBlocksPerBank * blockSize);
} else {
banks[i] = ByteBuffer.allocate(numberOfBlocksPerBank * blockSize);
}
locks[i] = new BlockLocks(numberOfBlocksPerBank);
lockCounters[i] = new AtomicInteger();
}
EvictionListener<BlockCacheKey,BlockCacheLocation> listener = new EvictionListener<BlockCacheKey,BlockCacheLocation>() {
@Override
public void onEviction(BlockCacheKey key, BlockCacheLocation location) {
releaseLocation(location);
}
};
cache = new ConcurrentLinkedHashMap.Builder<BlockCacheKey,BlockCacheLocation>()
.maximumWeightedCapacity(maxEntries).listener(listener).build();
this.blockSize = blockSize;
}
示例7: GoogleConcurrentLruCache
import com.googlecode.concurrentlinkedhashmap.EvictionListener; //导入依赖的package包/类
public GoogleConcurrentLruCache(int capacity, EvictionListener<K, V> listener){
if (capacity <= 0) {
capacity = DEFAULT_CAPACITY;
}
cache = new ConcurrentLinkedHashMap.Builder<K, V>().maximumWeightedCapacity(capacity)
.weigher(Weighers.singleton())
.concurrencyLevel(DEFAULT_CONCURENCY_LEVEL)
.listener(listener)
.build();
}
示例8: testSimple
import com.googlecode.concurrentlinkedhashmap.EvictionListener; //导入依赖的package包/类
@Test
public void testSimple() {
GoogleConcurrentLruCache cache = new GoogleConcurrentLruCache(10, new EvictionListener<String, String>() {
public void onEviction(String key, String value) {
System.out.println("evict key:" + key + " values:" + value);
}
});
for (int i = 0; i < 11; i++) {
cache.put("key" + i, "value" + i);
}
}
示例9: getListener
import com.googlecode.concurrentlinkedhashmap.EvictionListener; //导入依赖的package包/类
/**
* Creates and returns a new EvictionListener for the CLHM. It is worth noting that this
* EvictionListener is called in the context of the thread that has executed an insert (putIfAbsent)
* operation which has increased the CLHM size above its maxSize - in which case the CLHM
* evicts its LRU entry.
*
* @return a new EvictionListener for the CLHM
*/
private static EvictionListener<StatementMethod, StatementHolder> getListener() {
return new EvictionListener<StatementMethod, StatementHolder>() {
@Override
public void onEviction(StatementMethod statementMethod, StatementHolder statementHolder) {
if (statementHolder.state().getAndSet(EVICTED) == AVAILABLE)
quietClose(statementHolder.rawStatement());
if (logger.isTraceEnabled())
logger.trace("Evicted {}", statementHolder.rawStatement());
}
};
}
示例10: TableBlockCache
import com.googlecode.concurrentlinkedhashmap.EvictionListener; //导入依赖的package包/类
public TableBlockCache(long maxSize, Weigher<T> weigher) {
cache = new ConcurrentLinkedHashMap.Builder<Entry, T>().concurrencyLevel(CONCURRENCY_LEVEL).weigher(weigher)
.listener(new EvictionListener<Entry, T>() {
@Override
public void onEviction(Entry key, T value) {
totalSize.addAndGet(-(value.memory().size()));
value.memory().release();
}
}).maximumWeightedCapacity(maxSize).build();
this.maxSize = maxSize;
}
示例11: BlockCache
import com.googlecode.concurrentlinkedhashmap.EvictionListener; //导入依赖的package包/类
public BlockCache(boolean directAllocation, long totalMemory, int slabSize) {
_numberOfBlocksPerSlab = slabSize / _blockSize;
_numberOfSlabs = (int) (totalMemory / slabSize);
_directAllocation = directAllocation;
_slabs = new ByteBuffer[_numberOfSlabs];
_locks = new BlockLocks[_numberOfSlabs];
_lockCounters = new AtomicInteger[_numberOfSlabs];
_maxEntries = (_numberOfBlocksPerSlab * _numberOfSlabs) - 1;
for (int i = 0; i < _numberOfSlabs; i++) {
if (!lazy) {
if (_directAllocation) {
_slabs[i] = ByteBuffer.allocateDirect(_numberOfBlocksPerSlab * _blockSize);
} else {
_slabs[i] = ByteBuffer.allocate(_numberOfBlocksPerSlab * _blockSize);
}
}
_locks[i] = new BlockLocks(_numberOfBlocksPerSlab);
_lockCounters[i] = new AtomicInteger();
}
EvictionListener<BlockCacheKey, BlockCacheLocation> listener = new EvictionListener<BlockCacheKey, BlockCacheLocation>() {
@Override
public void onEviction(BlockCacheKey key, BlockCacheLocation location) {
releaseLocation(location);
}
};
_cache = new ConcurrentLinkedHashMap.Builder<BlockCacheKey, BlockCacheLocation>()
.maximumWeightedCapacity(_maxEntries).listener(listener).build();
}
示例12: BlockCache
import com.googlecode.concurrentlinkedhashmap.EvictionListener; //导入依赖的package包/类
public BlockCache(boolean directAllocation, long totalMemory, int slabSize) {
_numberOfBlocksPerSlab = slabSize / _blockSize;
_numberOfSlabs = (int) (totalMemory / slabSize);
_directAllocation = directAllocation;
_slabs = new ByteBuffer[_numberOfSlabs];
_locks = new BlockLocks[_numberOfSlabs];
_lockCounters = new AtomicInteger[_numberOfSlabs];
_maxEntries = (_numberOfBlocksPerSlab * _numberOfSlabs) - 1;
for (int i = 0; i < _numberOfSlabs; i++) {
if (!lazy) {
if (_directAllocation) {
_slabs[i] = ByteBuffer.allocateDirect(_numberOfBlocksPerSlab * _blockSize);
} else {
_slabs[i] = ByteBuffer.allocate(_numberOfBlocksPerSlab * _blockSize);
}
}
_locks[i] = new BlockLocks(_numberOfBlocksPerSlab);
_lockCounters[i] = new AtomicInteger();
}
evictions = Metrics.newMeter(new MetricName(ORG_APACHE_BLUR, CACHE, EVICTION), EVICTION, TimeUnit.SECONDS);
Metrics.newGauge(new MetricName(ORG_APACHE_BLUR, CACHE, ENTRIES), new Gauge<Long>() {
@Override
public Long value() {
return (long) getSize();
}
});
Metrics.newGauge(new MetricName(ORG_APACHE_BLUR, CACHE, SIZE), new Gauge<Long>() {
@Override
public Long value() {
return ((long) getSize()) * (long) _8K;
}
});
EvictionListener<BlockCacheKey, BlockCacheLocation> listener = new EvictionListener<BlockCacheKey, BlockCacheLocation>() {
@Override
public void onEviction(BlockCacheKey key, BlockCacheLocation location) {
releaseLocation(location);
evictions.mark();
}
};
_cache = new ConcurrentLinkedHashMap.Builder<BlockCacheKey, BlockCacheLocation>()
.maximumWeightedCapacity(_maxEntries).listener(listener).build();
}