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:
java.util.concurrent.ConcurrentMap<K,V>,java.util.Map<K,V>,ConcurrentMapInternals,HashingMap<K,V>,MapInternals
- Direct Known Subclasses:
AbstractConcurrentOffHeapCache,AbstractPersistentConcurrentOffHeapMap,ConcurrentOffHeapHashMap,ConcurrentWriteLockedOffHeapHashMap
public abstract class AbstractConcurrentOffHeapMap<K,V> extends java.util.AbstractMap<K,V> implements java.util.concurrent.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
Factoryinstance at construction time from which the required number of segments are created.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) classAbstractConcurrentOffHeapMap.AggregatedValuesCollection(package private) classAbstractConcurrentOffHeapMap.AggregateEntrySetprotected classAbstractConcurrentOffHeapMap.AggregateIterator<T>(package private) classAbstractConcurrentOffHeapMap.AggregateKeySetprivate classAbstractConcurrentOffHeapMap.BaseAggregateSet<T>
-
Field Summary
Fields Modifier and Type Field Description private static intDEFAULT_CONCURRENCYprivate java.util.Set<java.util.Map.Entry<K,V>>entrySetprivate java.util.Set<K>keySetprivate static intMAX_SEGMENTSprivate intsegmentMaskprotected Segment<K,V>[]segmentsprivate intsegmentShiftprivate java.util.Collection<V>values
-
Constructor Summary
Constructors Constructor Description AbstractConcurrentOffHeapMap(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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()MetadataTuple<V>computeIfAbsentWithMetadata(K key, java.util.function.Function<? super K,? extends MetadataTuple<V>> mappingFunction)MetadataTuple<V>computeIfPresentWithMetadata(K key, java.util.function.BiFunction<? super K,? super MetadataTuple<V>,? extends MetadataTuple<V>> remappingFunction)MetadataTuple<V>computeWithMetadata(K key, java.util.function.BiFunction<? super K,? super MetadataTuple<V>,? extends MetadataTuple<V>> remappingFunction)booleancontainsKey(java.lang.Object key)booleancontainsValue(java.lang.Object value)voiddestroy()java.util.Set<java.util.Map.Entry<K,V>>entrySet()Vfill(K key, V value)SeeOffHeapHashMap.fill(Object, Object)for a detailed description.Vfill(K key, V value, int metadata)Vget(java.lang.Object key)longgetAllocatedMemory()java.lang.IntegergetAndSetMetadata(K key, int mask, int values)protected intgetConcurrency()longgetDataAllocatedMemory()longgetDataOccupiedMemory()longgetDataSize()longgetDataVitalMemory()intgetIndexFor(int hash)java.lang.IntegergetMetadata(K key, int mask)longgetOccupiedMemory()longgetRemovedSlotCount()intgetReprobeLength()java.util.List<MapInternals>getSegmentInternals()java.util.List<Segment<K,V>>getSegments()longgetSize()longgetTableCapacity()longgetUsedSlotCount()VgetValueAndSetMetadata(K key, int mask, int values)longgetVitalMemory()booleanhandleOversizeMappingException(int hash)java.util.Set<K>keySet()Vput(K key, V value)Vput(K key, V value, int metadata)VputIfAbsent(K key, V value)protected voidreadLockAll()protected voidreadUnlockAll()Vremove(java.lang.Object key)booleanremove(java.lang.Object key, java.lang.Object value)java.util.Map<K,V>removeAllWithHash(int keyHash)Remove all keys having a specific hashcode.booleanremoveNoReturn(java.lang.Object key)Vreplace(K key, V value)booleanreplace(K key, V oldValue, V newValue)protected Segment<K,V>segmentFor(int hash)protected Segment<K,V>segmentFor(java.lang.Object key)intsize()private static intspread(int hash)java.util.Collection<V>values()voidwriteLockAll()voidwriteUnlockAll()-
Methods inherited from class java.util.AbstractMap
clone, equals, hashCode, isEmpty, putAll, toString
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
-
-
-
Field Detail
-
MAX_SEGMENTS
private static final int MAX_SEGMENTS
- See Also:
- Constant Field Values
-
DEFAULT_CONCURRENCY
private static final int DEFAULT_CONCURRENCY
- See Also:
- Constant Field Values
-
segmentShift
private final int segmentShift
-
segmentMask
private final int segmentMask
-
keySet
private java.util.Set<K> keySet
-
values
private java.util.Collection<V> values
-
-
Constructor Detail
-
AbstractConcurrentOffHeapMap
public AbstractConcurrentOffHeapMap(Factory<? extends Segment<K,V>> segmentFactory)
Create a concurrent map using a default number of segments.- Parameters:
segmentFactory- factory used to create the map segments
-
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:
java.lang.IllegalArgumentException- if the supplied number of segments is negative
-
-
Method Detail
-
getIndexFor
public int getIndexFor(int hash)
-
getConcurrency
protected int getConcurrency()
-
spread
private static int spread(int hash)
-
size
public int size()
-
containsKey
public boolean containsKey(java.lang.Object key)
-
containsValue
public boolean containsValue(java.lang.Object value)
-
get
public V get(java.lang.Object key)
-
fill
public V fill(K key, V value)
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).
-
remove
public V remove(java.lang.Object key)
-
removeNoReturn
public boolean removeNoReturn(java.lang.Object key)
-
getMetadata
public java.lang.Integer getMetadata(K key, int mask) throws java.lang.IllegalArgumentException
- Throws:
java.lang.IllegalArgumentException
-
getAndSetMetadata
public java.lang.Integer getAndSetMetadata(K key, int mask, int values) throws java.lang.IllegalArgumentException
- Throws:
java.lang.IllegalArgumentException
-
clear
public void clear()
-
destroy
public void destroy()
-
remove
public boolean remove(java.lang.Object key, java.lang.Object value)
-
keySet
public java.util.Set<K> keySet()
-
values
public java.util.Collection<V> values()
-
readLockAll
protected void readLockAll()
-
readUnlockAll
protected void readUnlockAll()
-
writeLockAll
public final void writeLockAll()
-
writeUnlockAll
public final void writeUnlockAll()
-
getSegmentInternals
public java.util.List<MapInternals> 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, java.util.function.BiFunction<? super K,? super MetadataTuple<V>,? extends MetadataTuple<V>> remappingFunction)
-
computeIfAbsentWithMetadata
public MetadataTuple<V> computeIfAbsentWithMetadata(K key, java.util.function.Function<? super K,? extends MetadataTuple<V>> mappingFunction)
-
computeIfPresentWithMetadata
public MetadataTuple<V> computeIfPresentWithMetadata(K key, java.util.function.BiFunction<? super K,? super MetadataTuple<V>,? extends MetadataTuple<V>> remappingFunction)
-
removeAllWithHash
public java.util.Map<K,V> removeAllWithHash(int keyHash)
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.
-
-