本文整理汇总了Java中com.google.common.cache.RemovalCause.EXPIRED属性的典型用法代码示例。如果您正苦于以下问题:Java RemovalCause.EXPIRED属性的具体用法?Java RemovalCause.EXPIRED怎么用?Java RemovalCause.EXPIRED使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.google.common.cache.RemovalCause
的用法示例。
在下文中一共展示了RemovalCause.EXPIRED属性的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testCacheExpire
@Test
public void testCacheExpire() throws InterruptedException {
int total = 10;
final Map<String, String> expired = new HashMap<>();
RemovalListener removalListener = new RemovalListener<String, String>() {
@Override
public void onRemoval(RemovalNotification<String, String> notification) {
if(RemovalCause.EXPIRED == notification.getCause()) {
expired.put(notification.getKey(), notification.getValue());
}
}
};
Cache<String, String> myCache = CacheBuilder.newBuilder()
.expireAfterWrite(2, TimeUnit.MILLISECONDS)
.removalListener(removalListener)
.build();
for(int i = 0; i < total; i++) {
myCache.put("key_" + i, "val_" + i);
}
Thread.sleep(10);
myCache.cleanUp();
assertEquals(total, expired.size());
}
示例2: init
public static void init() {
RemovalListener<String, Object> removalListener = removal -> {
if (removal.getCause() == RemovalCause.EXPIRED) {
getModpacks();
}
};
MODPACKS_CACHE = CacheBuilder.newBuilder().expireAfterWrite(1, TimeUnit.HOURS).removalListener(removalListener).build();
getModpacks();
getMods();
}
示例3: onRemoval
@Override
public void onRemoval(RemovalNotification<String, String> notification) {
// rollback transaction on expire
if(RemovalCause.EXPIRED == notification.getCause()) {
rollback(notification.getKey());
}
}
示例4: onRemoval
/**
* Callback method for removal of items from the histories cache. Items removed from the cache need to be acked or failed
* according to the reason they were removed
*/
@Override
public void onRemoval(RemovalNotification<CVParticle, String> notification) {
// make sure the CVParticle object is removed from the history (even if removal was automatic!)
history.clear(notification.getKey(), notification.getValue());
if(notification.getCause() == RemovalCause.EXPIRED || notification.getCause() == RemovalCause.SIZE){
// item removed automatically --> fail the tuple
collector.fail(notification.getKey().getTuple());
}else{
// item removed explicitly --> ack the tuple
collector.ack(notification.getKey().getTuple());
}
}
示例5: onRemoval
/**
* {@inheritDoc}
*/
@Override
public void onRemoval(final RemovalNotification<String, StratumTcpServerConnection> notification)
{
if (notification.getCause() == RemovalCause.EXPIRED)
StratumTcpServer.this.onConnectionTimeout(notification.getValue());
}
示例6: onRemoval
@Override
public void onRemoval(RemovalNotification<UUID, MapReduceTracker.RequestWrapper> notification) {
if (notification.getCause() == RemovalCause.EXPIRED) {
RequestWrapper wrapper = notification.getValue();
log.warn("Timing out MapReduce request <{}> with ref count <{}>", wrapper.getClass().toString(), wrapper.pendingResponseCount.get());
wrapper.request.onComplete(true);
}
}