Class AbstractConcurrentOffHeapMap<K,V>
java.lang.Object
java.util.AbstractMap<K,V>
org.terracotta.offheapstore.concurrent.AbstractConcurrentOffHeapMap<K,V>
- Type Parameters:
K- the type of keys maintained by this mapV- the type of mapped values
- All Implemented Interfaces:
ConcurrentMap<K,V>, Map<K, V>, ConcurrentMapInternals, HashingMap<K, V>, MapInternals
- Direct Known Subclasses:
AbstractConcurrentOffHeapCache, AbstractPersistentConcurrentOffHeapMap, ConcurrentOffHeapHashMap, ConcurrentWriteLockedOffHeapHashMap
public abstract class AbstractConcurrentOffHeapMap<K,V>
extends AbstractMap<K,V>
implements ConcurrentMap<K,V>, ConcurrentMapInternals, HashingMap<K,V>
An abstract concurrent (striped) off-heap map.
This is an n-way hashcode striped map implementation. Subclasses must
provide a Factory instance at construction time from which
the required number of segments are created.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) class(package private) classprotected class(package private) classprivate classNested classes/interfaces inherited from class AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K, V> -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intprivate static final intprivate final intprivate final intprivate Collection<V> -
Constructor Summary
ConstructorsConstructorDescriptionAbstractConcurrentOffHeapMap(Factory<? extends Segment<K, V>> segmentFactory) Create a concurrent map using a default number of segments.AbstractConcurrentOffHeapMap(Factory<? extends Segment<K, V>> segmentFactory, int concurrency) Create a concurrent map with a defined number of segments. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()computeIfAbsentWithMetadata(K key, Function<? super K, ? extends MetadataTuple<V>> mappingFunction) computeIfPresentWithMetadata(K key, BiFunction<? super K, ? super MetadataTuple<V>, ? extends MetadataTuple<V>> remappingFunction) computeWithMetadata(K key, BiFunction<? super K, ? super MetadataTuple<V>, ? extends MetadataTuple<V>> remappingFunction) booleancontainsKey(Object key) booleancontainsValue(Object value) voiddestroy()entrySet()SeeOffHeapHashMap.fill(Object, Object)for a detailed description.longgetAndSetMetadata(K key, int mask, int values) protected intlonglonglonglongintgetIndexFor(int hash) getMetadata(K key, int mask) longlongintlonggetSize()longlonggetValueAndSetMetadata(K key, int mask, int values) longfinal booleanhandleOversizeMappingException(int hash) keySet()putIfAbsent(K key, V value) protected voidprotected voidbooleanremoveAllWithHash(int keyHash) Remove all keys having a specific hashcode.booleanremoveNoReturn(Object key) booleansegmentFor(int hash) segmentFor(Object key) intsize()private static intspread(int hash) values()final voidfinal voidMethods inherited from interface ConcurrentMap
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, replaceAll
-
Field Details
-
MAX_SEGMENTS
private static final int MAX_SEGMENTS- See Also:
-
DEFAULT_CONCURRENCY
private static final int DEFAULT_CONCURRENCY- See Also:
-
segments
-
segmentShift
private final int segmentShift -
segmentMask
private final int segmentMask -
keySet
-
entrySet
-
values
-
-
Constructor Details
-
AbstractConcurrentOffHeapMap
-
AbstractConcurrentOffHeapMap
public AbstractConcurrentOffHeapMap(Factory<? extends Segment<K, V>> segmentFactory, int concurrency) Create a concurrent map with a defined number of segments.- Parameters:
segmentFactory- factory used to create the map segmentsconcurrency- number of segments in the map- Throws:
IllegalArgumentException- if the supplied number of segments is negative
-
-
Method Details
-
segmentFor
-
segmentFor
-
getIndexFor
public int getIndexFor(int hash) -
getSegments
-
getConcurrency
protected int getConcurrency() -
spread
private static int spread(int hash) -
size
-
containsKey
- Specified by:
containsKeyin interfaceMap<K,V> - Overrides:
containsKeyin classAbstractMap<K,V>
-
containsValue
- Specified by:
containsValuein interfaceMap<K,V> - Overrides:
containsValuein classAbstractMap<K,V>
-
get
-
put
-
put
-
fill
SeeOffHeapHashMap.fill(Object, Object)for a detailed description.- Parameters:
key- key with which the specified value is to be associatedvalue- value to be associated with the specified key- Returns:
- the previous value associated with key, or null if there was no mapping for key (irrespective of whether the value was successfully installed).
-
fill
-
remove
-
removeNoReturn
-
getMetadata
- Throws:
IllegalArgumentException
-
getAndSetMetadata
- Throws:
IllegalArgumentException
-
getValueAndSetMetadata
-
clear
-
destroy
public void destroy() -
putIfAbsent
- Specified by:
putIfAbsentin interfaceConcurrentMap<K,V> - Specified by:
putIfAbsentin interfaceMap<K,V>
-
remove
-
replace
-
replace
-
keySet
-
values
-
entrySet
-
readLockAll
protected void readLockAll() -
readUnlockAll
protected void readUnlockAll() -
writeLockAll
public final void writeLockAll() -
writeUnlockAll
public final void writeUnlockAll() -
getSegmentInternals
- Specified by:
getSegmentInternalsin interfaceConcurrentMapInternals
-
getSize
public long getSize()- Specified by:
getSizein interfaceMapInternals
-
getTableCapacity
public long getTableCapacity()- Specified by:
getTableCapacityin interfaceMapInternals
-
getUsedSlotCount
public long getUsedSlotCount()- Specified by:
getUsedSlotCountin interfaceMapInternals
-
getRemovedSlotCount
public long getRemovedSlotCount()- Specified by:
getRemovedSlotCountin interfaceMapInternals
-
getReprobeLength
public int getReprobeLength()- Specified by:
getReprobeLengthin interfaceMapInternals
-
getAllocatedMemory
public long getAllocatedMemory()- Specified by:
getAllocatedMemoryin interfaceMapInternals
-
getOccupiedMemory
public long getOccupiedMemory()- Specified by:
getOccupiedMemoryin interfaceMapInternals
-
getVitalMemory
public long getVitalMemory()- Specified by:
getVitalMemoryin interfaceMapInternals
-
getDataAllocatedMemory
public long getDataAllocatedMemory()- Specified by:
getDataAllocatedMemoryin interfaceMapInternals
-
getDataOccupiedMemory
public long getDataOccupiedMemory()- Specified by:
getDataOccupiedMemoryin interfaceMapInternals
-
getDataVitalMemory
public long getDataVitalMemory()- Specified by:
getDataVitalMemoryin interfaceMapInternals
-
getDataSize
public long getDataSize()- Specified by:
getDataSizein interfaceMapInternals
-
handleOversizeMappingException
public final boolean handleOversizeMappingException(int hash) -
computeWithMetadata
public MetadataTuple<V> computeWithMetadata(K key, BiFunction<? super K, ? super MetadataTuple<V>, ? extends MetadataTuple<V>> remappingFunction) -
computeIfAbsentWithMetadata
public MetadataTuple<V> computeIfAbsentWithMetadata(K key, Function<? super K, ? extends MetadataTuple<V>> mappingFunction) -
computeIfPresentWithMetadata
public MetadataTuple<V> computeIfPresentWithMetadata(K key, BiFunction<? super K, ? super MetadataTuple<V>, ? extends MetadataTuple<V>> remappingFunction) -
removeAllWithHash
Description copied from interface:HashingMapRemove all keys having a specific hashcode.- Specified by:
removeAllWithHashin interfaceHashingMap<K,V> - Parameters:
keyHash- the hashcode of the keys to be removed.- Returns:
- a
Mapcontaining the removed mappings.
-