org.terracotta.offheapstore.concurrent
Class AbstractConcurrentOffHeapMap<K,V>

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by org.terracotta.offheapstore.concurrent.AbstractConcurrentOffHeapMap<K,V>
Type Parameters:
K - the type of keys maintained by this map
V - the type of mapped values
All Implemented Interfaces:
ConcurrentMap<K,V>, Map<K,V>, ConcurrentMapInternals, MapInternals
Direct Known Subclasses:
AbstractConcurrentOffHeapCache, AbstractPersistentConcurrentOffHeapMap, ConcurrentOffHeapHashMap, ConcurrentWriteLockedOffHeapHashMap

public abstract class AbstractConcurrentOffHeapMap<K,V>
extends AbstractMap<K,V>
implements ConcurrentMap<K,V>, ConcurrentMapInternals

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.

Author:
Chris Dennis

Nested Class Summary
protected  class AbstractConcurrentOffHeapMap.AggregateIterator<T>
           
 
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Field Summary
protected  Segment<K,V>[] segments
           
 
Constructor Summary
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
 void clear()
           
 boolean containsKey(Object key)
           
 boolean containsValue(Object value)
           
 void destroy()
           
 Set<Map.Entry<K,V>> entrySet()
           
 V fill(K key, V value)
          See OffHeapHashMap.fill(Object, Object) for a detailed description.
 V fill(K key, V value, int metadata)
           
 V get(Object key)
           
 long getAllocatedMemory()
           
 Integer getAndSetMetadata(K key, int mask, int values)
           
protected  int getConcurrency()
           
 long getDataAllocatedMemory()
           
 long getDataOccupiedMemory()
           
 long getDataSize()
           
 long getDataVitalMemory()
           
 int getIndexFor(int hash)
           
 Integer getMetadata(K key, int mask)
           
 long getOccupiedMemory()
           
 long getRemovedSlotCount()
           
 int getReprobeLength()
           
 List<MapInternals> getSegmentInternals()
           
 List<Segment<K,V>> getSegments()
           
 long getSize()
           
 long getTableCapacity()
           
 long getUsedSlotCount()
           
 V getValueAndSetMetadata(K key, int mask, int values)
           
 long getVitalMemory()
           
 boolean handleOversizeMappingException(int hash)
           
 Set<K> keySet()
           
 V put(K key, V value)
           
 V put(K key, V value, int metadata)
           
 V putIfAbsent(K key, V value)
           
protected  void readLockAll()
           
protected  void readUnlockAll()
           
 V remove(Object key)
           
 boolean remove(Object key, Object value)
           
 boolean removeNoReturn(Object key)
           
 V replace(K key, V value)
           
 boolean replace(K key, V oldValue, V newValue)
           
protected  Segment<K,V> segmentFor(int hash)
           
protected  Segment<K,V> segmentFor(Object key)
           
 int size()
           
 Collection<V> values()
           
 void writeLockAll()
           
 void writeUnlockAll()
           
 
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
 
Methods inherited from interface java.util.Map
equals, hashCode, isEmpty, putAll
 

Field Detail

segments

protected final Segment<K,V>[] segments
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 segments
concurrency - number of segments in the map
Throws:
IllegalArgumentException - if the supplied number of segments is negative
Method Detail

segmentFor

protected Segment<K,V> segmentFor(Object key)

segmentFor

protected Segment<K,V> segmentFor(int hash)

getIndexFor

public int getIndexFor(int hash)

getSegments

public List<Segment<K,V>> getSegments()

getConcurrency

protected int getConcurrency()

size

public int size()
Specified by:
size in interface Map<K,V>
Overrides:
size in class AbstractMap<K,V>

containsKey

public boolean containsKey(Object key)
Specified by:
containsKey in interface Map<K,V>
Overrides:
containsKey in class AbstractMap<K,V>

containsValue

public boolean containsValue(Object value)
Specified by:
containsValue in interface Map<K,V>
Overrides:
containsValue in class AbstractMap<K,V>

get

public V get(Object key)
Specified by:
get in interface Map<K,V>
Overrides:
get in class AbstractMap<K,V>

put

public V put(K key,
             V value)
Specified by:
put in interface Map<K,V>
Overrides:
put in class AbstractMap<K,V>

put

public V put(K key,
             V value,
             int metadata)

fill

public V fill(K key,
              V value)
See OffHeapHashMap.fill(Object, Object) for a detailed description.

Parameters:
key - key with which the specified value is to be associated
value - 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

public V fill(K key,
              V value,
              int metadata)

remove

public V remove(Object key)
Specified by:
remove in interface Map<K,V>
Overrides:
remove in class AbstractMap<K,V>

removeNoReturn

public boolean removeNoReturn(Object key)

getMetadata

public Integer getMetadata(K key,
                           int mask)
                    throws IllegalArgumentException
Throws:
IllegalArgumentException

getAndSetMetadata

public Integer getAndSetMetadata(K key,
                                 int mask,
                                 int values)
                          throws IllegalArgumentException
Throws:
IllegalArgumentException

getValueAndSetMetadata

public V getValueAndSetMetadata(K key,
                                int mask,
                                int values)

clear

public void clear()
Specified by:
clear in interface Map<K,V>
Overrides:
clear in class AbstractMap<K,V>

destroy

public void destroy()

putIfAbsent

public V putIfAbsent(K key,
                     V value)
Specified by:
putIfAbsent in interface ConcurrentMap<K,V>

remove

public boolean remove(Object key,
                      Object value)
Specified by:
remove in interface ConcurrentMap<K,V>

replace

public boolean replace(K key,
                       V oldValue,
                       V newValue)
Specified by:
replace in interface ConcurrentMap<K,V>

replace

public V replace(K key,
                 V value)
Specified by:
replace in interface ConcurrentMap<K,V>

keySet

public Set<K> keySet()
Specified by:
keySet in interface Map<K,V>
Overrides:
keySet in class AbstractMap<K,V>

values

public Collection<V> values()
Specified by:
values in interface Map<K,V>
Overrides:
values in class AbstractMap<K,V>

entrySet

public Set<Map.Entry<K,V>> entrySet()
Specified by:
entrySet in interface Map<K,V>
Specified by:
entrySet in class AbstractMap<K,V>

readLockAll

protected void readLockAll()

readUnlockAll

protected void readUnlockAll()

writeLockAll

public final void writeLockAll()

writeUnlockAll

public final void writeUnlockAll()

getSegmentInternals

public List<MapInternals> getSegmentInternals()
Specified by:
getSegmentInternals in interface ConcurrentMapInternals

getSize

public long getSize()
Specified by:
getSize in interface MapInternals

getTableCapacity

public long getTableCapacity()
Specified by:
getTableCapacity in interface MapInternals

getUsedSlotCount

public long getUsedSlotCount()
Specified by:
getUsedSlotCount in interface MapInternals

getRemovedSlotCount

public long getRemovedSlotCount()
Specified by:
getRemovedSlotCount in interface MapInternals

getReprobeLength

public int getReprobeLength()
Specified by:
getReprobeLength in interface MapInternals

getAllocatedMemory

public long getAllocatedMemory()
Specified by:
getAllocatedMemory in interface MapInternals

getOccupiedMemory

public long getOccupiedMemory()
Specified by:
getOccupiedMemory in interface MapInternals

getVitalMemory

public long getVitalMemory()
Specified by:
getVitalMemory in interface MapInternals

getDataAllocatedMemory

public long getDataAllocatedMemory()
Specified by:
getDataAllocatedMemory in interface MapInternals

getDataOccupiedMemory

public long getDataOccupiedMemory()
Specified by:
getDataOccupiedMemory in interface MapInternals

getDataVitalMemory

public long getDataVitalMemory()
Specified by:
getDataVitalMemory in interface MapInternals

getDataSize

public long getDataSize()
Specified by:
getDataSize in interface MapInternals

handleOversizeMappingException

public final boolean handleOversizeMappingException(int hash)


Copyright © 2015. All Rights Reserved.