Package org.cache2k.core
Class SegmentedEviction
- java.lang.Object
-
- org.cache2k.core.SegmentedEviction
-
- All Implemented Interfaces:
NeedsClose,Eviction
public class SegmentedEviction extends Object implements Eviction
Forwards eviction operations to segments based on the hash code.- Author:
- Jens Wilke
-
-
Constructor Summary
Constructors Constructor Description SegmentedEviction(Eviction[] segments)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidchangeCapacity(long entryCountOrWeight)Change the capacity.voidcheckIntegrity(IntegrityState integrityState)voidclose(InternalCacheCloseContext closeContext)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 all segments for idlers.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.
-
-
-
Constructor Detail
-
SegmentedEviction
public SegmentedEviction(Eviction[] segments)
-
-
Method Detail
-
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
-
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
-
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
-
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)
Scan all segments for idlers. Maybe a round robin approach is more efficient.- 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.
-
close
public void close(InternalCacheCloseContext closeContext)
- Specified by:
closein interfaceNeedsClose
-
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
-
-