Java Code Examples for com.google.common.cache.RemovalNotification#getCause()

The following examples show how to use com.google.common.cache.RemovalNotification#getCause() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BookKeeper.java    From rubix with Apache License 2.0 6 votes vote down vote up
@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);
  }
}
 
Example 2
Source File: SingularityOfferCache.java    From Singularity with Apache License 2.0 6 votes vote down vote up
@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();
    }
  }
}
 
Example 3
Source File: MemberCacheLoader.java    From meghanada-server with GNU General Public License v3.0 5 votes vote down vote up
@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);
  }
}
 
Example 4
Source File: JavaSourceLoader.java    From meghanada-server with GNU General Public License v3.0 5 votes vote down vote up
@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);
    }
  }
}
 
Example 5
Source File: BatchInputBolt.java    From StormCV with Apache License 2.0 5 votes vote down vote up
/**
 * 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());
	}
}
 
Example 6
Source File: GuidePostsCacheImpl.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@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});
        }
    }
}
 
Example 7
Source File: VoiceContextExecutorRegistry.java    From arcusplatform with Apache License 2.0 4 votes vote down vote up
private void onRemoved(RemovalNotification notification) {
   if(notification.getCause() != RemovalCause.EXPLICIT) {
      logger.info("voice context for {} removed from cache because {}", notification.getKey(), notification.getCause());
   }
}
 
Example 8
Source File: FinalizedStateCache.java    From teku with Apache License 2.0 4 votes vote down vote up
private void onRemovedFromCache(
    final RemovalNotification<UnsignedLong, BeaconState> removalNotification) {
  if (removalNotification.getCause() != RemovalCause.REPLACED) {
    availableSlots.remove(removalNotification.getKey());
  }
}
 
Example 9
Source File: LocalNodeManager.java    From xian with Apache License 2.0 4 votes vote down vote up
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", "正常删除");
            }});
    }
}