Package io.debezium.util
Class BoundedConcurrentHashMap.LRU<K,V>
- java.lang.Object
-
- java.util.AbstractMap<K,V>
-
- java.util.HashMap<K,V>
-
- java.util.LinkedHashMap<BoundedConcurrentHashMap.HashEntry<K,V>,V>
-
- io.debezium.util.BoundedConcurrentHashMap.LRU<K,V>
-
- All Implemented Interfaces:
BoundedConcurrentHashMap.EvictionPolicy<K,V>,Serializable,Cloneable,Map<BoundedConcurrentHashMap.HashEntry<K,V>,V>
- Enclosing class:
- BoundedConcurrentHashMap<K,V>
static final class BoundedConcurrentHashMap.LRU<K,V> extends LinkedHashMap<BoundedConcurrentHashMap.HashEntry<K,V>,V> implements BoundedConcurrentHashMap.EvictionPolicy<K,V>
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object,V extends Object>
-
-
Field Summary
Fields Modifier and Type Field Description private ConcurrentLinkedQueue<BoundedConcurrentHashMap.HashEntry<K,V>>accessQueueprivate floatbatchThresholdFactorprivate Set<BoundedConcurrentHashMap.HashEntry<K,V>>evictedprivate intmaxBatchQueueSizeprivate BoundedConcurrentHashMap.Segment<K,V>segmentprivate static longserialVersionUIDThe serialVersionUIDprivate inttrimDownSize-
Fields inherited from interface io.debezium.util.BoundedConcurrentHashMap.EvictionPolicy
MAX_BATCH_SIZE
-
-
Constructor Summary
Constructors Constructor Description LRU(BoundedConcurrentHashMap.Segment<K,V> s, int capacity, float lf, int maxBatchSize, float batchThresholdFactor)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Invoked to notify EvictionPolicy implementation that all Segment entries have been cleared.BoundedConcurrentHashMap.HashEntry<K,V>createNewEntry(K key, int hash, BoundedConcurrentHashMap.HashEntry<K,V> next, V value)Set<BoundedConcurrentHashMap.HashEntry<K,V>>execute()Invokes eviction policy algorithm and returns set of evicted entries.protected booleanisAboveThreshold()booleanonEntryHit(BoundedConcurrentHashMap.HashEntry<K,V> e)Invoked to notify EvictionPolicy implementation that an entry in Segment has been accessed.Set<BoundedConcurrentHashMap.HashEntry<K,V>>onEntryMiss(BoundedConcurrentHashMap.HashEntry<K,V> e)Invoked to notify EvictionPolicy implementation that there has been an attempt to access an entry in Segment, however that entry was not present in Segment.voidonEntryRemove(BoundedConcurrentHashMap.HashEntry<K,V> e)Invoked to notify EvictionPolicy implementation that an entry e has been removed from Segment.protected booleanremoveEldestEntry(Map.Entry<BoundedConcurrentHashMap.HashEntry<K,V>,V> eldest)BoundedConcurrentHashMap.Evictionstrategy()Returns type of eviction algorithm (strategy).booleanthresholdExpired()Returns true if batching threshold has expired, false otherwise.-
Methods inherited from class java.util.LinkedHashMap
containsValue, entrySet, forEach, get, getOrDefault, keySet, replaceAll, values
-
Methods inherited from class java.util.HashMap
clone, compute, computeIfAbsent, computeIfPresent, containsKey, isEmpty, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, size
-
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, containsKey, equals, hashCode, isEmpty, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, size
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
The serialVersionUID- See Also:
- Constant Field Values
-
accessQueue
private final ConcurrentLinkedQueue<BoundedConcurrentHashMap.HashEntry<K,V>> accessQueue
-
segment
private final BoundedConcurrentHashMap.Segment<K,V> segment
-
maxBatchQueueSize
private final int maxBatchQueueSize
-
trimDownSize
private final int trimDownSize
-
batchThresholdFactor
private final float batchThresholdFactor
-
evicted
private final Set<BoundedConcurrentHashMap.HashEntry<K,V>> evicted
-
-
Constructor Detail
-
LRU
public LRU(BoundedConcurrentHashMap.Segment<K,V> s, int capacity, float lf, int maxBatchSize, float batchThresholdFactor)
-
-
Method Detail
-
execute
public Set<BoundedConcurrentHashMap.HashEntry<K,V>> execute()
Description copied from interface:BoundedConcurrentHashMap.EvictionPolicyInvokes eviction policy algorithm and returns set of evicted entries. Set cannot be null but could possibly be an empty set.- Specified by:
executein interfaceBoundedConcurrentHashMap.EvictionPolicy<K,V>- Returns:
- set of evicted entries.
-
onEntryMiss
public Set<BoundedConcurrentHashMap.HashEntry<K,V>> onEntryMiss(BoundedConcurrentHashMap.HashEntry<K,V> e)
Description copied from interface:BoundedConcurrentHashMap.EvictionPolicyInvoked to notify EvictionPolicy implementation that there has been an attempt to access an entry in Segment, however that entry was not present in Segment.- Specified by:
onEntryMissin interfaceBoundedConcurrentHashMap.EvictionPolicy<K,V>- Parameters:
e- accessed entry in Segment- Returns:
- non null set of evicted entries.
-
onEntryHit
public boolean onEntryHit(BoundedConcurrentHashMap.HashEntry<K,V> e)
Description copied from interface:BoundedConcurrentHashMap.EvictionPolicyInvoked to notify EvictionPolicy implementation that an entry in Segment has been accessed. Returns true if batching threshold has been reached, false otherwise. Note that this method is potentially invoked without holding a lock on Segment.- Specified by:
onEntryHitin interfaceBoundedConcurrentHashMap.EvictionPolicy<K,V>- Parameters:
e- accessed entry in Segment- Returns:
- true if batching threshold has been reached, false otherwise.
-
thresholdExpired
public boolean thresholdExpired()
Description copied from interface:BoundedConcurrentHashMap.EvictionPolicyReturns true if batching threshold has expired, false otherwise. Note that this method is potentially invoked without holding a lock on Segment.- Specified by:
thresholdExpiredin interfaceBoundedConcurrentHashMap.EvictionPolicy<K,V>- Returns:
- true if batching threshold has expired, false otherwise.
-
onEntryRemove
public void onEntryRemove(BoundedConcurrentHashMap.HashEntry<K,V> e)
Description copied from interface:BoundedConcurrentHashMap.EvictionPolicyInvoked to notify EvictionPolicy implementation that an entry e has been removed from Segment.- Specified by:
onEntryRemovein interfaceBoundedConcurrentHashMap.EvictionPolicy<K,V>- Parameters:
e- removed entry in Segment
-
clear
public void clear()
Description copied from interface:BoundedConcurrentHashMap.EvictionPolicyInvoked to notify EvictionPolicy implementation that all Segment entries have been cleared.- Specified by:
clearin interfaceBoundedConcurrentHashMap.EvictionPolicy<K,V>- Specified by:
clearin interfaceMap<K,V>- Overrides:
clearin classLinkedHashMap<BoundedConcurrentHashMap.HashEntry<K,V>,V>
-
strategy
public BoundedConcurrentHashMap.Eviction strategy()
Description copied from interface:BoundedConcurrentHashMap.EvictionPolicyReturns type of eviction algorithm (strategy).- Specified by:
strategyin interfaceBoundedConcurrentHashMap.EvictionPolicy<K,V>- Returns:
- type of eviction algorithm
-
isAboveThreshold
protected boolean isAboveThreshold()
-
removeEldestEntry
protected boolean removeEldestEntry(Map.Entry<BoundedConcurrentHashMap.HashEntry<K,V>,V> eldest)
- Overrides:
removeEldestEntryin classLinkedHashMap<BoundedConcurrentHashMap.HashEntry<K,V>,V>
-
createNewEntry
public BoundedConcurrentHashMap.HashEntry<K,V> createNewEntry(K key, int hash, BoundedConcurrentHashMap.HashEntry<K,V> next, V value)
- Specified by:
createNewEntryin interfaceBoundedConcurrentHashMap.EvictionPolicy<K,V>
-
-