public V getLastEvictedValue() { return lastNotification.getValue(); }
public V getLastEvictedValue() { return lastNotification.getValue(); }
@Override public void onRemoval(RemovalNotification<String, ProtocolType> arg) { if (arg == null) return; shutdownProtocolImpl(arg.getValue()); } });
@Override public void onRemoval(RemovalNotification<String, ISource> entry) { ISource s = entry.getValue(); if (s != null) { try { s.close(); } catch (Throwable e) { logger.error("Failed to close ISource: {}", s.getClass().getName(), e); } } } }).build();
@Override public void onRemoval(RemovalNotification<Integer, AtomicInteger> notification) { if (notification.wasEvicted()) { evictionCount.incrementAndGet(); totalSum.addAndGet(notification.getValue().get()); } } };
@Override public void onRemoval(RemovalNotification<State, Set<KeyAndSource>> notification) { Preconditions.checkState(RemovalCause.COLLECTED.equals(notification.getCause())); cleanUpForCollectedState(notification.getValue()); } })
@Override public void onRemoval(RemovalNotification<StandardTransactionId, TxEntry> notification) { RemovalCause cause = notification.getCause(); Preconditions.checkArgument(cause == RemovalCause.EXPIRED, "Unexpected removal cause [%s] for transaction [%s]", cause, notification.getKey()); TxEntry entry = notification.getValue(); if (entry.status == LogTxStatus.SECONDARY_FAILURE || entry.status == LogTxStatus.PRIMARY_SUCCESS) { failureTxCounter.incrementAndGet(); fixSecondaryFailure(notification.getKey(), entry); } else { successTxCounter.incrementAndGet(); } } })
private static <K, V> void assertNotificationEnqueued( LocalCache<K, V> map, K key, V value, int hash) { RemovalNotification<K, V> notification = map.removalNotificationQueue.poll(); assertSame(key, notification.getKey()); assertSame(value, notification.getValue()); }
@Override public void onRemoval(RemovalNotification<Long, InternalVertex> notification) { if (notification.getCause() == RemovalCause.EXPLICIT) { //Due to invalidation at the end assert volatileVertices.isEmpty(); return; } //Should only get evicted based on size constraint or replaced through add assert (notification.getCause() == RemovalCause.SIZE || notification.getCause() == RemovalCause.REPLACED) : "Cause: " + notification.getCause(); InternalVertex v = notification.getValue(); if (v.isModified()) { volatileVertices.putIfAbsent(notification.getKey(), v); } } })
public void testGet() { Object computed = new Object(); LoadingCache<Object, Object> cache = CacheBuilder.newBuilder() .maximumSize(0) .removalListener(listener) .build(constantLoader(computed)); Object key = new Object(); assertSame(computed, cache.getUnchecked(key)); RemovalNotification<Object, Object> notification = listener.remove(); assertSame(key, notification.getKey()); assertSame(computed, notification.getValue()); assertSame(RemovalCause.SIZE, notification.getCause()); assertTrue(listener.isEmpty()); checkEmpty(cache); }
public void testGet_expireAfterWrite() { Object computed = new Object(); LoadingCache<Object, Object> cache = CacheBuilder.newBuilder() .expireAfterWrite(0, SECONDS) .removalListener(listener) .build(constantLoader(computed)); Object key = new Object(); assertSame(computed, cache.getUnchecked(key)); RemovalNotification<Object, Object> notification = listener.remove(); assertSame(key, notification.getKey()); assertSame(computed, notification.getValue()); assertSame(RemovalCause.SIZE, notification.getCause()); assertTrue(listener.isEmpty()); checkEmpty(cache); }
public void testGet_expireAfterAccess() { Object computed = new Object(); LoadingCache<Object, Object> cache = CacheBuilder.newBuilder() .expireAfterAccess(0, SECONDS) .removalListener(listener) .build(constantLoader(computed)); Object key = new Object(); assertSame(computed, cache.getUnchecked(key)); RemovalNotification<Object, Object> notification = listener.remove(); assertSame(key, notification.getKey()); assertSame(computed, notification.getValue()); assertSame(RemovalCause.SIZE, notification.getCause()); assertTrue(listener.isEmpty()); checkEmpty(cache); }
RemovalNotification<String, String> notification = listener.remove(); assertEquals("a", notification.getKey()); assertEquals("a", notification.getValue()); assertEquals(1, cache.size()); assertEquals("b", cache.getUnchecked("b"));
static <K, V> void assertNotified( QueuingRemovalListener<K, V> listener, K key, V value, RemovalCause cause) { RemovalNotification<K, V> notification = listener.remove(); assertSame(key, notification.getKey()); assertSame(value, notification.getValue()); assertSame(cause, notification.getCause()); }
@Override public void onRemoval(RemovalNotification<K, V> notification) { RemovalCause cause = RemovalCause.valueOf(notification.getCause().name()); if (translateZeroExpire && (cause == RemovalCause.SIZE)) { // Guava internally uses sizing logic for null cache case cause = RemovalCause.EXPIRED; } delegate.onRemoval(notification.getKey(), notification.getValue(), cause); } }
public void testGet() { Object computed = new Object(); LoadingCache<Object, Object> cache = CaffeinatedGuava.build(Caffeine.newBuilder() .executor(MoreExecutors.directExecutor()) .maximumSize(0) .removalListener(listener), constantLoader(computed)); Object key = new Object(); assertSame(computed, cache.getUnchecked(key)); RemovalNotification<Object, Object> notification = listener.remove(); assertSame(key, notification.getKey()); assertSame(computed, notification.getValue()); assertSame(RemovalCause.SIZE, notification.getCause()); assertTrue(listener.isEmpty()); checkEmpty(cache); }
public void testGet_expireAfterWrite() { // Guava sends a notification with SIZE as the removal cause by redefining 0 expiration as // a maximum size of zero. This is not done as expiration can be dynamically updated Object computed = new Object(); LoadingCache<Object, Object> cache = CaffeinatedGuava.build(Caffeine.newBuilder() .executor(MoreExecutors.directExecutor()) .expireAfterWrite(0, SECONDS) .removalListener(listener), constantLoader(computed)); Object key = new Object(); assertSame(computed, cache.getUnchecked(key)); RemovalNotification<Object, Object> notification = listener.remove(); assertSame(key, notification.getKey()); assertSame(computed, notification.getValue()); assertSame(RemovalCause.EXPIRED, notification.getCause()); assertTrue(listener.isEmpty()); checkEmpty(cache); }
public void testGet_expireAfterAccess() { // Guava sends a notification with SIZE as the removal cause by redefining 0 expiration as // a maximum size of zero. This is not done as expiration can be dynamically updated Object computed = new Object(); LoadingCache<Object, Object> cache = CaffeinatedGuava.build(Caffeine.newBuilder() .executor(MoreExecutors.directExecutor()) .expireAfterAccess(0, SECONDS) .removalListener(listener), constantLoader(computed)); Object key = new Object(); assertSame(computed, cache.getUnchecked(key)); RemovalNotification<Object, Object> notification = listener.remove(); assertSame(key, notification.getKey()); assertSame(computed, notification.getValue()); assertSame(RemovalCause.EXPIRED, notification.getCause()); assertTrue(listener.isEmpty()); checkEmpty(cache); }