com.google.common.cache.RemovalNotification#wasEvicted ( )源码实例Demo

下面列出了com.google.common.cache.RemovalNotification#wasEvicted ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: tutorials   文件: GuavaCacheUnitTest.java
@Test
public void whenEntryRemovedFromCache_thenNotify() {
    final CacheLoader<String, String> loader = new CacheLoader<String, String>() {
        @Override
        public final String load(final String key) {
            return key.toUpperCase();
        }
    };
    final RemovalListener<String, String> listener = new RemovalListener<String, String>() {
        @Override
        public void onRemoval(final RemovalNotification<String, String> n) {
            if (n.wasEvicted()) {
                final String cause = n.getCause().name();
                assertEquals(RemovalCause.SIZE.toString(), cause);
            }
        }
    };
    final LoadingCache<String, String> cache = CacheBuilder.newBuilder().maximumSize(3).removalListener(listener).build(loader);
    cache.getUnchecked("first");
    cache.getUnchecked("second");
    cache.getUnchecked("third");
    cache.getUnchecked("last");
    assertEquals(3, cache.size());
}
 
源代码2 项目: Elasticsearch   文件: ShardRequestCache.java
@Override
public void onRemoval(RemovalNotification<IndicesRequestCache.Key, IndicesRequestCache.Value> removalNotification) {
    if (removalNotification.wasEvicted()) {
        evictionsMetric.inc();
    }
    long dec = 0;
    if (removalNotification.getKey() != null) {
        dec += removalNotification.getKey().ramBytesUsed();
    }
    if (removalNotification.getValue() != null) {
        dec += removalNotification.getValue().ramBytesUsed();
    }
    totalMetric.dec(dec);
}
 
源代码3 项目: distributedlog   文件: LogSegmentMetadataCache.java
@Override
public void onRemoval(RemovalNotification<String, LogSegmentMetadata> notification) {
    if (notification.wasEvicted()) {
        if (logger.isDebugEnabled()) {
            logger.debug("Log segment of {} was evicted.", notification.getKey());
        }
    }
}
 
源代码4 项目: Pistachio   文件: NettyPistachioClientHandler.java
@Override
public void onRemoval(
        RemovalNotification<Integer, SettableFuture<Response>> arg0) {
    if (arg0.wasEvicted()) {
        SettableFuture<Response> response = arg0.getValue();
        logger.warn("request id {} timeout", arg0.getKey());
        response.setException(new RequestTimeoutException("request timeout"));
    }
}
 
源代码5 项目: ipmi4j   文件: IpmiPayloadReceiveDispatcher.java
@Override
public void onRemoval(RemovalNotification<IpmiReceiverKey, IpmiReceiver> notification) {
    IpmiReceiverKey key = notification.getKey();
    IpmiReceiver receiver = notification.getValue();
    if (key != null && receiver != null && notification.wasEvicted())
        receiver.timeout(key);
}
 
源代码6 项目: onos   文件: SimpleVirtualFlowRuleStore.java
@Override
public void onRemoval(RemovalNotification<Long,
        SettableFuture<CompletedBatchOperation>> notification) {
    // wrapping in ExecutionException to support Future.get
    if (notification.wasEvicted()) {
        notification.getValue()
                .setException(new ExecutionException("Timed out",
                                                     new TimeoutException()));
    }
}
 
源代码7 项目: onos   文件: SimpleFlowRuleStore.java
@Override
public void onRemoval(RemovalNotification<Integer, SettableFuture<CompletedBatchOperation>> notification) {
    // wrapping in ExecutionException to support Future.get
    if (notification.wasEvicted()) {
        notification.getValue()
                .setException(new ExecutionException("Timed out",
                                                     new TimeoutException()));
    }
}
 
源代码8 项目: elasticactors   文件: CacheManager.java
@Override
public void onRemoval(RemovalNotification<CacheKey, V> notification) {
    if(notification.getKey() != null && notification.wasEvicted()) {
        segmentIndex.remove(notification.getKey().segmentKey,notification.getKey());
    }
    EvictionListener<V> evictionListener = evictionListeners.get(notification.getKey().segmentKey);
    // only notify when it was not evicted explicitly (when a entry was deleted)
    // otherwise the prePassivate will run
    if(evictionListener != null && notification.wasEvicted()) {
        evictionListener.onEvicted(notification.getValue());
    }
}
 
源代码9 项目: storm-crawler   文件: StatusUpdaterBolt.java
public void onRemoval(RemovalNotification<String, List<Tuple>> removal) {
    if (!removal.wasEvicted())
        return;
    LOG.error("Purged from waitAck {} with {} values", removal.getKey(),
            removal.getValue().size());
    for (Tuple t : removal.getValue()) {
        _collector.fail(t);
    }
}
 
源代码10 项目: storm-crawler   文件: IndexerBolt.java
public void onRemoval(RemovalNotification<String, Tuple> removal) {
    if (!removal.wasEvicted())
        return;
    LOG.error("Purged from waitAck {} - {}", removal.getKey(), removal
            .getValue().getStringByField("url"));
    _collector.fail(removal.getValue());
}