@Override public ReferenceEntry<K, V> poll() { ReferenceEntry<K, V> next = head.getNextInWriteQueue(); if (next == head) { return null; } remove(next); return next; }
@Override @SuppressWarnings("unchecked") public boolean remove(Object o) { ReferenceEntry<K, V> e = (ReferenceEntry) o; ReferenceEntry<K, V> previous = e.getPreviousInAccessQueue(); ReferenceEntry<K, V> next = e.getNextInAccessQueue(); connectAccessOrder(previous, next); nullifyAccessOrder(e); return next != NullEntry.INSTANCE; }
@Override public ReferenceEntry<K, V> poll() { ReferenceEntry<K, V> next = head.getNextInAccessQueue(); if (next == head) { return null; } remove(next); return next; }
/** * Sets a new value of an entry. Adds newly created entries at the end of the access queue. */ void setValue(@Nonnull ReferenceEntry<K, V> entry, K key, V value, long now) { ValueReference<K, V> previous = entry.getValueReference(); int weight = map.weigher.weigh(key, value); Preconditions.checkState(weight >= 0, "Weights must be non-negative"); ValueReference<K, V> valueReference = map.valueStrength.referenceValue(this, entry, value, weight); entry.setValueReference(valueReference); recordWrite(entry, weight, now); previous.notifyNewValue(value); }
boolean containsKey(Object key, int hash) { try { if (count != 0) { // read-volatile long now = map.ticker.read(); ReferenceEntry<K, V> e = getLiveEntry(key, hash, now); if (e == null) { return false; } return e.getValueReference().get() != null; } return false; } finally { postReadCleanup(); } }
void reclaimValue(@Nonnull ValueReference<K, V> valueReference) { ReferenceEntry<K, V> entry = valueReference.getEntry(); int hash = entry.getHash(); segmentFor(hash).reclaimValue(entry.getKey(), hash, valueReference); }
/** * This method is a convenience for testing. Code should call {@link Segment#setValue} instead. */ // Guarded By Segment.this @Nonnull ValueReference<K, V> newValueReference(@Nonnull ReferenceEntry<K, V> entry, @Nonnull V value, int weight) { int hash = entry.getHash(); return valueStrength.referenceValue(segmentFor(hash), entry, Preconditions.checkNotNull(value), weight); }
/** * Drain the key and value reference queues, cleaning up internal entries containing garbage * collected keys or values. */ void drainReferenceQueues() { if (map.usesKeyReferences()) { drainKeyReferenceQueue(); } if (map.usesValueReferences()) { drainValueReferenceQueue(); } }
@Override public void clear() { ReferenceEntry<K, V> e = head.getNextInAccessQueue(); while (e != head) { ReferenceEntry<K, V> next = e.getNextInAccessQueue(); nullifyAccessOrder(e); e = next; } head.setNextInAccessQueue(head); head.setPreviousInAccessQueue(head); }
void cleanUp() { long now = map.ticker.read(); runLockedCleanup(now); runUnlockedCleanup(); }
/** * This method is a convenience for testing. Code should call {@link Segment#getLiveValue} * instead. */ boolean isLive(@Nonnull ReferenceEntry<K, V> entry, long now) { return segmentFor(entry.getHash()).getLiveValue(entry, now) != null; }
/** * @since 11.0 */ @Override public void invalidateAll(Iterable<?> keys) { delegate().invalidateAll(keys); }
void runUnlockedCleanup() { // locked cleanup may generate notifications we can send unlocked if (!isHeldByCurrentThread()) { map.processPendingNotifications(); } }
/** * @since 11.0 */ @Override public Map<K, V> getAllPresent(Iterable<?> keys) { return delegate().getAllPresent(keys); }