下面列出了com.google.common.cache.RemovalNotification#getCause ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void onRemoval(RemovalNotification<String, FileMetadata> notification)
{
FileMetadata md = notification.getValue();
try {
md.closeAndCleanup(notification.getCause(), fileMetadataCache);
if (!isValidatingCachingBehavior(md.getRemotePath())) {
switch (notification.getCause()) {
case EXPLICIT:
cacheInvalidationCount.inc();
break;
case SIZE:
cacheEvictionCount.inc();
break;
case EXPIRED:
cacheExpiryCount.inc();
break;
default:
break;
}
}
}
catch (IOException e) {
log.warn("Could not cleanup FileMetadata for " + notification.getKey(), e);
}
}
@Override
public void onRemoval(RemovalNotification<String, CachedOffer> notification) {
if (notification.getCause() == RemovalCause.EXPLICIT) {
return;
}
LOG.debug(
"Cache removal for {} due to {}",
notification.getKey(),
notification.getCause()
);
synchronized (offerCache) {
if (notification.getValue().offerState == OfferState.AVAILABLE) {
declineOffer(notification.getValue());
} else {
notification.getValue().expire();
}
}
}
@Override
public void onRemoval(final RemovalNotification<String, List<MemberDescriptor>> notification) {
final RemovalCause cause = notification.getCause();
if (cause.equals(RemovalCause.EXPLICIT)) {
final String key = notification.getKey();
boolean b = ProjectDatabaseHelper.deleteMemberDescriptors(key);
}
}
@Override
public void onRemoval(final RemovalNotification<File, Source> notification) {
final RemovalCause cause = notification.getCause();
final Config config = Config.load();
if (config.useSourceCache() && cause.equals(RemovalCause.EXPLICIT)) {
final Source source = notification.getValue();
try {
deleteSource(source);
} catch (Exception e) {
log.catching(e);
}
}
}
/**
* 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());
}
}
@Override
public void onRemoval(RemovalNotification<GuidePostsKey, GuidePostsInfo> notification) {
if (logger.isTraceEnabled()) {
final RemovalCause cause = notification.getCause();
if (wasEvicted(cause)) {
GuidePostsKey key = notification.getKey();
logger.trace("Cached stats for {} with size={}bytes was evicted due to cause={}",
new Object[] {key, notification.getValue().getEstimatedSize(),
cause});
}
}
}
private void onRemoved(RemovalNotification notification) {
if(notification.getCause() != RemovalCause.EXPLICIT) {
logger.info("voice context for {} removed from cache because {}", notification.getKey(), notification.getCause());
}
}
private void onRemovedFromCache(
final RemovalNotification<UnsignedLong, BeaconState> removalNotification) {
if (removalNotification.getCause() != RemovalCause.REPLACED) {
availableSlots.remove(removalNotification.getKey());
}
}
public void onRemoval(RemovalNotification<String, NotifyHandler> notification) {
String description;
switch (notification.getCause()) {
case REPLACED:
description = "出现重复的ssid的notifyHandler,原ssid对应的notifyHandler被移除,ssid=" + notification.getKey();
LOG.error(new JSONObject() {{
put("type", "notifyHandlerMapRemoval");
put("mapSize", handleMap.size());
put("cause", notification.getCause().name());
put("ssid", notification.getKey());
put("notifyHandler", notification.getValue());
put("description", description);
}});
break;
case EXPIRED:
description = "notifyHandler已过期:" + notification.getKey();
LOG.info(new JSONObject() {{
put("type", "notifyHandlerMapRemoval");
put("mapSize", handleMap.size());
put("cause", notification.getCause().name());
put("ssid", notification.getKey());
put("notifyHandler", notification.getValue());
put("description", description);
}});
break;
case SIZE:
description = "notifyHandlerMap的size超过上限,可能是内存泄漏";
LOG.info(new JSONObject() {{
put("type", "notifyHandlerMapRemoval");
put("mapSize", handleMap.size());
put("cause", notification.getCause().name());
put("ssid", notification.getKey());
put("notifyHandler", notification.getValue());
put("description", description);
}});
break;
default:
LOG.debug(new JSONObject() {{
put("type", "notifyHandlerMapRemoval");
put("mapSize", handleMap.size());
put("cause", notification.getCause().name());
put("ssid", notification.getKey());
put("notifyHandler", notification.getValue());
put("description", "正常删除");
}});
}
}