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
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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Entry.ProcessingState
Different possible processing states.
-
Field Summary
Fields Modifier and Type Field Description static int
ABORTED
Entry<K,V>
another
Hash implementation: Link to another entry in the same hash table slot when the hash code collides.static int
DATA_VALID
bigger or equal means entry has / contains valid datastatic int
EXPIRED
static int
EXPIRED_REFRESH_PENDING
Expired, but protect entry from removal, since refresh is started.static int
EXPIRED_REFRESHED
Entry is in refresh probation phasestatic int
EXPIRY_TIME_MIN
A value greater as means it is a time value.static int
GONE
static int
GONE_OTHER
int
hashCode
Hash implementation: the calculated, modified hash code, retrieved from the key when the entry is inserted in the cachelong
hitCnt
Hit counter.protected static org.cache2k.core.CompactEntry.InitialValueInEntryNeverReturned
INITIAL_VALUE
Entry
next
Lru list: pointer to next element or list headprotected long
nextRefreshTime
Contains the next time a refresh has to occur, or if no background refresh is configured, when the entry is expired.Entry
prev
Lru list: pointer to previous element or list headstatic int
READ_NON_VALID
static int
REMOVE_PENDING
Cache.remove() operation received.static int
VIRGIN
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description boolean
checkAndSwitchProcessingState(int ps0, int ps)
Check and switch the processing state atomically.static boolean
checkCyclicListIntegrity(Entry e)
void
ensureAbort(boolean finished)
Make sure entry processing is properly finished, otherwise threads waiting for an entry get stuck.boolean
equalsValue(V v)
int
getCompressedWeight()
static int
getCyclicListEntryCount(Entry e)
EntryAction
getEntryAction()
org.cache2k.io.LoadExceptionInfo<K,V>
getExceptionInfo()
long
getExpiryTime()
org.cache2k.CacheEntry<K,V>
getInspectionEntry()
Used as current entry for expiry policy, loader or resilience policy suppress.K
getKey()
K
getKeyObj()
Get the raw object reference.long
getModificationTime()
long
getNextRefreshTime()
<X> X
getPiggyBack(Class<X> type)
int
getProcessingState()
long
getRefreshProbationNextRefreshTime()
org.cache2k.io.LoadExceptionInfo
getSuppressedLoadExceptionInformation()
TimerTask
getTask()
V
getValue()
Deprecated.long
getValueExpiryTime()
Expiry time or 0.Object
getValueOrException()
The value of the entry or anExceptionWrapper
.boolean
hasException()
boolean
hasFreshData(org.cache2k.operation.TimeReference t)
Entry has a valid value and is fresh / not expired.static void
insertInList(Entry head, Entry e)
static <E extends Entry>
EinsertIntoTailCyclicList(E head, E e)
boolean
isDataAvailable()
The entry value was fetched and is valid, which means it can be returned by the cache.boolean
isDataAvailableOrProbation()
boolean
isExpiredState()
The entry expired, still in the cache and subject to removal from the cache ifHeapCache.isKeepAfterExpired()
is false.boolean
isGettingRefresh()
boolean
isGone()
The entry is not present in the heap any more and was evicted, expired or removed.boolean
isHot()
boolean
isNotYetInsertedInReplacementList()
Entry was not inserted into the replacement list AND not removed from replacement list.boolean
isProcessing()
boolean
isRemovedFromReplacementList()
Check that this entry is removed from the list, may be used in assertions.boolean
isValidOrExpiredAndNoException()
Use this entry as currentEntry in expiry policy, loader and resilience policyboolean
isVirgin()
Initial state of an entry.boolean
needsTimeCheck()
static boolean
needsTimeCheck(long nextRefreshTime)
void
nextProcessingStep(int ps)
Switch to another processing state that is other then done.static String
num2processingStateText(int ps)
void
processingDone()
void
processingDone(EntryAction action)
Set processing state to done and notify all that wait for processing this entry.void
removedFromList()
Reset next as a marker forisRemovedFromReplacementList()
static <E extends Entry>
EremoveFromCyclicList(E head, E e)
static Entry
removeFromCyclicList(Entry e)
static void
removeFromList(Entry e)
void
resetEntryAction()
void
resetSuppressedLoadExceptionInformation()
If the entry carries information about a suppressed exception, clear it.void
setCompressedWeight(int v)
Store weight as 16 bit floating point number.void
setEntryAction(EntryAction action)
void
setGone()
void
setHot(boolean f)
void
setNextRefreshTime(long nextRefreshTime)
void
setRefreshProbationNextRefreshTime(long nrt)
void
setRefreshTime(long t)
Set modification time and marks entry as dirty.void
setSuppressedLoadExceptionInformation(org.cache2k.io.LoadExceptionInfo w)
void
setTask(TimerTask v)
void
setValueOrException(Object valueOrException)
Entry
shortCircuit()
void
startProcessing(int ps, EntryAction action)
Starts long operation on entry.String
toString()
String
toString(HeapCache c)
void
waitForProcessing()
-
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
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.
-
getModificationTime
public long getModificationTime()
- Specified by:
getModificationTime
in 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:
getExpiryTime
in 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.true
means 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:
getExceptionInfo
in 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:
getValue
in interfaceorg.cache2k.CacheEntry<K,V>
-
getValueOrException
public Object getValueOrException()
The value of the entry or anExceptionWrapper
.
-
getKey
public K getKey()
- Specified by:
getKey
in interfaceorg.cache2k.CacheEntry<K,V>
-
getKeyObj
public K getKeyObj()
Get the raw object reference. Isnull
for theIntHeapCache
.
-
-