本文整理汇总了Java中com.googlecode.concurrentlinkedhashmap.Weighers类的典型用法代码示例。如果您正苦于以下问题:Java Weighers类的具体用法?Java Weighers怎么用?Java Weighers使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Weighers类属于com.googlecode.concurrentlinkedhashmap包,在下文中一共展示了Weighers类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: SerializingCache
import com.googlecode.concurrentlinkedhashmap.Weighers; //导入依赖的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();
}
示例2: init
import com.googlecode.concurrentlinkedhashmap.Weighers; //导入依赖的package包/类
private void init() {
if (cache == null) {
synchronized (this) {
if (cache == null) {
cache = new ConcurrentLinkedHashMap.Builder<InnerQueryKey, SQLParsedState>().maximumWeightedCapacity(capacity).weigher(Weighers.singleton()).build();
}
}
}
}
示例3: PersistableCache
import com.googlecode.concurrentlinkedhashmap.Weighers; //导入依赖的package包/类
public PersistableCache(JdbcTemplate template, int size) {
dataMap = new ConcurrentLinkedHashMap.Builder<Long, Persistable>().maximumWeightedCapacity(size).weigher(Weighers.singleton())
.listener((id, data) -> {
if (data.isDirty()) {
//如果发现数据是脏的,那么重新put一次,保证及时入库
LOGGER.error("脏数据从缓存中移除了:" + id);
}
}).build();
}
示例4: MessagesRegistry
import com.googlecode.concurrentlinkedhashmap.Weighers; //导入依赖的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();
}
示例5: testSerializingCache
import com.googlecode.concurrentlinkedhashmap.Weighers; //导入依赖的package包/类
@Test
public void testSerializingCache() throws InterruptedException
{
ICache<MeasureableString, IRowCacheEntry> cache = SerializingCache.create(CAPACITY, Weighers.<RefCountedMemory>singleton(), new SerializingCacheProvider.RowCacheSerializer());
ColumnFamily cf = createCF();
simpleCase(cf, cache);
concurrentCase(cf, cache);
}
示例6: testHeapCache
import com.googlecode.concurrentlinkedhashmap.Weighers; //导入依赖的package包/类
@Test
public void testHeapCache() throws InterruptedException
{
ICache<MeasureableString, IRowCacheEntry> cache = ConcurrentLinkedHashCache.create(CAPACITY, Weighers.<MeasureableString, IRowCacheEntry>entrySingleton());
ColumnFamily cf = createCF();
simpleCase(cf, cache);
concurrentCase(cf, cache);
}
示例7: GoogleConcurrentLruCache
import com.googlecode.concurrentlinkedhashmap.Weighers; //导入依赖的package包/类
public GoogleConcurrentLruCache(int capacity){
if (capacity <= 0) {
capacity = DEFAULT_CAPACITY;
}
cache = new ConcurrentLinkedHashMap.Builder<K, V>().maximumWeightedCapacity(capacity)
.weigher(Weighers.singleton())
.concurrencyLevel(DEFAULT_CONCURENCY_LEVEL)
.build();
}
示例8: testSerializingCache
import com.googlecode.concurrentlinkedhashmap.Weighers; //导入依赖的package包/类
@Test
public void testSerializingCache() throws InterruptedException
{
ICache<MeasureableString, IRowCacheEntry> cache = SerializingCache.create(CAPACITY, Weighers.<RefCountedMemory>singleton(), new SerializingCacheProvider.RowCacheSerializer());
CachedBTreePartition partition = createPartition();
simpleCase(partition, cache);
concurrentCase(partition, cache);
}
示例9: LRUCache
import com.googlecode.concurrentlinkedhashmap.Weighers; //导入依赖的package包/类
public LRUCache(String title, int maxsize, long expiretime) {
this.title = title;
this.expiretime.set(expiretime);
this.maxsize.set(maxsize);
cache = new ConcurrentLinkedHashMap.Builder<Object, CacheItem>().maximumWeightedCapacity(maxsize).weigher(Weighers.singleton()).build();
LRUCacheManager.regist(title, this);
}
示例10: create
import com.googlecode.concurrentlinkedhashmap.Weighers; //导入依赖的package包/类
public static <K, V> ConcurrentLinkedHashCache<K, V> create(int capacity, String tableName, String cfname)
{
ConcurrentLinkedHashMap<K, V> map = new ConcurrentLinkedHashMap.Builder<K, V>()
.weigher(Weighers.<V>singleton())
.initialCapacity(capacity)
.maximumWeightedCapacity(capacity)
.concurrencyLevel(DEFAULT_CONCURENCY_LEVEL)
.build();
return new ConcurrentLinkedHashCache<K, V>(map);
}