Package com.google.common.cache
Class LocalCache.LoadingValueReference<K,V>
- java.lang.Object
-
- com.google.common.cache.LocalCache.LoadingValueReference<K,V>
-
- All Implemented Interfaces:
LocalCache.ValueReference<K,V>
- Enclosing class:
- LocalCache<K,V>
static class LocalCache.LoadingValueReference<K,V> extends java.lang.Object implements LocalCache.ValueReference<K,V>
-
-
Field Summary
Fields Modifier and Type Field Description (package private) SettableFuture<V>futureValue(package private) LocalCache.ValueReference<K,V>oldValue(package private) Stopwatchstopwatch
-
Constructor Summary
Constructors Constructor Description LoadingValueReference()LoadingValueReference(LocalCache.ValueReference<K,V> oldValue)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Vcompute(K key, java.util.function.BiFunction<? super K,? super V,? extends V> function)LocalCache.ValueReference<K,V>copyFor(java.lang.ref.ReferenceQueue<V> queue, V value, ReferenceEntry<K,V> entry)Creates a copy of this reference for the given entry.longelapsedNanos()private ListenableFuture<V>fullyFailedFuture(java.lang.Throwable t)Vget()Returns the value.ReferenceEntry<K,V>getEntry()Returns the entry associated with this value reference, ornullif this value reference is independent of any entry.LocalCache.ValueReference<K,V>getOldValue()intgetWeight()Returns the weight of this entry.booleanisActive()Returns true if this reference contains an active value, meaning one that is still considered present in the cache.booleanisLoading()Returns true if a new value is currently loading, regardless of whether or not there is an existing value.ListenableFuture<V>loadFuture(K key, CacheLoader<? super K,V> loader)voidnotifyNewValue(V newValue)Notify pending loads that a new value was set.booleanset(V newValue)booleansetException(java.lang.Throwable t)VwaitForValue()Waits for a value that may still be loading.
-
-
-
Field Detail
-
oldValue
volatile LocalCache.ValueReference<K,V> oldValue
-
futureValue
final SettableFuture<V> futureValue
-
stopwatch
final Stopwatch stopwatch
-
-
Constructor Detail
-
LoadingValueReference
public LoadingValueReference()
-
LoadingValueReference
public LoadingValueReference(LocalCache.ValueReference<K,V> oldValue)
-
-
Method Detail
-
isLoading
public boolean isLoading()
Description copied from interface:LocalCache.ValueReferenceReturns true if a new value is currently loading, regardless of whether or not there is an existing value. It is assumed that the return value of this method is constant for any given ValueReference instance.- Specified by:
isLoadingin interfaceLocalCache.ValueReference<K,V>
-
isActive
public boolean isActive()
Description copied from interface:LocalCache.ValueReferenceReturns true if this reference contains an active value, meaning one that is still considered present in the cache. Active values consist of live values, which are returned by cache lookups, and dead values, which have been evicted but awaiting removal. Non-active values consist strictly of loading values, though during refresh a value may be both active and loading.- Specified by:
isActivein interfaceLocalCache.ValueReference<K,V>
-
getWeight
public int getWeight()
Description copied from interface:LocalCache.ValueReferenceReturns the weight of this entry. This is assumed to be static between calls to setValue.- Specified by:
getWeightin interfaceLocalCache.ValueReference<K,V>
-
set
public boolean set(V newValue)
-
setException
public boolean setException(java.lang.Throwable t)
-
fullyFailedFuture
private ListenableFuture<V> fullyFailedFuture(java.lang.Throwable t)
-
notifyNewValue
public void notifyNewValue(V newValue)
Description copied from interface:LocalCache.ValueReferenceNotify pending loads that a new value was set. This is only relevant to loading value references.- Specified by:
notifyNewValuein interfaceLocalCache.ValueReference<K,V>
-
loadFuture
public ListenableFuture<V> loadFuture(K key, CacheLoader<? super K,V> loader)
-
compute
public V compute(K key, java.util.function.BiFunction<? super K,? super V,? extends V> function)
-
elapsedNanos
public long elapsedNanos()
-
waitForValue
public V waitForValue() throws java.util.concurrent.ExecutionException
Description copied from interface:LocalCache.ValueReferenceWaits for a value that may still be loading. Unlike get(), this method can block (in the case of FutureValueReference).- Specified by:
waitForValuein interfaceLocalCache.ValueReference<K,V>- Throws:
java.util.concurrent.ExecutionException- if the loading thread throws an exception
-
get
public V get()
Description copied from interface:LocalCache.ValueReferenceReturns the value. Does not block or throw exceptions.- Specified by:
getin interfaceLocalCache.ValueReference<K,V>
-
getOldValue
public LocalCache.ValueReference<K,V> getOldValue()
-
getEntry
public ReferenceEntry<K,V> getEntry()
Description copied from interface:LocalCache.ValueReferenceReturns the entry associated with this value reference, ornullif this value reference is independent of any entry.- Specified by:
getEntryin interfaceLocalCache.ValueReference<K,V>
-
copyFor
public LocalCache.ValueReference<K,V> copyFor(java.lang.ref.ReferenceQueue<V> queue, V value, ReferenceEntry<K,V> entry)
Description copied from interface:LocalCache.ValueReferenceCreates a copy of this reference for the given entry.valuemay be null only for a loading reference.- Specified by:
copyForin interfaceLocalCache.ValueReference<K,V>
-
-