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>>
Direct Known Subclasses:
FD, FS, FW, PD, PS, PW, TimerWheel.Sentinel

abstract class Node<K,V> extends 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.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
     
    static final int
     
    static final int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    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.
    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.
    abstract boolean
    containsValue(@NonNull Object value)
    Returns true if the given objects are considered equivalent.
    abstract void
    die()
    Sets the node to the dead state.
    long
    Returns the time that this entry was last accessed, in ns.
    abstract @Nullable K
    Return the key or null if it has been reclaimed by the garbage collector.
    abstract @NonNull Object
    Returns the reference that the cache is holding the entry by.
    @Nullable Node<K,V>
    Retrieves the next element or null if either the element is unlinked or the last element on the deque.
     
    @Nullable Node<K,V>
    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 int
    Returns the weight of this entry from the policy's perspective.
    @Nullable Node<K,V>
    Retrieves the previous element or null if either the element is unlinked or the first element on the deque.
     
    @Nullable Node<K,V>
    Retrieves the previous element or null if either the element is unlinked or the first element on the deque.
    int
    Returns the queue that the entry's resides in (window, probation, or protected).
    abstract @Nullable V
    Return the value or null if it has been reclaimed by the garbage collector.
    abstract @NonNull Object
    Returns the reference to the value.
    long
    Returns the variable expiration time, in nanoseconds.
    @org.checkerframework.checker.index.qual.NonNegative int
    Returns the weight of this entry from the entry's perspective.
    long
    Returns the time that this entry was last written, in ns.
    boolean
    Returns if the entry is in the Main space's probation queue.
    boolean
    Returns if the entry is in the Main space's protected queue.
    boolean
    Returns if the entry is in the Window or Main space.
    abstract boolean
    If the entry is available in the hash-table and page replacement policy.
    abstract boolean
    If the entry was removed from the hash-table and the page replacement policy.
    abstract boolean
    If the entry was removed from the hash-table and is awaiting removal from the page replacement policy.
    void
    Sets the status to the Main space's probation queue.
    void
    Sets the status to the Main space's protected queue.
    void
    Sets the status to the Window queue.
    abstract void
    Sets the node to the retired state.
    void
    setAccessTime(long time)
    Sets the access time in nanoseconds.
    void
    setNextInAccessOrder(@Nullable Node<K,V> next)
    Sets the next element or null if there is no link.
    void
    setNextInVariableOrder(@Nullable Node<K,V> prev)
     
    void
    setNextInWriteOrder(@Nullable Node<K,V> next)
    Sets the next element or null if there is no link.
    void
    setPolicyWeight(@org.checkerframework.checker.index.qual.NonNegative int weight)
    Sets the weight from the policy's perspective.
    void
    setPreviousInAccessOrder(@Nullable Node<K,V> prev)
    Sets the previous element or null if there is no link.
    void
     
    void
    setPreviousInWriteOrder(@Nullable Node<K,V> prev)
    Sets the previous element or null if there is no link.
    void
    setQueueType(int queueType)
    Set queue that the entry resides in (window, probation, or protected).
    abstract void
    setValue(@NonNull V value, @Nullable ReferenceQueue<V> referenceQueue)
    Sets the value, which may be held strongly, weakly, or softly.
    void
    setVariableTime(long time)
    Sets the variable expiration time in nanoseconds.
    void
    setWeight(@org.checkerframework.checker.index.qual.NonNegative int weight)
    Sets the weight from the entry's perspective.
    void
    setWriteTime(long time)
    Sets the write time in nanoseconds.
    final String
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

  • Constructor Details

    • Node

      Node()
  • Method Details

    • getKey

      public abstract @Nullable K getKey()
      Return the key or null if it has been reclaimed by the garbage collector.
    • getKeyReference

      public abstract @NonNull Object getKeyReference()
      Returns the reference that the cache is holding the entry by. This is either the key if strongly held or a WeakReference to that key.
    • getValue

      public abstract @Nullable V getValue()
      Return the value or null if it has been reclaimed by the garbage collector.
    • getValueReference

      public abstract @NonNull Object getValueReference()
      Returns the reference to the value. This is either the value if strongly held or a Reference to that value.
    • setValue

      public abstract void setValue(@NonNull V value, @Nullable 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 Object value)
      Returns true if 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.
    • getPreviousInVariableOrder

      public Node<K,V> getPreviousInVariableOrder()
    • setPreviousInVariableOrder

      public void setPreviousInVariableOrder(@Nullable Node<K,V> prev)
    • getNextInVariableOrder

      public Node<K,V> getNextInVariableOrder()
    • setNextInVariableOrder

      public void setNextInVariableOrder(@Nullable Node<K,V> prev)
    • 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.AccessOrder
      Retrieves the previous element or null if either the element is unlinked or the first element on the deque.
      Specified by:
      getPreviousInAccessOrder in interface AccessOrderDeque.AccessOrder<K>
    • setPreviousInAccessOrder

      public void setPreviousInAccessOrder(@Nullable Node<K,V> prev)
      Description copied from interface: AccessOrderDeque.AccessOrder
      Sets the previous element or null if there is no link.
      Specified by:
      setPreviousInAccessOrder in interface AccessOrderDeque.AccessOrder<K>
    • getNextInAccessOrder

      public @Nullable Node<K,V> getNextInAccessOrder()
      Description copied from interface: AccessOrderDeque.AccessOrder
      Retrieves the next element or null if either the element is unlinked or the last element on the deque.
      Specified by:
      getNextInAccessOrder in interface AccessOrderDeque.AccessOrder<K>
    • setNextInAccessOrder

      public void setNextInAccessOrder(@Nullable Node<K,V> next)
      Description copied from interface: AccessOrderDeque.AccessOrder
      Sets the next element or null if there is no link.
      Specified by:
      setNextInAccessOrder in interface AccessOrderDeque.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.WriteOrder
      Retrieves the previous element or null if either the element is unlinked or the first element on the deque.
      Specified by:
      getPreviousInWriteOrder in interface WriteOrderDeque.WriteOrder<K>
    • setPreviousInWriteOrder

      public void setPreviousInWriteOrder(@Nullable Node<K,V> prev)
      Description copied from interface: WriteOrderDeque.WriteOrder
      Sets the previous element or null if there is no link.
      Specified by:
      setPreviousInWriteOrder in interface WriteOrderDeque.WriteOrder<K>
    • getNextInWriteOrder

      public @Nullable Node<K,V> getNextInWriteOrder()
      Description copied from interface: WriteOrderDeque.WriteOrder
      Retrieves the next element or null if either the element is unlinked or the last element on the deque.
      Specified by:
      getNextInWriteOrder in interface WriteOrderDeque.WriteOrder<K>
    • setNextInWriteOrder

      public void setNextInWriteOrder(@Nullable Node<K,V> next)
      Description copied from interface: WriteOrderDeque.WriteOrder
      Sets the next element or null if there is no link.
      Specified by:
      setNextInWriteOrder in interface WriteOrderDeque.WriteOrder<K>
    • toString

      public final String toString()
      Overrides:
      toString in class Object