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

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

源代码1 项目: Quicksql   文件: QuicksqlServerMeta.java
public void onRemoval(RemovalNotification<Integer, StatementInfo> notification) {
    Integer stmtId = notification.getKey();
    StatementInfo doomed = notification.getValue();
    if (doomed == null) {
        // log/throw?
        return;
    }
    LOGGER.debug("Expiring statement {} because {}", stmtId, notification.getCause());
    try {
        if (doomed.getResultSet() != null) {
            doomed.getResultSet().close();
        }
        if (doomed.statement != null) {
            doomed.statement.close();
        }
    } catch (Throwable t) {
        LOGGER.info("Exception thrown while expiring statement {}", stmtId, t);
    }
}
 
源代码2 项目: kylin-on-parquet-v2   文件: ColumnarStoreCache.java
@Override
public void onRemoval(RemovalNotification<DataSegmentFragment, FragmentData> notification) {
    DataSegmentFragment fragment = notification.getKey();
    logger.debug("Data fragment " + fragment + " is unloaded from Cache due to "
            + notification.getCause());
    FragmentData fragmentData = notification.getValue();
    AtomicLong refCounter = refCounters.get(fragment);
    if (refCounter != null) {
        synchronized (refCounter) {
            if (refCounter.get() <= 0) {
                int bufferSize = fragmentData.getBufferCapacity();
                currentBufferedSize.addAndGet(-bufferSize);
                fragmentData.tryForceUnMapBuffer();
                refCounters.remove(fragment);
            } else {
                logger.debug("Fragment mapped buffer " + fragment
                        + " cannot be cleaned, because it has reference " + refCounter.get());
            }
        }
    } else {
        logger.debug("no ref counter found for fragment: " + fragment);
    }
}
 
源代码3 项目: Elasticsearch   文件: BitsetFilterCache.java
@Override
public void onRemoval(RemovalNotification<Object, Cache<Query, Value>> notification) {
    Object key = notification.getKey();
    if (key == null) {
        return;
    }

    Cache<Query, Value> valueCache = notification.getValue();
    if (valueCache == null) {
        return;
    }

    for (Value value : valueCache.asMap().values()) {
        listener.onRemoval(value.shardId, value.bitset);
        // if null then this means the shard has already been removed and the stats are 0 anyway for the shard this key belongs to
    }
}
 
源代码4 项目: quark   文件: QuarkMetaImpl.java
public void onRemoval(RemovalNotification<Integer, StatementInfo> notification) {
  Integer stmtId = notification.getKey();
  StatementInfo doomed = notification.getValue();
  if (doomed == null) {
    // log/throw?
    return;
  }
  if (LOG.isDebugEnabled()) {
    LOG.debug("Expiring statement " + stmtId + " because "
        + notification.getCause());
  }
  try {
    if (doomed.resultSet != null) {
      doomed.resultSet.close();
    }
    if (doomed.statement != null) {
      doomed.statement.close();
    }
  } catch (Throwable t) {
    LOG.info("Exception thrown while expiring statement " + stmtId);
  }
}
 
源代码5 项目: docker-plugin   文件: UsageTrackingCache.java
/**
 * Full constructor.
 * 
 * @param duration
 *            How long inactive things should be kept in the cache.
 * @param unit
 *            The <code>duration</code>'s unit of measurement.
 * @param expiryHandler
 *            Callback that is given all expired values from the cache just
 *            before they are thrown away.
 */
UsageTrackingCache(final long duration, @Nonnull final TimeUnit unit,
        @Nonnull final ExpiryHandler<K, V> expiryHandler) {
    activeCacheByKey = new HashMap<>();
    activeCacheByValue = new IdentityHashMap();
    CacheBuilder<Object, Object> cacheBuilder = CacheBuilder.newBuilder();
    cacheBuilder = cacheBuilder.expireAfterAccess(duration, unit);
    final RemovalListener removalHandler = new RemovalListener<K, CacheEntry<K, V>>() {
        @Override
        public void onRemoval(RemovalNotification<K, CacheEntry<K, V>> notification) {
            final K key = notification.getKey();
            if (!activeCacheByKey.containsKey(key)) {
                final CacheEntry<K, V> record = notification.getValue();
                final V value = record.getValue();
                expiryHandler.entryDroppedFromCache(key, value);
            }
        }
    };
    cacheBuilder = cacheBuilder.removalListener(removalHandler);
    durationCache = cacheBuilder.build();
}
 
源代码6 项目: bistoury   文件: AgentProfilerFileProcessor.java
private void close(RemovalNotification<String, OutputStream> notification) {
    String filePath = notification.getKey();
    OutputStream outputStream = notification.getValue();
    try {
        outputStream.flush();
        outputStream.close();
    } catch (IOException e) {
        logger.error("close file from agent error. path: {}", filePath, e);
    }
}
 
源代码7 项目: Quicksql   文件: QuicksqlServerMeta.java
public void onRemoval(RemovalNotification<String, Connection> notification) {
    String connectionId = notification.getKey();
    Connection doomed = notification.getValue();
    LOGGER.debug("Expiring connection {} because {}", connectionId, notification.getCause());
    try {
        if (doomed != null) {
            doomed.close();
        }
    } catch (Throwable t) {
        LOGGER.info("Exception thrown while expiring connection {}", connectionId, t);
    }
}
 
源代码8 项目: Elasticsearch   文件: IndicesRequestCache.java
@Override
public void onRemoval(RemovalNotification<Key, Value> notification) {
    if (notification.getKey() == null) {
        return;
    }
    notification.getKey().shard.requestCache().onRemoval(notification);
}
 
源代码9 项目: 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);
}
 
源代码10 项目: calcite-avatica   文件: JdbcMeta.java
public void onRemoval(RemovalNotification<String, Connection> notification) {
  String connectionId = notification.getKey();
  Connection doomed = notification.getValue();
  LOG.debug("Expiring connection {} because {}", connectionId, notification.getCause());
  try {
    if (doomed != null) {
      doomed.close();
    }
  } catch (Throwable t) {
    LOG.info("Exception thrown while expiring connection {}", connectionId, t);
  }
}
 
源代码11 项目: multiway-pool   文件: TransferPool.java
/**
 * Atomically transitions the resource to a state where it can no longer be used. If the
 * resource is idle or retired then it is immediately discarded. If the resource is
 * currently in use then it is marked to be discarded when it has been released.
 */
@Override
public void onRemoval(RemovalNotification<ResourceKey<K>, R> notification) {
  ResourceKey<K> resourceKey = notification.getKey();
  for (;;) {
    Status status = resourceKey.getStatus();
    switch (status) {
      case IDLE:
        // The resource is not being used and may be immediately discarded
        if (resourceKey.goFromIdleToDead()) {
          discardFromIdle(resourceKey, notification.getValue());
          return;
        }
        break;
      case IN_FLIGHT:
        // The resource is currently being used and should be discarded when released
        if (resourceKey.goFromInFlightToRetired()) {
          return;
        }
        break;
      case RETIRED:
        // A resource is already retired when it has been expired by the idle cache
        if (resourceKey.goFromRetiredToDead()) {
          discardFromRetired(resourceKey, notification.getValue());
          return;
        }
        break;
      default:
        throw new IllegalStateException("Unnexpected state: " + status);
    }
  }
}
 
源代码12 项目: meghanada-server   文件: MemberCacheLoader.java
@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);
  }
}
 
源代码13 项目: runelite   文件: AuthFilter.java
private void removalListener(RemovalNotification<UUID, SessionEntry> notification)
{
	UUID uuid = notification.getKey();
	Instant now = Instant.now();

	try (Connection con = sql2o.open())
	{
		con.createQuery("update sessions set last_used = :last_used where uuid = :uuid")
			.addParameter("last_used", Timestamp.from(now))
			.addParameter("uuid", uuid.toString())
			.executeUpdate();
	}
}
 
/**
 * Creates the removal listener which is attached to the cache.
 *
 * @return cache entry removal listener.
 */
private RemovalListener<String, FSFilterStreamContext> createCacheRemoveListener()
{
  //When an entry is removed from the cache, removal listener is notified and it closes the output stream.
  return new RemovalListener<String, FSFilterStreamContext>()
  {
    @Override
    public void onRemoval(@Nonnull RemovalNotification<String, FSFilterStreamContext> notification)
    {
      FSFilterStreamContext streamContext = notification.getValue();
      if (streamContext != null) {
        try {
          String filename = notification.getKey();
          String partFileName = getPartFileNamePri(filename);

          LOG.info("closing {}", partFileName);
          long start = System.currentTimeMillis();

          closeStream(streamContext);
          filesWithOpenStreams.remove(filename);

          totalWritingTime += System.currentTimeMillis() - start;
        } catch (IOException e) {
          LOG.error("removing {}", notification.getValue(), e);
          throw new RuntimeException(e);
        }
      }
    }
  };
}
 
源代码15 项目: quark   文件: QuarkMetaImpl.java
public void onRemoval(RemovalNotification<String, Connection> notification) {
  String connectionId = notification.getKey();
  Connection doomed = notification.getValue();
  if (LOG.isDebugEnabled()) {
    LOG.debug("Expiring connection " + connectionId + " because "
        + notification.getCause());
  }
  try {
    if (doomed != null) {
      doomed.close();
    }
  } catch (Throwable t) {
    LOG.info("Exception thrown while expiring connection " + connectionId, t);
  }
}
 
源代码16 项目: mongowp   文件: GuavaStringPool.java
@Override
public void onRemoval(RemovalNotification<ByteBuf, String> notification) {
  ByteBuf key = notification.getKey();
  if (key == null) {
    throw new IllegalStateException("Unexpected null key");
  }
  boolean release = key.release();
  if (!release) {
    LOGGER.warn("The cached string ByteBuf with value {} was "
        + "removed but it had more references than expected", notification.getValue());
  }
}
 
源代码17 项目: 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);
}
 
源代码18 项目: phoenix   文件: GuidePostsCacheImpl.java
@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});
        }
    }
}
 
源代码19 项目: 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());
    }
}
 
源代码20 项目: xian   文件: LocalNodeManager.java
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", "正常删除");
            }});
    }
}