Class GridUnsafeMap
- java.lang.Object
-
- org.apache.ignite.internal.util.offheap.unsafe.GridUnsafeMap
-
- All Implemented Interfaces:
GridOffHeapMap
public class GridUnsafeMap extends Object implements GridOffHeapMap
Off-heap map based onUnsafeimplementation.
-
-
Constructor Summary
Constructors Constructor Description GridUnsafeMap(int concurrency, float load, long initCap, long totalMem, short lruStripes, @Nullable GridOffHeapEvictListener evictLsnr)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description longallocatedSize()Gets memory allocated for map entries so far.intconcurrency()Gets concurrency level for this map.booleancontains(int hash, byte[] keyBytes)Checks if given key is contained in the map.voiddestruct()Destructs this map and deallocates all memory.voidenableEviction(int hash, byte[] keyBytes)Enables eviction for given key.booleaneventListener(GridOffHeapEventListener evtLsnr)Adds off-heap event listener.booleanevictListener(GridOffHeapEvictListener evictLsnr)Sets callback for when entries are evicted due to memory constraints.longfreeSize()Gets available memory.byte[]get(int hash, byte[] keyBytes)Gets value bytes for given key.voidinsert(int hash, byte[] keyBytes, byte[] valBytes)Inserts new entry into the map without comparing if there is a mapping for given key already stored in map.GridCloseableIterator<IgniteBiTuple<byte[],byte[]>>iterator()Gets iterator over map.<T> GridCloseableIterator<T>iterator(CX2<T2<Long,Integer>,T2<Long,Integer>,T> c)Gets iterator over map.floatloadFactor()Gets load factor of this map.longlruMemorySize()Gets memory size occupied by LRU queue.longlruSize()Gets number of elements in LRU queue.shortlruStripes()Gets number of LRU stripes.longmemorySize()Gets total available memory size.intpartition()Gets partition this map belongs to.booleanput(int hash, byte[] keyBytes, byte[] valBytes)Puts key and value bytes into the map potentially replacing existing entry.byte[]remove(int hash, byte[] keyBytes)Removes value from off-heap map.booleanremovex(int hash, byte[] keyBytes)Removes value from off-heap map without returning it.booleanremovex(int hash, byte[] keyBytes, IgniteBiPredicate<Long,Integer> p)Removes value from off-heap map without returning it.longsize()Gets number of elements in the map.longsystemAllocatedSize()Gets memory allocated for map internal structure so far.longtotalSize()Gets number of elements in the map.@Nullable IgniteBiTuple<Long,Integer>valuePointer(int hash, byte[] keyBytes)Gets value pointer for given key.
-
-
-
Constructor Detail
-
GridUnsafeMap
public GridUnsafeMap(int concurrency, float load, long initCap, long totalMem, short lruStripes, @Nullable @Nullable GridOffHeapEvictListener evictLsnr)- Parameters:
concurrency- Concurrency.load- Load factor.initCap- Initial capacity.totalMem- Total memory.lruStripes- Number of LRU stripes.evictLsnr- Eviction listener.
-
-
Method Detail
-
eventListener
public boolean eventListener(GridOffHeapEventListener evtLsnr)
Adds off-heap event listener.- Specified by:
eventListenerin interfaceGridOffHeapMap- Parameters:
evtLsnr- Listener.- Returns:
Trueif event listener was added,falseif another listener already exists.
-
evictListener
public boolean evictListener(GridOffHeapEvictListener evictLsnr)
Sets callback for when entries are evicted due to memory constraints. The parameter into closure is key bytes.- Specified by:
evictListenerin interfaceGridOffHeapMap- Parameters:
evictLsnr- Evict listener.- Returns:
Trueif evict listener was added,falseif another listener already exists orLRUis disabled.
-
partition
public int partition()
Gets partition this map belongs to.- Specified by:
partitionin interfaceGridOffHeapMap- Returns:
- Partition this map belongs to.
-
loadFactor
public float loadFactor()
Gets load factor of this map.- Specified by:
loadFactorin interfaceGridOffHeapMap- Returns:
- Load factor.
-
concurrency
public int concurrency()
Gets concurrency level for this map.- Specified by:
concurrencyin interfaceGridOffHeapMap- Returns:
- Concurrency level.
-
contains
public boolean contains(int hash, byte[] keyBytes)Checks if given key is contained in the map.- Specified by:
containsin interfaceGridOffHeapMap- Parameters:
hash- Hash.keyBytes- Key bytes.- Returns:
Trueif key is contained in the map.
-
get
public byte[] get(int hash, byte[] keyBytes)Gets value bytes for given key.- Specified by:
getin interfaceGridOffHeapMap- Parameters:
hash- Hash.keyBytes- Key bytes.- Returns:
- Value bytes.
-
valuePointer
@Nullable public @Nullable IgniteBiTuple<Long,Integer> valuePointer(int hash, byte[] keyBytes)
Gets value pointer for given key.- Specified by:
valuePointerin interfaceGridOffHeapMap- Parameters:
hash- Hash.keyBytes- Key bytes.- Returns:
- Value pointer.
-
enableEviction
public void enableEviction(int hash, byte[] keyBytes)Enables eviction for given key.- Specified by:
enableEvictionin interfaceGridOffHeapMap- Parameters:
hash- Hash.keyBytes- Key bytes.
-
remove
public byte[] remove(int hash, byte[] keyBytes)Removes value from off-heap map.- Specified by:
removein interfaceGridOffHeapMap- Parameters:
hash- Hash.keyBytes- Key bytes.- Returns:
- Removed value bytes.
-
removex
public boolean removex(int hash, byte[] keyBytes)Removes value from off-heap map without returning it.- Specified by:
removexin interfaceGridOffHeapMap- Parameters:
hash- Hash.keyBytes- Key bytes.- Returns:
Trueif value was removed.
-
removex
public boolean removex(int hash, byte[] keyBytes, IgniteBiPredicate<Long,Integer> p)Removes value from off-heap map without returning it.- Specified by:
removexin interfaceGridOffHeapMap- Parameters:
hash- Hash.keyBytes- Key bytes.p- Value predicate (arguments are value address and value length).- Returns:
Trueif value was removed.
-
put
public boolean put(int hash, byte[] keyBytes, byte[] valBytes)Puts key and value bytes into the map potentially replacing existing entry.- Specified by:
putin interfaceGridOffHeapMap- Parameters:
hash- Hash.keyBytes- Key bytes.valBytes- Value bytes.- Returns:
Trueif new entry was created,falseif existing value was updated.
-
insert
public void insert(int hash, byte[] keyBytes, byte[] valBytes)Inserts new entry into the map without comparing if there is a mapping for given key already stored in map.Use with caution whenever certain that inserting a new value without current mapping.
- Specified by:
insertin interfaceGridOffHeapMap- Parameters:
hash- Hash.keyBytes- Key bytes.valBytes- Value bytes.
-
totalSize
public long totalSize()
Gets number of elements in the map.- Specified by:
totalSizein interfaceGridOffHeapMap- Returns:
- Number of elements in the map.
-
size
public long size()
Gets number of elements in the map.- Specified by:
sizein interfaceGridOffHeapMap- Returns:
- Number of elements in the map.
-
memorySize
public long memorySize()
Gets total available memory size.- Specified by:
memorySizein interfaceGridOffHeapMap- Returns:
- Memory size.
-
allocatedSize
public long allocatedSize()
Gets memory allocated for map entries so far.- Specified by:
allocatedSizein interfaceGridOffHeapMap- Returns:
- Allocated memory.
-
systemAllocatedSize
public long systemAllocatedSize()
Gets memory allocated for map internal structure so far.- Specified by:
systemAllocatedSizein interfaceGridOffHeapMap- Returns:
- Allocated memory.
-
freeSize
public long freeSize()
Gets available memory.- Specified by:
freeSizein interfaceGridOffHeapMap- Returns:
- Available memory.
-
destruct
public void destruct()
Destructs this map and deallocates all memory.- Specified by:
destructin interfaceGridOffHeapMap
-
iterator
public GridCloseableIterator<IgniteBiTuple<byte[],byte[]>> iterator()
Gets iterator over map.- Specified by:
iteratorin interfaceGridOffHeapMap- Returns:
- Iterator over map.
-
iterator
public <T> GridCloseableIterator<T> iterator(CX2<T2<Long,Integer>,T2<Long,Integer>,T> c)
Gets iterator over map.- Specified by:
iteratorin interfaceGridOffHeapMap- Parameters:
c- Key/value closure.- Returns:
- Iterator over map.
-
lruStripes
public short lruStripes()
Gets number of LRU stripes.- Returns:
- Number of LRU stripes.
-
lruMemorySize
public long lruMemorySize()
Gets memory size occupied by LRU queue.- Returns:
- Memory size occupied by LRU queue.
-
lruSize
public long lruSize()
Gets number of elements in LRU queue.- Returns:
- Number of elements in LRU queue.
-
-