Class ClockPolicy.Holder
- java.lang.Object
-
- org.apache.derby.impl.services.cache.ClockPolicy.Holder
-
- All Implemented Interfaces:
ReplacementPolicy.Callback
- Enclosing class:
- ClockPolicy
private class ClockPolicy.Holder extends java.lang.Object implements ReplacementPolicy.Callback
Holder class which represents an entry in the cache. It maintains arecentlyUsedrequired by the clock algorithm. The class also implements theCallbackinterface, so thatConcurrentCachecan notify the clock policy about events relevant to the clock algorithm.
-
-
Field Summary
Fields Modifier and Type Field Description private CacheEntryentryReference to theCacheEntryobject held by this object.private booleanevictedFlag which tells whether this holder has been evicted from the clock.private CacheablefreedCacheableCacheable object from a removed object.(package private) booleanrecentlyUsedFlag indicating whether or not this entry has been accessed recently.
-
Constructor Summary
Constructors Constructor Description Holder(CacheEntry e)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaccess()Mark this entry as recently used.(package private) booleanevictIfFree()Evict this holder from the clock if it is not associated with an entry.voidfree()Mark this object as free and reusable.(package private) CacheEntrygetEntry()Returns the entry that is currently associated with this holder.(package private) booleanisEvicted()Check whether this holder has been evicted from the clock.(package private) voidsetEvicted()Mark this holder as evicted from the clock, effectively preventing reuse of the holder.(package private) voidswitchEntry(CacheEntry e)Switch which entry the holder is associated with.(package private) booleantakeIfFree(CacheEntry e)Associate this holder with the specified entry if the holder is free (that is, not associated with any other entry).
-
-
-
Field Detail
-
recentlyUsed
boolean recentlyUsed
Flag indicating whether or not this entry has been accessed recently. Should only be accessed/modified when the current thread has locked theCacheEntryobject stored in theentryfield.
-
entry
private CacheEntry entry
Reference to theCacheEntryobject held by this object. The reference should only be accessed when the thread owns the monitor on this holder. A thread is only allowed to change the reference if it also has locked the entry that the reference points to (if the reference is non-null). This ensures that no other thread can disassociate a holder from its entry while the entry is locked, even though the monitor on the holder has been released.
-
freedCacheable
private Cacheable freedCacheable
Cacheable object from a removed object. If this object is non-null,entrymust benull(which means that the holder is not associated with any object in the cache).
-
evicted
private boolean evicted
Flag which tells whether this holder has been evicted from the clock. If it has been evicted, it can't be reused when a new entry is inserted. Only the owner of this holder's monitor is allowed to access this variable.
-
-
Constructor Detail
-
Holder
Holder(CacheEntry e)
-
-
Method Detail
-
access
public void access()
Mark this entry as recently used. Caller must have lockedentry.- Specified by:
accessin interfaceReplacementPolicy.Callback
-
free
public void free()
Mark this object as free and reusable. Caller must have lockedentry.- Specified by:
freein interfaceReplacementPolicy.Callback
-
takeIfFree
boolean takeIfFree(CacheEntry e)
Associate this holder with the specified entry if the holder is free (that is, not associated with any other entry).- Parameters:
e- the entry to associate the holder with (it must be locked by the current thread)- Returns:
trueif the holder has been associated with the specified entry,falseif someone else has taken it or the holder has been evicted from the clock
-
getEntry
CacheEntry getEntry()
Returns the entry that is currently associated with this holder.- Returns:
- the associated entry
-
switchEntry
void switchEntry(CacheEntry e)
Switch which entry the holder is associated with. Will be called when we evict an entry to make room for a new one. When this method is called, the current thread must have locked both the entry that is evicted and the entry that is inserted.- Parameters:
e- the entry to associate this holder with
-
evictIfFree
boolean evictIfFree()
Evict this holder from the clock if it is not associated with an entry.- Returns:
trueif the holder was successfully evicted,falseotherwise
-
setEvicted
void setEvicted()
Mark this holder as evicted from the clock, effectively preventing reuse of the holder. Calling thread must have locked the holder's entry.
-
isEvicted
boolean isEvicted()
Check whether this holder has been evicted from the clock.- Returns:
trueif it has been evicted,falseotherwise
-
-