Package io.debezium.util
Class BoundedConcurrentHashMap.Segment<K,V>
- java.lang.Object
-
- java.util.concurrent.locks.ReentrantLock
-
- io.debezium.util.BoundedConcurrentHashMap.Segment<K,V>
-
- All Implemented Interfaces:
Serializable,Lock
- Enclosing class:
- BoundedConcurrentHashMap<K,V>
static final class BoundedConcurrentHashMap.Segment<K,V> extends ReentrantLock
Segments are specialized versions of hash tables. This subclasses from ReentrantLock opportunistically, just to simplify some locking and avoid separate construction.
-
-
Field Summary
Fields Modifier and Type Field Description (package private) intcountThe number of elements in this segment's region.(package private) intevictCap(package private) BoundedConcurrentHashMap.EvictionPolicy<K,V>eviction(package private) BoundedConcurrentHashMap.EvictionListener<K,V>evictionListener(package private) floatloadFactorThe load factor for the hash table.(package private) intmodCountNumber of updates that alter the size of the table.private static longserialVersionUID(package private) BoundedConcurrentHashMap.HashEntry<K,V>[]tableThe per-segment table.(package private) intthresholdThe table is rehashed when its size exceeds this threshold.
-
Constructor Summary
Constructors Constructor Description Segment(int cap, int evictCap, float lf, BoundedConcurrentHashMap.Eviction es, BoundedConcurrentHashMap.EvictionListener<K,V> listener)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private Set<BoundedConcurrentHashMap.HashEntry<K,V>>attemptEviction(boolean lockedAlready)(package private) voidclear()(package private) booleancontainsKey(Object key, int hash)(package private) booleancontainsValue(Object value)(package private) Vget(Object key, int hash)(package private) BoundedConcurrentHashMap.EvictionListener<K,V>getEvictionListener()(package private) BoundedConcurrentHashMap.HashEntry<K,V>getFirst(int hash)Returns properly casted first entry of bin for given hash.(package private) static <K,V>
BoundedConcurrentHashMap.Segment<K,V>[]newArray(int i)private voidnotifyEvictionListener(Set<BoundedConcurrentHashMap.HashEntry<K,V>> evicted)(package private) Vput(K key, int hash, V value, boolean onlyIfAbsent)(package private) VreadValueUnderLock(BoundedConcurrentHashMap.HashEntry<K,V> e)Reads value field of an entry under lock.(package private) voidrehash()(package private) Vremove(Object key, int hash, Object value)Remove; match on key only if value null, else match both.(package private) Vreplace(K key, int hash, V newValue)(package private) booleanreplace(K key, int hash, V oldValue, V newValue)(package private) voidsetTable(BoundedConcurrentHashMap.HashEntry<K,V>[] newTable)Sets table to new HashEntry array.-
Methods inherited from class java.util.concurrent.locks.ReentrantLock
getHoldCount, getOwner, getQueuedThreads, getQueueLength, getWaitingThreads, getWaitQueueLength, hasQueuedThread, hasQueuedThreads, hasWaiters, isFair, isHeldByCurrentThread, isLocked, lock, lockInterruptibly, newCondition, toString, tryLock, tryLock, unlock
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
count
transient volatile int count
The number of elements in this segment's region.
-
modCount
transient int modCount
Number of updates that alter the size of the table. This is used during bulk-read methods to make sure they see a consistent snapshot: If modCounts change during a traversal of segments computing size or checking containsValue, then we might have an inconsistent view of state so (usually) must retry.
-
threshold
transient int threshold
The table is rehashed when its size exceeds this threshold. (The value of this field is always (int)(capacity * loadFactor).)
-
table
transient volatile BoundedConcurrentHashMap.HashEntry<K,V>[] table
The per-segment table.
-
loadFactor
final float loadFactor
The load factor for the hash table. Even though this value is same for all segments, it is replicated to avoid needing links to outer object.
-
evictCap
final int evictCap
-
eviction
final transient BoundedConcurrentHashMap.EvictionPolicy<K,V> eviction
-
evictionListener
final transient BoundedConcurrentHashMap.EvictionListener<K,V> evictionListener
-
-
Constructor Detail
-
Segment
Segment(int cap, int evictCap, float lf, BoundedConcurrentHashMap.Eviction es, BoundedConcurrentHashMap.EvictionListener<K,V> listener)
-
-
Method Detail
-
newArray
static <K,V> BoundedConcurrentHashMap.Segment<K,V>[] newArray(int i)
-
getEvictionListener
BoundedConcurrentHashMap.EvictionListener<K,V> getEvictionListener()
-
setTable
void setTable(BoundedConcurrentHashMap.HashEntry<K,V>[] newTable)
Sets table to new HashEntry array. Call only while holding lock or in constructor.
-
getFirst
BoundedConcurrentHashMap.HashEntry<K,V> getFirst(int hash)
Returns properly casted first entry of bin for given hash.
-
readValueUnderLock
V readValueUnderLock(BoundedConcurrentHashMap.HashEntry<K,V> e)
Reads value field of an entry under lock. Called if value field ever appears to be null. This is possible only if a compiler happens to reorder a HashEntry initialization with its table assignment, which is legal under memory model but is not known to ever occur.
-
containsKey
boolean containsKey(Object key, int hash)
-
containsValue
boolean containsValue(Object value)
-
rehash
void rehash()
-
remove
V remove(Object key, int hash, Object value)
Remove; match on key only if value null, else match both.
-
clear
void clear()
-
attemptEviction
private Set<BoundedConcurrentHashMap.HashEntry<K,V>> attemptEviction(boolean lockedAlready)
-
notifyEvictionListener
private void notifyEvictionListener(Set<BoundedConcurrentHashMap.HashEntry<K,V>> evicted)
-
-