Class Entry<K,​V>

  • All Implemented Interfaces:
    org.cache2k.CacheEntry<K,​V>, ExaminationEntry<K,​V>, org.cache2k.DataAware<K,​V>

    public class Entry<K,​V>
    extends Object
    implements ExaminationEntry<K,​V>
    The cache entry. This is a combined hash table entry with hashCode and and collision list (other field) and it contains a double linked list (next and previous) for the eviction algorithm.

    When an entry is present and its value is updated, the entry objects stays the same. The entry object is used for locking and coordination of all concurrent accesses to it.

    The entry is only used as CacheEntry directly and handed to the application when it is locked and the values are stable, that is for example when the loader is called.

    Author:
    Jens Wilke
    • Field Detail

      • EXPIRY_TIME_MIN

        public static final int EXPIRY_TIME_MIN
        A value greater as means it is a time value.
        See Also:
        Constant Field Values
      • DATA_VALID

        public static final int DATA_VALID
        bigger or equal means entry has / contains valid data
        See Also:
        Constant Field Values
      • REMOVE_PENDING

        public static final int REMOVE_PENDING
        Cache.remove() operation received. Needs to be send to storage.
        See Also:
        Constant Field Values
      • EXPIRED_REFRESH_PENDING

        public static final int EXPIRED_REFRESH_PENDING
        Expired, but protect entry from removal, since refresh is started.
        See Also:
        Constant Field Values
      • EXPIRED_REFRESHED

        public static final int EXPIRED_REFRESHED
        Entry is in refresh probation phase
        See Also:
        Constant Field Values
      • next

        public Entry next
        Lru list: pointer to next element or list head
      • prev

        public Entry prev
        Lru list: pointer to previous element or list head
      • INITIAL_VALUE

        protected static final org.cache2k.core.CompactEntry.InitialValueInEntryNeverReturned INITIAL_VALUE
      • nextRefreshTime

        protected volatile long nextRefreshTime
        Contains the next time a refresh has to occur, or if no background refresh is configured, when the entry is expired. Low values have a special meaning, see defined constants. Negative values means that we need to check against the wall clock.
      • hashCode

        public final int hashCode
        Hash implementation: the calculated, modified hash code, retrieved from the key when the entry is inserted in the cache
        See Also:
        HeapCache.modifiedHash(int)
      • another

        public Entry<K,​V> another
        Hash implementation: Link to another entry in the same hash table slot when the hash code collides.
      • hitCnt

        public long hitCnt
        Hit counter. Modified directly by heap cache and eviction algorithm.
        See Also:
        HeapCache.recordHit(Entry)
    • Constructor Detail

      • Entry

        public Entry​(K key,
                     int hashCode)
      • Entry

        public Entry()
    • Method Detail

      • getInspectionEntry

        public org.cache2k.CacheEntry<K,​V> getInspectionEntry()
        Used as current entry for expiry policy, loader or resilience policy suppress.
      • setRefreshTime

        public void setRefreshTime​(long t)
        Set modification time and marks entry as dirty. Bit 0 was used as dirty bit for the storage attachment. Not used at the moment.
      • num2processingStateText

        public static String num2processingStateText​(int ps)
      • getProcessingState

        public int getProcessingState()
      • checkAndSwitchProcessingState

        public boolean checkAndSwitchProcessingState​(int ps0,
                                                     int ps)
        Check and switch the processing state atomically.
      • startProcessing

        public void startProcessing​(int ps,
                                    EntryAction action)
        Starts long operation on entry. Pins the entry in the cache.
      • nextProcessingStep

        public void nextProcessingStep​(int ps)
        Switch to another processing state that is other then done.
      • processingDone

        public void processingDone​(EntryAction action)
        Set processing state to done and notify all that wait for processing this entry.
      • processingDone

        public void processingDone()
      • getNextRefreshTime

        public long getNextRefreshTime()
      • getExpiryTime

        public long getExpiryTime()
        Specified by:
        getExpiryTime in interface ExaminationEntry<K,​V>
        See Also:
        MutableCacheEntry.getExpiryTime()
      • setNextRefreshTime

        public void setNextRefreshTime​(long nextRefreshTime)
      • ensureAbort

        public void ensureAbort​(boolean finished)
        Make sure entry processing is properly finished, otherwise threads waiting for an entry get stuck.

        Usually no exceptions happens, but the CacheClosedException is happening out of order and stops processing to properly finish.

      • isProcessing

        public boolean isProcessing()
      • waitForProcessing

        public void waitForProcessing()
      • isGettingRefresh

        public boolean isGettingRefresh()
      • isRemovedFromReplacementList

        public boolean isRemovedFromReplacementList()
        Check that this entry is removed from the list, may be used in assertions.
      • isNotYetInsertedInReplacementList

        public boolean isNotYetInsertedInReplacementList()
        Entry was not inserted into the replacement list AND not removed from replacement list. In practise it may happen that an entry gets removed before even entering the replacement list, because of clear.
      • shortCircuit

        public Entry shortCircuit()
      • isVirgin

        public final boolean isVirgin()
        Initial state of an entry.
      • isDataAvailable

        public final boolean isDataAvailable()
        The entry value was fetched and is valid, which means it can be returned by the cache. If a valid entry gets removed from the cache the data is still valid. This is because a concurrent get needs to return the data. There is also the chance that an entry is removed by eviction, or is never inserted to the cache, before the get returns it.

        Even if this is true, the data may be expired. Use hasFreshData() to make sure to get not expired data.

      • isDataAvailableOrProbation

        public final boolean isDataAvailableOrProbation()
      • isValidOrExpiredAndNoException

        public final boolean isValidOrExpiredAndNoException()
        Use this entry as currentEntry in expiry policy, loader and resilience policy
      • hasFreshData

        public final boolean hasFreshData​(org.cache2k.operation.TimeReference t)
        Entry has a valid value and is fresh / not expired. This predicate may depend on the clock, if the expiry of an entry was not yet detected by the cache, e.g. the internal expiry event is not yet delivered.

        Logic duplicates in EntryAction.hasFreshData()

        See Also:
        EntryAction.hasFreshData()
      • isExpiredState

        public boolean isExpiredState()
        The entry expired, still in the cache and subject to removal from the cache if HeapCache.isKeepAfterExpired() is false. true means that the expiry was detected by the cache. To find out whether the entry is valid and not expired hasFreshData(TimeReference) needs to be used.
      • setGone

        public void setGone()
      • isGone

        public final boolean isGone()
        The entry is not present in the heap any more and was evicted, expired or removed.
      • needsTimeCheck

        public final boolean needsTimeCheck()
      • needsTimeCheck

        public static boolean needsTimeCheck​(long nextRefreshTime)
      • isHot

        public boolean isHot()
      • setHot

        public void setHot​(boolean f)
      • setCompressedWeight

        public void setCompressedWeight​(int v)
        Store weight as 16 bit floating point number.
      • getCompressedWeight

        public int getCompressedWeight()
      • getValueExpiryTime

        public long getValueExpiryTime()
        Expiry time or 0.
      • getPiggyBack

        public <X> X getPiggyBack​(Class<X> type)
      • setTask

        public void setTask​(TimerTask v)
      • setEntryAction

        public void setEntryAction​(EntryAction action)
      • resetEntryAction

        public void resetEntryAction()
      • setSuppressedLoadExceptionInformation

        public void setSuppressedLoadExceptionInformation​(org.cache2k.io.LoadExceptionInfo w)
      • resetSuppressedLoadExceptionInformation

        public void resetSuppressedLoadExceptionInformation()
        If the entry carries information about a suppressed exception, clear it.
      • getSuppressedLoadExceptionInformation

        public org.cache2k.io.LoadExceptionInfo getSuppressedLoadExceptionInformation()
      • setRefreshProbationNextRefreshTime

        public void setRefreshProbationNextRefreshTime​(long nrt)
      • getRefreshProbationNextRefreshTime

        public long getRefreshProbationNextRefreshTime()
      • removeFromList

        public static void removeFromList​(Entry e)
      • insertInList

        public static void insertInList​(Entry head,
                                        Entry e)
      • insertIntoTailCyclicList

        public static <E extends Entry> E insertIntoTailCyclicList​(E head,
                                                                   E e)
      • removeFromCyclicList

        public static <E extends Entry> E removeFromCyclicList​(E head,
                                                               E e)
      • removeFromCyclicList

        public static Entry removeFromCyclicList​(Entry e)
      • getCyclicListEntryCount

        public static int getCyclicListEntryCount​(Entry e)
      • checkCyclicListIntegrity

        public static boolean checkCyclicListIntegrity​(Entry e)
      • setValueOrException

        public void setValueOrException​(Object valueOrException)
      • getExceptionInfo

        public org.cache2k.io.LoadExceptionInfo<K,​V> getExceptionInfo()
        Specified by:
        getExceptionInfo in interface org.cache2k.CacheEntry<K,​V>
      • hasException

        public boolean hasException()
      • equalsValue

        public boolean equalsValue​(V v)
      • getValue

        @Deprecated
        public V getValue()
        Deprecated.
        Should never be called under normal circumstances. For efficiency reasons the entry is handed to the expiry policy directly, only in case its not an exception wrapper.
        Specified by:
        getValue in interface org.cache2k.CacheEntry<K,​V>
      • getKey

        public K getKey()
        Specified by:
        getKey in interface org.cache2k.CacheEntry<K,​V>
      • getKeyObj

        public K getKeyObj()
        Get the raw object reference. Is null for the IntHeapCache.