/** * Poke into the Cache internals to simulate garbage collection of the given key. This assumes * that the given entry is a weak or soft reference, and throws an IllegalStateException if that * assumption does not hold. */ @SuppressWarnings("unchecked") // the instanceof check and the cast generate this warning static <K, V> void simulateKeyReclamation(Cache<K, V> cache, K key) { ReferenceEntry<K, V> entry = getReferenceEntry(cache, key); Preconditions.checkState(entry instanceof Reference); Reference<?> ref = (Reference<?>) entry; if (ref != null) { ref.clear(); } }
/** * Poke into the Cache internals to simulate garbage collection of the value associated with the * given key. This assumes that the associated entry is a WeakValueReference or a * SoftValueReference (and not a LoadingValueReference), and throws an IllegalStateException if * that assumption does not hold. */ @SuppressWarnings("unchecked") // the instanceof check and the cast generate this warning static <K, V> void simulateValueReclamation(Cache<K, V> cache, K key) { ReferenceEntry<K, V> entry = getReferenceEntry(cache, key); if (entry != null) { ValueReference<K, V> valueRef = entry.getValueReference(); // fail on strong/computing refs Preconditions.checkState(valueRef instanceof Reference); Reference<V> ref = (Reference<V>) valueRef; if (ref != null) { ref.clear(); } } }
/** * Poke into the Cache internals to simulate garbage collection of the given key. This assumes * that the given entry is a weak or soft reference, and throws an IllegalStateException if that * assumption does not hold. */ @SuppressWarnings("unchecked") // the instanceof check and the cast generate this warning static <K, V> void simulateKeyReclamation(Cache<K, V> cache, K key) { ReferenceEntry<K, V> entry = getReferenceEntry(cache, key); Preconditions.checkState(entry instanceof Reference); Reference<?> ref = (Reference<?>) entry; if (ref != null) { ref.clear(); } }
/** * Poke into the Cache internals to simulate garbage collection of the value associated with the * given key. This assumes that the associated entry is a WeakValueReference or a * SoftValueReference (and not a LoadingValueReference), and throws an IllegalStateException * if that assumption does not hold. */ @SuppressWarnings("unchecked") // the instanceof check and the cast generate this warning static <K, V> void simulateValueReclamation(Cache<K, V> cache, K key) { ReferenceEntry<K, V> entry = getReferenceEntry(cache, key); if (entry != null) { ValueReference<K, V> valueRef = entry.getValueReference(); // fail on strong/computing refs Preconditions.checkState(valueRef instanceof Reference); Reference<V> ref = (Reference<V>) valueRef; if (ref != null) { ref.clear(); } } }