Package org.cache2k.core
Class Entry<K,V>
- java.lang.Object
-
- org.cache2k.core.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
CacheEntrydirectly 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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classEntry.ProcessingStateDifferent possible processing states.
-
Field Summary
Fields Modifier and Type Field Description static intABORTEDEntry<K,V>anotherHash implementation: Link to another entry in the same hash table slot when the hash code collides.static intDATA_VALIDbigger or equal means entry has / contains valid datastatic intEXPIREDstatic intEXPIRED_REFRESH_PENDINGExpired, but protect entry from removal, since refresh is started.static intEXPIRED_REFRESHEDEntry is in refresh probation phasestatic intEXPIRY_TIME_MINA value greater as means it is a time value.static intGONEstatic intGONE_OTHERinthashCodeEither the spreaded hash code or the integer key in case keys are integers.longhitCntHit counter.protected static org.cache2k.core.CompactEntry.InitialValueInEntryNeverReturnedINITIAL_VALUEEntrynextLru list: pointer to next element or list headprotected longnextRefreshTimeContains the next time a refresh has to occur, or if no background refresh is configured, when the entry is expired.EntryprevLru list: pointer to previous element or list headstatic intREAD_NON_VALIDstatic intREMOVE_PENDINGCache.remove() operation received.static intVIRGIN
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description booleancheckAndSwitchProcessingState(int ps0, int ps)Check and switch the processing state atomically.static booleancheckCyclicListIntegrity(Entry e)voidensureAbort(boolean finished)Make sure entry processing is properly finished, otherwise threads waiting for an entry get stuck.booleanequalsValue(V v)intgetCompressedWeight()static intgetCyclicListEntryCount(Entry e)EntryActiongetEntryAction()org.cache2k.io.LoadExceptionInfo<K,V>getExceptionInfo()longgetExpiryTime()org.cache2k.CacheEntry<K,V>getInspectionEntry()Used as current entry for expiry policy, loader or resilience policy suppress.KgetKey()KgetKeyObj()Get the raw object reference.longgetModificationTime()longgetNextRefreshTime()<X> XgetPiggyBack(Class<X> type)intgetProcessingState()longgetRefreshProbationNextRefreshTime()org.cache2k.io.LoadExceptionInfogetSuppressedLoadExceptionInformation()TimerTaskgetTask()VgetValue()Deprecated.longgetValueExpiryTime()Expiry time or 0.ObjectgetValueOrException()The value of the entry or anExceptionWrapper.booleanhasException()booleanhasFreshData(org.cache2k.operation.TimeReference t)Entry has a valid value and is fresh / not expired.static voidinsertInList(Entry head, Entry e)static <E extends Entry>
EinsertIntoTailCyclicList(E head, E e)booleanisDataAvailable()The entry value was fetched and is valid, which means it can be returned by the cache.booleanisDataAvailableOrProbation()booleanisExpiredState()The entry expired, still in the cache and subject to removal from the cache ifHeapCache.isKeepAfterExpired()is false.booleanisGettingRefresh()booleanisGone()The entry is not present in the heap any more and was evicted, expired or removed.booleanisHot()booleanisNotYetInsertedInReplacementList()Entry was not inserted into the replacement list AND not removed from replacement list.booleanisProcessing()booleanisRemovedFromReplacementList()Check that this entry is removed from the list, may be used in assertions.booleanisValidOrExpiredAndNoException()Use this entry as currentEntry in expiry policy, loader and resilience policybooleanisVirgin()Initial state of an entry.booleanneedsTimeCheck()static booleanneedsTimeCheck(long nextRefreshTime)voidnextProcessingStep(int ps)Switch to another processing state that is other then done.static Stringnum2processingStateText(int ps)voidprocessingDone()voidprocessingDone(EntryAction action)Set processing state to done and notify all that wait for processing this entry.voidremovedFromList()Reset next as a marker forisRemovedFromReplacementList()static <E extends Entry>
EremoveFromCyclicList(E head, E e)static EntryremoveFromCyclicList(Entry e)static voidremoveFromList(Entry e)voidresetEntryAction()voidresetSuppressedLoadExceptionInformation()If the entry carries information about a suppressed exception, clear it.voidsetCompressedWeight(int v)Store weight as 16 bit floating point number.voidsetEntryAction(EntryAction action)voidsetGone()voidsetHot(boolean f)voidsetNextRefreshTime(long nextRefreshTime)voidsetRefreshProbationNextRefreshTime(long nrt)voidsetRefreshTime(long t)Set modification time and marks entry as dirty.voidsetSuppressedLoadExceptionInformation(org.cache2k.io.LoadExceptionInfo w)voidsetTask(TimerTask v)voidsetValueOrException(Object valueOrException)EntryshortCircuit()voidstartProcessing(int ps, EntryAction action)Starts long operation on entry.StringtoString()StringtoString(HeapCache c)voidwaitForProcessing()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.cache2k.core.operation.ExaminationEntry
getKey, getValueOrException
-
-
-
-
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
-
VIRGIN
public static final int VIRGIN
- See Also:
isVirgin(), Constant Field Values
-
READ_NON_VALID
public static final int READ_NON_VALID
- 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
-
ABORTED
public static final int ABORTED
- See Also:
- Constant Field Values
-
EXPIRED
public static final int EXPIRED
- See Also:
isExpiredState(), 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
-
GONE
public static final int GONE
- See Also:
isGone(), Constant Field Values
-
GONE_OTHER
public static final int GONE_OTHER
- 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
Either the spreaded hash code or the integer key in case keys are integers.- See Also:
HeapCache.spreadHash(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.
-
getModificationTime
public long getModificationTime()
- Specified by:
getModificationTimein interfaceExaminationEntry<K,V>
-
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:
getExpiryTimein interfaceExaminationEntry<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()
-
removedFromList
public final void removedFromList()
Reset next as a marker forisRemovedFromReplacementList()
-
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 ifHeapCache.isKeepAfterExpired()is false.truemeans that the expiry was detected by the cache. To find out whether the entry is valid and not expiredhasFreshData(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.
-
getTask
public TimerTask getTask()
-
getPiggyBack
public <X> X getPiggyBack(Class<X> type)
-
setTask
public void setTask(TimerTask v)
-
setEntryAction
public void setEntryAction(EntryAction action)
-
getEntryAction
public EntryAction getEntryAction()
-
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)
-
insertIntoTailCyclicList
public static <E extends Entry> E insertIntoTailCyclicList(E head, E e)
-
removeFromCyclicList
public static <E extends Entry> E removeFromCyclicList(E head, E 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:
getExceptionInfoin interfaceorg.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:
getValuein interfaceorg.cache2k.CacheEntry<K,V>
-
getValueOrException
public Object getValueOrException()
The value of the entry or anExceptionWrapper.
-
getKey
public K getKey()
- Specified by:
getKeyin interfaceorg.cache2k.CacheEntry<K,V>
-
getKeyObj
public K getKeyObj()
Get the raw object reference. Isnullfor theIntHeapCache.
-
-