Package org.cache2k.core
Class SegmentedEviction
- java.lang.Object
-
- org.cache2k.core.SegmentedEviction
-
-
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()Free resources, for example thread pool or queue.booleandrain()Drain eviction queue and do updates in the eviction data structures.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.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.voidstart()Start concurrent eviction threads.voidstop()Stop concurrent threads that may access the eviction data structures.booleansubmitWithoutTriggeringEviction(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
-
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
-
removeAll
public long removeAll()
Description copied from interface:EvictionRemove all entries from the eviction data structure.
-
start
public void start()
Description copied from interface:EvictionStart concurrent eviction threads.
-
stop
public void stop()
Description copied from interface:EvictionStop concurrent threads that may access the eviction data structures. Needs to be called before checkIntegrity or accessing the counter values.
-
close
public void close()
Description copied from interface:EvictionFree resources, for example thread pool or queue.
-
drain
public boolean drain()
Description copied from interface:EvictionDrain eviction queue and do updates in the eviction data structures. Does no eviction when size limit is reached.
-
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 mad to extract consistent statistics and 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
-
-