Package org.cache2k.core.eviction
Class DelegatingEviction
- java.lang.Object
-
- org.cache2k.core.eviction.DelegatingEviction
-
- All Implemented Interfaces:
NeedsClose,Eviction
- Direct Known Subclasses:
IdleScanEviction
public abstract class DelegatingEviction extends Object implements Eviction
Delegates all eviction interaction.- Author:
- Jens Wilke
-
-
Constructor Summary
Constructors Constructor Description DelegatingEviction()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidchangeCapacity(long entryCountOrWeight)Change the capacity.voidcheckIntegrity(IntegrityState integrityState)voidclose(InternalCacheCloseContext closeContext)protected abstract Evictiondelegate()voidevictEventually()Evict if needed, checks all segments.voidevictEventuallyBeforeInsert()Evict if needed, checks all segments.voidevictEventuallyBeforeInsertOnSegment(int hashCodeHint)Evict if needed, focused on the segment addressed by the hash code.longevictIdleEntries(int maxScan)Scan for idle (no access count since last scan) entries and evict them.EvictionMetricsgetMetrics()Get metrics related to the eviction.booleanisWeigherPresent()longremoveAll()Remove all entries from the eviction data structure.<T> TrunLocked(Supplier<T> j)Runs job making sure concurrent evictions operations pause.longstartNewIdleScanRound()Start new idle scan round and return current scan counterbooleansubmitWithoutTriggeringEviction(Entry e)Submit to eviction for inserting or removing from the replacement list.StringtoString()booleanupdateWeight(Entry e)Updates the weight on the entry and recalculates the total weight if needed.
-
-
-
Method Detail
-
delegate
protected abstract Eviction delegate()
-
startNewIdleScanRound
public long startNewIdleScanRound()
Description copied from interface:EvictionStart new idle scan round and return current scan counter- Specified by:
startNewIdleScanRoundin interfaceEviction- See Also:
IdleScan
-
close
public void close(InternalCacheCloseContext closeContext)
- Specified by:
closein interfaceNeedsClose
-
submitWithoutTriggeringEviction
public boolean submitWithoutTriggeringEviction(Entry e)
Description copied from interface:EvictionSubmit to eviction for inserting or removing from the replacement list. However, eviction should not be triggered (which in turn triggers a hash table update) since the hash segment lock is hold at the moment.- Specified by:
submitWithoutTriggeringEvictionin interfaceEviction
-
updateWeight
public boolean updateWeight(Entry e)
Description copied from interface:EvictionUpdates the weight on the entry and recalculates the total weight if needed.Expected not to hold the entry lock, which means, that this does not run in sync with the actual update. That is okay as long as it runs after every update.
Since we need to lock the eviction structure, this can happen in a separate thread.
- Specified by:
updateWeightin interfaceEviction- Returns:
- hint whether eviction should be run. for a bulk operation we want to do eviction once, so not do it within this method
-
evictEventuallyBeforeInsertOnSegment
public void evictEventuallyBeforeInsertOnSegment(int hashCodeHint)
Description copied from interface:EvictionEvict if needed, focused on the segment addressed by the hash code. Called before a new entry is inserted (changed from after in v1.4)- Specified by:
evictEventuallyBeforeInsertOnSegmentin interfaceEviction
-
evictEventuallyBeforeInsert
public void evictEventuallyBeforeInsert()
Description copied from interface:EvictionEvict if needed, checks all segments. Called before a new entry is inserted (changed from after in v1.4)- Specified by:
evictEventuallyBeforeInsertin interfaceEviction
-
evictEventually
public void evictEventually()
Description copied from interface:EvictionEvict if needed, checks all segments.- Specified by:
evictEventuallyin interfaceEviction
-
evictIdleEntries
public long evictIdleEntries(int maxScan)
Description copied from interface:EvictionScan for idle (no access count since last scan) entries and evict them.- Specified by:
evictIdleEntriesin interfaceEviction- Returns:
- number of evicted entries
- See Also:
IdleScan
-
removeAll
public long removeAll()
Description copied from interface:EvictionRemove all entries from the eviction data structure.
-
runLocked
public <T> T runLocked(Supplier<T> j)
Description copied from interface:EvictionRuns job making sure concurrent evictions operations pause.
-
checkIntegrity
public void checkIntegrity(IntegrityState integrityState)
- Specified by:
checkIntegrityin interfaceEviction
-
getMetrics
public EvictionMetrics getMetrics()
Description copied from interface:EvictionGet metrics related to the eviction. No lock is needed before calling this method. Best efforts are made to extract consistent statistics and keep interruption short.- Specified by:
getMetricsin interfaceEviction
-
isWeigherPresent
public boolean isWeigherPresent()
- Specified by:
isWeigherPresentin interfaceEviction
-
changeCapacity
public void changeCapacity(long entryCountOrWeight)
Description copied from interface:EvictionChange the capacity. If capacity is reduced, it will evict entries before returning.- Specified by:
changeCapacityin interfaceEviction
-
-