Class Node<K,V>
- java.lang.Object
-
- com.github.benmanes.caffeine.cache.Node<K,V>
-
- All Implemented Interfaces:
AccessOrderDeque.AccessOrder<Node<K,V>>,WriteOrderDeque.WriteOrder<Node<K,V>>
abstract class Node<K,V> extends java.lang.Object implements AccessOrderDeque.AccessOrder<Node<K,V>>, WriteOrderDeque.WriteOrder<Node<K,V>>
An entry in the cache containing the key, value, weight, access, and write metadata. The key or value may be held weakly or softly requiring identity comparison.
-
-
Constructor Summary
Constructors Constructor Description Node()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description booleancasVariableTime(long expect, long update)Atomically sets the variable time to the given updated value if the current value equals the expected value and returns if the update was successful.booleancasWriteTime(long expect, long update)Atomically sets the write time to the given updated value if the current value equals the expected value and returns if the update was successful.abstract booleancontainsValue(@NonNull java.lang.Object value)Returnstrueif the given objects are considered equivalent.abstract voiddie()Sets the node to the dead state.longgetAccessTime()Returns the time that this entry was last accessed, in ns.abstract @Nullable KgetKey()Return the key ornullif it has been reclaimed by the garbage collector.abstract @NonNull java.lang.ObjectgetKeyReference()Returns the reference that the cache is holding the entry by.@Nullable Node<K,V>getNextInAccessOrder()Retrieves the next element or null if either the element is unlinked or the last element on the deque.Node<K,V>getNextInVariableOrder()@Nullable Node<K,V>getNextInWriteOrder()Retrieves the next element or null if either the element is unlinked or the last element on the deque.@org.checkerframework.checker.index.qual.NonNegative intgetPolicyWeight()Returns the weight of this entry from the policy's perspective.@Nullable Node<K,V>getPreviousInAccessOrder()Retrieves the previous element or null if either the element is unlinked or the first element on the deque.Node<K,V>getPreviousInVariableOrder()@Nullable Node<K,V>getPreviousInWriteOrder()Retrieves the previous element or null if either the element is unlinked or the first element on the deque.intgetQueueType()Returns the queue that the entry's resides in (window, probation, or protected).abstract @Nullable VgetValue()Return the value ornullif it has been reclaimed by the garbage collector.abstract @NonNull java.lang.ObjectgetValueReference()Returns the reference to the value.longgetVariableTime()Returns the variable expiration time, in nanoseconds.@org.checkerframework.checker.index.qual.NonNegative intgetWeight()Returns the weight of this entry from the entry's perspective.longgetWriteTime()Returns the time that this entry was last written, in ns.booleaninMainProbation()Returns if the entry is in the Main space's probation queue.booleaninMainProtected()Returns if the entry is in the Main space's protected queue.booleaninWindow()Returns if the entry is in the Window or Main space.abstract booleanisAlive()If the entry is available in the hash-table and page replacement policy.abstract booleanisDead()If the entry was removed from the hash-table and the page replacement policy.abstract booleanisRetired()If the entry was removed from the hash-table and is awaiting removal from the page replacement policy.voidmakeMainProbation()Sets the status to the Main space's probation queue.voidmakeMainProtected()Sets the status to the Main space's protected queue.voidmakeWindow()Sets the status to the Window queue.abstract voidretire()Sets the node to the retired state.voidsetAccessTime(long time)Sets the access time in nanoseconds.voidsetNextInAccessOrder(@Nullable Node<K,V> next)Sets the next element or null if there is no link.voidsetNextInVariableOrder(@Nullable Node<K,V> prev)voidsetNextInWriteOrder(@Nullable Node<K,V> next)Sets the next element or null if there is no link.voidsetPolicyWeight(@org.checkerframework.checker.index.qual.NonNegative int weight)Sets the weight from the policy's perspective.voidsetPreviousInAccessOrder(@Nullable Node<K,V> prev)Sets the previous element or null if there is no link.voidsetPreviousInVariableOrder(@Nullable Node<K,V> prev)voidsetPreviousInWriteOrder(@Nullable Node<K,V> prev)Sets the previous element or null if there is no link.voidsetQueueType(int queueType)Set queue that the entry resides in (window, probation, or protected).abstract voidsetValue(@NonNull V value, @Nullable java.lang.ref.ReferenceQueue<V> referenceQueue)Sets the value, which may be held strongly, weakly, or softly.voidsetVariableTime(long time)Sets the variable expiration time in nanoseconds.voidsetWeight(@org.checkerframework.checker.index.qual.NonNegative int weight)Sets the weight from the entry's perspective.voidsetWriteTime(long time)Sets the write time in nanoseconds.java.lang.StringtoString()
-
-
-
Field Detail
-
WINDOW
public static final int WINDOW
- See Also:
- Constant Field Values
-
PROBATION
public static final int PROBATION
- See Also:
- Constant Field Values
-
PROTECTED
public static final int PROTECTED
- See Also:
- Constant Field Values
-
-
Method Detail
-
getKey
public abstract @Nullable K getKey()
Return the key ornullif it has been reclaimed by the garbage collector.
-
getKeyReference
public abstract @NonNull java.lang.Object getKeyReference()
Returns the reference that the cache is holding the entry by. This is either the key if strongly held or aWeakReferenceto that key.
-
getValue
public abstract @Nullable V getValue()
Return the value ornullif it has been reclaimed by the garbage collector.
-
getValueReference
public abstract @NonNull java.lang.Object getValueReference()
Returns the reference to the value. This is either the value if strongly held or aReferenceto that value.
-
setValue
public abstract void setValue(@NonNull V value, @Nullable java.lang.ref.ReferenceQueue<V> referenceQueue)
Sets the value, which may be held strongly, weakly, or softly. This update may be set lazily and rely on the memory fence when the lock is released.
-
containsValue
public abstract boolean containsValue(@NonNull java.lang.Object value)
Returnstrueif the given objects are considered equivalent. A strongly held value is compared by equality and a weakly or softly held value is compared by identity.
-
getWeight
public @org.checkerframework.checker.index.qual.NonNegative int getWeight()
Returns the weight of this entry from the entry's perspective.
-
setWeight
public void setWeight(@org.checkerframework.checker.index.qual.NonNegative int weight)
Sets the weight from the entry's perspective.
-
getPolicyWeight
public @org.checkerframework.checker.index.qual.NonNegative int getPolicyWeight()
Returns the weight of this entry from the policy's perspective.
-
setPolicyWeight
public void setPolicyWeight(@org.checkerframework.checker.index.qual.NonNegative int weight)
Sets the weight from the policy's perspective.
-
isAlive
public abstract boolean isAlive()
If the entry is available in the hash-table and page replacement policy.
-
isRetired
public abstract boolean isRetired()
If the entry was removed from the hash-table and is awaiting removal from the page replacement policy.
-
isDead
public abstract boolean isDead()
If the entry was removed from the hash-table and the page replacement policy.
-
retire
public abstract void retire()
Sets the node to the retired state.
-
die
public abstract void die()
Sets the node to the dead state.
-
getVariableTime
public long getVariableTime()
Returns the variable expiration time, in nanoseconds.
-
setVariableTime
public void setVariableTime(long time)
Sets the variable expiration time in nanoseconds. This update may be set lazily and rely on the memory fence when the lock is released.
-
casVariableTime
public boolean casVariableTime(long expect, long update)Atomically sets the variable time to the given updated value if the current value equals the expected value and returns if the update was successful.
-
inWindow
public boolean inWindow()
Returns if the entry is in the Window or Main space.
-
inMainProbation
public boolean inMainProbation()
Returns if the entry is in the Main space's probation queue.
-
inMainProtected
public boolean inMainProtected()
Returns if the entry is in the Main space's protected queue.
-
makeWindow
public void makeWindow()
Sets the status to the Window queue.
-
makeMainProbation
public void makeMainProbation()
Sets the status to the Main space's probation queue.
-
makeMainProtected
public void makeMainProtected()
Sets the status to the Main space's protected queue.
-
getQueueType
public int getQueueType()
Returns the queue that the entry's resides in (window, probation, or protected).
-
setQueueType
public void setQueueType(int queueType)
Set queue that the entry resides in (window, probation, or protected).
-
getAccessTime
public long getAccessTime()
Returns the time that this entry was last accessed, in ns.
-
setAccessTime
public void setAccessTime(long time)
Sets the access time in nanoseconds. This update may be set lazily and rely on the memory fence when the lock is released.
-
getPreviousInAccessOrder
public @Nullable Node<K,V> getPreviousInAccessOrder()
Description copied from interface:AccessOrderDeque.AccessOrderRetrieves the previous element or null if either the element is unlinked or the first element on the deque.- Specified by:
getPreviousInAccessOrderin interfaceAccessOrderDeque.AccessOrder<K>
-
setPreviousInAccessOrder
public void setPreviousInAccessOrder(@Nullable Node<K,V> prev)
Description copied from interface:AccessOrderDeque.AccessOrderSets the previous element or null if there is no link.- Specified by:
setPreviousInAccessOrderin interfaceAccessOrderDeque.AccessOrder<K>
-
getNextInAccessOrder
public @Nullable Node<K,V> getNextInAccessOrder()
Description copied from interface:AccessOrderDeque.AccessOrderRetrieves the next element or null if either the element is unlinked or the last element on the deque.- Specified by:
getNextInAccessOrderin interfaceAccessOrderDeque.AccessOrder<K>
-
setNextInAccessOrder
public void setNextInAccessOrder(@Nullable Node<K,V> next)
Description copied from interface:AccessOrderDeque.AccessOrderSets the next element or null if there is no link.- Specified by:
setNextInAccessOrderin interfaceAccessOrderDeque.AccessOrder<K>
-
getWriteTime
public long getWriteTime()
Returns the time that this entry was last written, in ns.
-
setWriteTime
public void setWriteTime(long time)
Sets the write time in nanoseconds. This update may be set lazily and rely on the memory fence when the lock is released.
-
casWriteTime
public boolean casWriteTime(long expect, long update)Atomically sets the write time to the given updated value if the current value equals the expected value and returns if the update was successful.
-
getPreviousInWriteOrder
public @Nullable Node<K,V> getPreviousInWriteOrder()
Description copied from interface:WriteOrderDeque.WriteOrderRetrieves the previous element or null if either the element is unlinked or the first element on the deque.- Specified by:
getPreviousInWriteOrderin interfaceWriteOrderDeque.WriteOrder<K>
-
setPreviousInWriteOrder
public void setPreviousInWriteOrder(@Nullable Node<K,V> prev)
Description copied from interface:WriteOrderDeque.WriteOrderSets the previous element or null if there is no link.- Specified by:
setPreviousInWriteOrderin interfaceWriteOrderDeque.WriteOrder<K>
-
getNextInWriteOrder
public @Nullable Node<K,V> getNextInWriteOrder()
Description copied from interface:WriteOrderDeque.WriteOrderRetrieves the next element or null if either the element is unlinked or the last element on the deque.- Specified by:
getNextInWriteOrderin interfaceWriteOrderDeque.WriteOrder<K>
-
setNextInWriteOrder
public void setNextInWriteOrder(@Nullable Node<K,V> next)
Description copied from interface:WriteOrderDeque.WriteOrderSets the next element or null if there is no link.- Specified by:
setNextInWriteOrderin interfaceWriteOrderDeque.WriteOrder<K>
-
toString
public final java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-