Java Code Examples for com.google.common.cache.RemovalNotification#getKey()
The following examples show how to use
com.google.common.cache.RemovalNotification#getKey() .
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: QuicksqlServerMeta.java From Quicksql with MIT License | 6 votes |
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); } }
Example 2
Source File: ColumnarStoreCache.java From kylin-on-parquet-v2 with Apache License 2.0 | 6 votes |
@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); } }
Example 3
Source File: UsageTrackingCache.java From docker-plugin with MIT License | 6 votes |
/** * 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(); }
Example 4
Source File: BitsetFilterCache.java From Elasticsearch with Apache License 2.0 | 6 votes |
@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 } }
Example 5
Source File: QuarkMetaImpl.java From quark with Apache License 2.0 | 6 votes |
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); } }
Example 6
Source File: MemberCacheLoader.java From meghanada-server with GNU General Public License v3.0 | 5 votes |
@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 7
Source File: CacheManager.java From elasticactors with Apache License 2.0 | 5 votes |
@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()); } }
Example 8
Source File: GuidePostsCacheImpl.java From phoenix with Apache License 2.0 | 5 votes |
@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 9
Source File: IpmiPayloadReceiveDispatcher.java From ipmi4j with Apache License 2.0 | 5 votes |
@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); }
Example 10
Source File: GuavaStringPool.java From mongowp with Apache License 2.0 | 5 votes |
@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()); } }
Example 11
Source File: QuarkMetaImpl.java From quark with Apache License 2.0 | 5 votes |
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); } }
Example 12
Source File: AbstractFileOutputOperator.java From attic-apex-malhar with Apache License 2.0 | 5 votes |
/** * 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); } } } }; }
Example 13
Source File: AuthFilter.java From runelite with BSD 2-Clause "Simplified" License | 5 votes |
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(); } }
Example 14
Source File: AgentProfilerFileProcessor.java From bistoury with GNU General Public License v3.0 | 5 votes |
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); } }
Example 15
Source File: TransferPool.java From multiway-pool with Apache License 2.0 | 5 votes |
/** * 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); } } }
Example 16
Source File: JdbcMeta.java From calcite-avatica with Apache License 2.0 | 5 votes |
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); } }
Example 17
Source File: ShardRequestCache.java From Elasticsearch with Apache License 2.0 | 5 votes |
@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); }
Example 18
Source File: IndicesRequestCache.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override public void onRemoval(RemovalNotification<Key, Value> notification) { if (notification.getKey() == null) { return; } notification.getKey().shard.requestCache().onRemoval(notification); }
Example 19
Source File: QuicksqlServerMeta.java From Quicksql with MIT License | 5 votes |
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); } }
Example 20
Source File: LocalNodeManager.java From xian with Apache License 2.0 | 4 votes |
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", "正常删除"); }}); } }