• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java EvictionListener类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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();
}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:20,代码来源:SerializingCache.java


示例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();
}
 
开发者ID:Jakegogo,项目名称:concurrent,代码行数:25,代码来源:ConcurrentLinkedHashMapCache.java


示例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>();
}
 
开发者ID:apache,项目名称:incubator-blur,代码行数:23,代码来源:DeepPagingCache.java


示例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();
}
 
开发者ID:devdattakulkarni,项目名称:Cassandra-KVPM,代码行数:20,代码来源:SerializingCache.java


示例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();
}
 
开发者ID:btcsoft,项目名称:coinj-dash,代码行数:12,代码来源:MessagesRegistry.java


示例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;
}
 
开发者ID:europeana,项目名称:search,代码行数:31,代码来源:BlockCache.java


示例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();
}
 
开发者ID:beebeandwer,项目名称:TDDL,代码行数:12,代码来源:GoogleConcurrentLruCache.java


示例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);
    }
}
 
开发者ID:beebeandwer,项目名称:TDDL,代码行数:15,代码来源:GoogleConcurrentLruCacheTest.java


示例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());
        }
    };
}
 
开发者ID:vibur,项目名称:vibur-dbcp,代码行数:20,代码来源:ClhmStatementCache.java


示例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;
}
 
开发者ID:jordw,项目名称:heftydb,代码行数:12,代码来源:TableBlockCache.java


示例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();
}
 
开发者ID:booz-allen-hamilton,项目名称:lucene-hdfs-directory,代码行数:31,代码来源:BlockCache.java


示例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();
}
 
开发者ID:apache,项目名称:incubator-blur,代码行数:46,代码来源:BlockCache.java



注:本文中的com.googlecode.concurrentlinkedhashmap.EvictionListener类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java InstanceStatus类代码示例发布时间:2022-05-21
下一篇:
Java SubscriberExceptionContext类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap