Package org.cache2k.core
Class SegmentedEviction
- java.lang.Object
-
- org.cache2k.core.SegmentedEviction
-
- All Implemented Interfaces:
Eviction
,EvictionMetrics
public class SegmentedEviction extends Object implements Eviction, EvictionMetrics
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 void
changeCapacity(long entryCountOrWeight)
Change the capacity.void
checkIntegrity(IntegrityState integrityState)
void
close()
Free resources, for example thread pool or queue.boolean
drain()
Drain eviction queue and do updates in the eviction data structures.void
evictEventually()
Evict if needed, checks all segments.void
evictEventuallyBeforeInsert()
Evict if needed, checks all segments.void
evictEventuallyBeforeInsertOnSegment(int hashCodeHint)
Evict if needed, focused on the segment addressed by the hash code.long
getEvictedCount()
Number of entries evictedlong
getEvictedWeight()
Accumulated weight of evicted or deleted entriesint
getEvictionRunningCount()
Number of eviction currently going onlong
getExpiredRemovedCount()
Removed entries, because expiredString
getExtraStatistics()
Fragment that the eviction wants to add to theCache.toString()
output.long
getHitCount()
Number of recorded hits.long
getMaxSize()
Size limit after eviction kicks inlong
getMaxWeight()
EvictionMetrics
getMetrics()
long
getNewEntryCount()
long
getRemovedCount()
long
getSize()
Number of entries in the eviction data structurelong
getTotalWeight()
Accumulated weight of all entries currently controlled by eviction.long
getVirginRemovedCount()
Removal of an entry that was never usedboolean
isWeigherPresent()
long
removeAll()
Remove all entries from the eviction data structure.<T> T
runLocked(Supplier<T> j)
Runs job making sure concurrent evictions operations pause.void
start()
Start concurrent eviction threads.void
stop()
Stop concurrent threads that may access the eviction data structures.boolean
submitWithoutTriggeringEviction(Entry e)
Submit to eviction for inserting or removing from the replacement list.boolean
updateWeight(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:Eviction
Updates 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 its runs after every update.
Since we need to lock the eviction structure, this could happen async in a separate thread.
- Specified by:
updateWeight
in interfaceEviction
- Returns:
- hint whether eviction should be run. for bulk operations do eviction once. so not do it within this method
-
submitWithoutTriggeringEviction
public boolean submitWithoutTriggeringEviction(Entry e)
Description copied from interface:Eviction
Submit 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:
submitWithoutTriggeringEviction
in interfaceEviction
-
evictEventuallyBeforeInsertOnSegment
public void evictEventuallyBeforeInsertOnSegment(int hashCodeHint)
Description copied from interface:Eviction
Evict 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:
evictEventuallyBeforeInsertOnSegment
in interfaceEviction
-
evictEventuallyBeforeInsert
public void evictEventuallyBeforeInsert()
Description copied from interface:Eviction
Evict if needed, checks all segments. Called before a new entry is inserted (changed from after in v1.4)- Specified by:
evictEventuallyBeforeInsert
in interfaceEviction
-
evictEventually
public void evictEventually()
Description copied from interface:Eviction
Evict if needed, checks all segments.- Specified by:
evictEventually
in interfaceEviction
-
removeAll
public long removeAll()
Description copied from interface:Eviction
Remove all entries from the eviction data structure.
-
start
public void start()
Description copied from interface:Eviction
Start concurrent eviction threads.
-
stop
public void stop()
Description copied from interface:Eviction
Stop 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:Eviction
Free resources, for example thread pool or queue.
-
drain
public boolean drain()
Description copied from interface:Eviction
Drain 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:Eviction
Runs job making sure concurrent evictions operations pause.
-
checkIntegrity
public void checkIntegrity(IntegrityState integrityState)
- Specified by:
checkIntegrity
in interfaceEviction
-
getMetrics
public EvictionMetrics getMetrics()
- Specified by:
getMetrics
in interfaceEviction
-
getExtraStatistics
public String getExtraStatistics()
Description copied from interface:EvictionMetrics
Fragment that the eviction wants to add to theCache.toString()
output.- Specified by:
getExtraStatistics
in interfaceEvictionMetrics
-
getHitCount
public long getHitCount()
Description copied from interface:EvictionMetrics
Number of recorded hits.- Specified by:
getHitCount
in interfaceEvictionMetrics
-
getNewEntryCount
public long getNewEntryCount()
- Specified by:
getNewEntryCount
in interfaceEvictionMetrics
- See Also:
InternalCacheInfo.getNewEntryCount()
-
getRemovedCount
public long getRemovedCount()
- Specified by:
getRemovedCount
in interfaceEvictionMetrics
- See Also:
InternalCacheInfo.getRemoveCount()
-
getExpiredRemovedCount
public long getExpiredRemovedCount()
Description copied from interface:EvictionMetrics
Removed entries, because expired- Specified by:
getExpiredRemovedCount
in interfaceEvictionMetrics
- See Also:
InternalCacheInfo.getExpiredCount()
-
getVirginRemovedCount
public long getVirginRemovedCount()
Description copied from interface:EvictionMetrics
Removal of an entry that was never used- Specified by:
getVirginRemovedCount
in interfaceEvictionMetrics
-
getEvictedCount
public long getEvictedCount()
Description copied from interface:EvictionMetrics
Number of entries evicted- Specified by:
getEvictedCount
in interfaceEvictionMetrics
- See Also:
InternalCacheInfo.getEvictedCount()
-
getSize
public long getSize()
Description copied from interface:EvictionMetrics
Number of entries in the eviction data structure- Specified by:
getSize
in interfaceEvictionMetrics
-
getMaxSize
public long getMaxSize()
Description copied from interface:EvictionMetrics
Size limit after eviction kicks in- Specified by:
getMaxSize
in interfaceEvictionMetrics
-
getMaxWeight
public long getMaxWeight()
- Specified by:
getMaxWeight
in interfaceEvictionMetrics
-
getTotalWeight
public long getTotalWeight()
Description copied from interface:EvictionMetrics
Accumulated weight of all entries currently controlled by eviction.- Specified by:
getTotalWeight
in interfaceEvictionMetrics
-
getEvictionRunningCount
public int getEvictionRunningCount()
Description copied from interface:EvictionMetrics
Number of eviction currently going on- Specified by:
getEvictionRunningCount
in interfaceEvictionMetrics
-
getEvictedWeight
public long getEvictedWeight()
Description copied from interface:EvictionMetrics
Accumulated weight of evicted or deleted entries- Specified by:
getEvictedWeight
in interfaceEvictionMetrics
-
isWeigherPresent
public boolean isWeigherPresent()
- Specified by:
isWeigherPresent
in interfaceEviction
-
changeCapacity
public void changeCapacity(long entryCountOrWeight)
Description copied from interface:Eviction
Change the capacity. If capacity is reduced, it will evict entries before returning.- Specified by:
changeCapacity
in interfaceEviction
-
-