org.terracotta.offheapstore
Class AbstractLockedOffHeapHashMap<K,V>

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by org.terracotta.offheapstore.OffHeapHashMap<K,V>
          extended by org.terracotta.offheapstore.AbstractLockedOffHeapHashMap<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>, ReadWriteLock, Map<K,V>, HashingMap<K,V>, MapInternals, Segment<K,V>, StorageEngine.Owner
Direct Known Subclasses:
AbstractOffHeapClockCache, AbstractPersistentLockedOffHeapHashMap, ReadWriteLockedOffHeapHashMap, WriteLockedOffHeapHashMap

public abstract class AbstractLockedOffHeapHashMap<K,V>
extends OffHeapHashMap<K,V>
implements Segment<K,V>

An abstract locked off-heap map.

Subclasses must implement the readLock() and writeLock() methods such that they return the correct locks under which read and write operations must occur.

Author:
Chris Dennis

Nested Class Summary
 
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
 
Fields inherited from class org.terracotta.offheapstore.OffHeapHashMap
ENCODING, ENTRY_BIT_SHIFT, ENTRY_SIZE, hashtable, hashTablePage, KEY_HASHCODE, modCount, removedSlots, reprobeLimit, RESERVED_STATUS_BITS, size, STATUS, STATUS_REMOVED, STATUS_USED, storageEngine, tableSource
 
Constructor Summary
AbstractLockedOffHeapHashMap(PageSource source, boolean tableAllocationsSteal, StorageEngine<? super K,? super V> storageEngine)
           
AbstractLockedOffHeapHashMap(PageSource source, boolean tableAllocationsSteal, StorageEngine<? super K,? super V> storageEngine, int tableSize)
           
AbstractLockedOffHeapHashMap(PageSource source, StorageEngine<? super K,? super V> storageEngine)
           
AbstractLockedOffHeapHashMap(PageSource source, StorageEngine<? super K,? super V> storageEngine, boolean bootstrap)
           
AbstractLockedOffHeapHashMap(PageSource source, StorageEngine<? super K,? super V> storageEngine, int tableSize)
           
AbstractLockedOffHeapHashMap(PageSource source, StorageEngine<? super K,? super V> storageEngine, int tableSize, boolean bootstrap)
           
 
Method Summary
 void clear()
           
 MetadataTuple<V> computeIfAbsentWithMetadata(K key, Function<? super K,? extends MetadataTuple<V>> mappingFunction)
           
 MetadataTuple<V> computeIfPresentWithMetadata(K key, BiFunction<? super K,? super MetadataTuple<V>,? extends MetadataTuple<V>> remappingFunction)
           
 MetadataTuple<V> computeWithMetadata(K key, BiFunction<? super K,? super MetadataTuple<V>,? extends MetadataTuple<V>> remappingFunction)
           
 boolean containsKey(Object key)
           
 void destroy()
           
 Set<Map.Entry<K,V>> entrySet()
           
 boolean evict(int index, boolean shrink)
           
 V fill(K key, V value)
          Associates the specified value with the specified key in this map.
 V fill(K key, V value, int metadata)
           
 V get(Object key)
           
 Integer getAndSetMetadata(Object key, int mask, int values)
           
 Long getEncodingForHashAndBinary(int hash, ByteBuffer binaryKey)
           
 Integer getMetadata(Object key, int mask)
           
 V getValueAndSetMetadata(Object key, int mask, int values)
           
 long installMappingForHashAndEncoding(int pojoHash, ByteBuffer offheapBinaryKey, ByteBuffer offheapBinaryValue, int metadata)
           
 Set<K> keySet()
           
 V put(K key, V value)
           
 V put(K key, V value, int metadata)
           
 V putIfAbsent(K key, V value)
           
abstract  Lock readLock()
           
 V remove(Object key)
           
 boolean remove(Object key, Object value)
           
 Map<K,V> removeAllWithHash(int hash)
          Remove all keys having a specific hashcode.
protected  boolean removeMapping(Object o)
           
 boolean removeNoReturn(Object key)
           
 V replace(K key, V value)
           
 boolean replace(K key, V oldValue, V newValue)
           
 boolean shrink()
           
 int size()
           
 Collection<V> values()
           
abstract  Lock writeLock()
           
 
Methods inherited from class org.terracotta.offheapstore.OffHeapHashMap
added, encodingSet, fill, freePendingTables, getAllocatedMemory, getAtTableOffset, getDataAllocatedMemory, getDataOccupiedMemory, getDataSize, getDataVitalMemory, getEntryAtTableOffset, getOccupiedMemory, getRemovedSlotCount, getReprobeLength, getSize, getSlotForHashAndEncoding, getStorageEngine, getTableCapacity, getUsedSlotCount, getVitalMemory, hit, indexFor, indexFor, isAvailable, isPresent, isRemoved, isRemoved, isTerminating, isTerminating, isThiefForTableAllocations, readLong, readLong, removeAtTableOffset, removed, shrinkTable, spread, storageEngineFailure, tableExpansionFailure, tryIncreaseReprobe, updated, updateEncoding
 
Methods inherited from class java.util.AbstractMap
clone, containsValue, equals, hashCode, isEmpty, putAll, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.terracotta.offheapstore.Segment
getLock
 
Methods inherited from interface org.terracotta.offheapstore.MapInternals
getAllocatedMemory, getDataAllocatedMemory, getDataOccupiedMemory, getDataSize, getDataVitalMemory, getOccupiedMemory, getRemovedSlotCount, getReprobeLength, getSize, getTableCapacity, getUsedSlotCount, getVitalMemory
 
Methods inherited from interface java.util.Map
containsValue, equals, hashCode, isEmpty, putAll
 

Constructor Detail

AbstractLockedOffHeapHashMap

public AbstractLockedOffHeapHashMap(PageSource source,
                                    StorageEngine<? super K,? super V> storageEngine)

AbstractLockedOffHeapHashMap

public AbstractLockedOffHeapHashMap(PageSource source,
                                    boolean tableAllocationsSteal,
                                    StorageEngine<? super K,? super V> storageEngine)

AbstractLockedOffHeapHashMap

public AbstractLockedOffHeapHashMap(PageSource source,
                                    StorageEngine<? super K,? super V> storageEngine,
                                    boolean bootstrap)

AbstractLockedOffHeapHashMap

public AbstractLockedOffHeapHashMap(PageSource source,
                                    StorageEngine<? super K,? super V> storageEngine,
                                    int tableSize)

AbstractLockedOffHeapHashMap

public AbstractLockedOffHeapHashMap(PageSource source,
                                    boolean tableAllocationsSteal,
                                    StorageEngine<? super K,? super V> storageEngine,
                                    int tableSize)

AbstractLockedOffHeapHashMap

public AbstractLockedOffHeapHashMap(PageSource source,
                                    StorageEngine<? super K,? super V> storageEngine,
                                    int tableSize,
                                    boolean bootstrap)
Method Detail

size

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

containsKey

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

get

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

getEncodingForHashAndBinary

public Long getEncodingForHashAndBinary(int hash,
                                        ByteBuffer binaryKey)
Specified by:
getEncodingForHashAndBinary in interface StorageEngine.Owner
Overrides:
getEncodingForHashAndBinary in class OffHeapHashMap<K,V>

installMappingForHashAndEncoding

public long installMappingForHashAndEncoding(int pojoHash,
                                             ByteBuffer offheapBinaryKey,
                                             ByteBuffer offheapBinaryValue,
                                             int metadata)
Specified by:
installMappingForHashAndEncoding in interface StorageEngine.Owner
Overrides:
installMappingForHashAndEncoding in class OffHeapHashMap<K,V>

put

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

put

public V put(K key,
             V value,
             int metadata)
Specified by:
put in interface Segment<K,V>
Overrides:
put in class OffHeapHashMap<K,V>

fill

public V fill(K key,
              V value)
Description copied from class: OffHeapHashMap
Associates the specified value with the specified key in this map. If the map does not contain a mapping for the key, the new mapping is only installed if there is room. If the map previously contained a mapping for the key, the old value is replaced by the specified value even if this results in a failure or eviction.

Specified by:
fill in interface Segment<K,V>
Overrides:
fill in class OffHeapHashMap<K,V>
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)
Specified by:
fill in interface Segment<K,V>
Overrides:
fill in class OffHeapHashMap<K,V>

remove

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

removeNoReturn

public boolean removeNoReturn(Object key)
Specified by:
removeNoReturn in interface Segment<K,V>
Overrides:
removeNoReturn in class OffHeapHashMap<K,V>

clear

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

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>

getMetadata

public Integer getMetadata(Object key,
                           int mask)
Specified by:
getMetadata in interface Segment<K,V>
Overrides:
getMetadata in class OffHeapHashMap<K,V>

getAndSetMetadata

public Integer getAndSetMetadata(Object key,
                                 int mask,
                                 int values)
Specified by:
getAndSetMetadata in interface Segment<K,V>
Overrides:
getAndSetMetadata in class OffHeapHashMap<K,V>

getValueAndSetMetadata

public V getValueAndSetMetadata(Object key,
                                int mask,
                                int values)
Specified by:
getValueAndSetMetadata in interface Segment<K,V>
Overrides:
getValueAndSetMetadata in class OffHeapHashMap<K,V>

removeMapping

protected boolean removeMapping(Object o)
Overrides:
removeMapping in class OffHeapHashMap<K,V>

evict

public boolean evict(int index,
                     boolean shrink)
Specified by:
evict in interface StorageEngine.Owner
Overrides:
evict in class OffHeapHashMap<K,V>

entrySet

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

keySet

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

values

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

destroy

public void destroy()
Specified by:
destroy in interface Segment<K,V>
Overrides:
destroy in class OffHeapHashMap<K,V>

shrink

public boolean shrink()
Specified by:
shrink in interface Segment<K,V>

readLock

public abstract Lock readLock()
Specified by:
readLock in interface ReadWriteLock
Overrides:
readLock in class OffHeapHashMap<K,V>

writeLock

public abstract Lock writeLock()
Specified by:
writeLock in interface ReadWriteLock
Overrides:
writeLock in class OffHeapHashMap<K,V>

computeWithMetadata

public MetadataTuple<V> computeWithMetadata(K key,
                                            BiFunction<? super K,? super MetadataTuple<V>,? extends MetadataTuple<V>> remappingFunction)
Specified by:
computeWithMetadata in interface Segment<K,V>
Overrides:
computeWithMetadata in class OffHeapHashMap<K,V>

computeIfAbsentWithMetadata

public MetadataTuple<V> computeIfAbsentWithMetadata(K key,
                                                    Function<? super K,? extends MetadataTuple<V>> mappingFunction)
Specified by:
computeIfAbsentWithMetadata in interface Segment<K,V>
Overrides:
computeIfAbsentWithMetadata in class OffHeapHashMap<K,V>

computeIfPresentWithMetadata

public MetadataTuple<V> computeIfPresentWithMetadata(K key,
                                                     BiFunction<? super K,? super MetadataTuple<V>,? extends MetadataTuple<V>> remappingFunction)
Specified by:
computeIfPresentWithMetadata in interface Segment<K,V>
Overrides:
computeIfPresentWithMetadata in class OffHeapHashMap<K,V>

removeAllWithHash

public Map<K,V> removeAllWithHash(int hash)
Description copied from interface: HashingMap
Remove all keys having a specific hashcode.

Specified by:
removeAllWithHash in interface HashingMap<K,V>
Overrides:
removeAllWithHash in class OffHeapHashMap<K,V>
Parameters:
hash - the hashcode of the keys to be removed.
Returns:
a Map containing the removed mappings.


Copyright © 2016. All Rights Reserved.