org.apache.ignite.internal.util.offheap.unsafe

## Class GridUnsafePartitionedMap

- java.lang.Object
- - org.apache.ignite.internal.util.offheap.unsafe.GridUnsafePartitionedMap

All Implemented Interfaces:
  GridOffHeapPartitionedMap

    public class GridUnsafePartitionedMap
    extends Object
    implements GridOffHeapPartitionedMap

Off-heap map based on `Unsafe` implementation.

### Constructor Summary

Constructors
Constructor and Description
`GridUnsafePartitionedMap(int parts, int concurrency, float load, long initCap, long totalMem, short lruStripes, @Nullable GridOffHeapEvictListener evictLsnr)`

### Method Summary

All Methods Instance Methods Concrete Methods
`long` `allocatedSize()` Gets size of a memory allocated for map entries so far.
`int` `concurrency()` Gets concurrency level for this map.
`boolean` `contains(int part, int hash, byte[] keyBytes)` Checks if given key is contained in the map.
`void` `destruct()` Destructs this map and deallocates all memory.
`void` `enableEviction(int p, int hash, byte[] keyBytes)` Enables eviction for entry.
`boolean` `eventListener(GridOffHeapEventListener evtLsnr)` Adds off-heap event listener.
`boolean` `evictListener(GridOffHeapEvictListener evictLsnr)` Sets callback for when entries are evicted due to memory constraints.
`long` `freeSize()` Gets available memory.
`byte[]` `get(int p, int hash, byte[] keyBytes)` Gets value bytes for given key.
`void` `insert(int p, 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 the whole map.
`<T> GridCloseableIterator<T>` `iterator(CX2<T2<Long,Integer>,T2<Long,Integer>,T> c)` Gets iterator over the whole map.
`<T> GridCloseableIterator<T>` `iterator(CX2<T2<Long,Integer>,T2<Long,Integer>,T> c, int part)` Gets iterator over the partition.
`GridCloseableIterator<IgniteBiTuple<byte[],byte[]>>` `iterator(int p)` Gets iterator over certain partition.
`float` `loadFactor()` Gets load factor of this map.
`long` `lruMemorySize()` Gets memory size occupied by LRU queue.
`long` `lruSize()` Gets number of elements in LRU queue.
`short` `lruStripes()` Gets number of LRU stripes.
`long` `memorySize()` Gets total available memory size.
`int` `partitions()` Gets number of partitions.
`boolean` `put(int p, int hash, byte[] keyBytes, byte[] valBytes)` Puts key and value bytes into the map potentially replacing existing entry.
`byte[]` `remove(int p, int hash, byte[] keyBytes)` Removes value from off-heap map.
`boolean` `removex(int p, int hash, byte[] keyBytes)` Removes value from off-heap map without returning it.
`boolean` `removex(int part, int hash, byte[] keyBytes, IgniteBiPredicate<Long,Integer> p)` Removes value from off-heap map without returning it.
`long` `size()` Gets number of elements in the map.
`long` `size(Set<Integer> parts)` Gets number of elements in the map.
`long` `systemAllocatedSize()` Gets memory allocated for map internal structure so far.
`IgniteBiTuple<Long,Integer>` `valuePointer(int p, int hash, byte[] keyBytes)` Gets value pointer for given key.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### GridUnsafePartitionedMap

    public GridUnsafePartitionedMap(int parts,
                                    int concurrency,
                                    float load,
                                    long initCap,
                                    long totalMem,
                                    short lruStripes,
                                    @Nullable
                                    @Nullable GridOffHeapEvictListener evictLsnr)

Parameters:
  `parts` - Partitions.
  `concurrency` - Concurrency.
  `load` - Load factor.
  `initCap` - Initial capacity.
  `totalMem` - Total memory.
  `lruStripes` - LRU stripes.
  `evictLsnr` - Eviction callback.

### Method Detail

#### loadFactor

    public float loadFactor()

Gets load factor of this map.

Specified by:
  `loadFactor` in interface `GridOffHeapPartitionedMap`
Returns:
  Load factor.

#### concurrency

    public int concurrency()

Gets concurrency level for this map.

Specified by:
  `concurrency` in interface `GridOffHeapPartitionedMap`
Returns:
  Concurrency level.

#### partitions

    public int partitions()

Gets number of partitions.

Specified by:
  `partitions` in interface `GridOffHeapPartitionedMap`
Returns:
  Number of partitions.

#### contains

    public boolean contains(int part,
                            int hash,
                            byte[] keyBytes)

Checks if given key is contained in the map.

Specified by:
  `contains` in interface `GridOffHeapPartitionedMap`
Parameters:
  `part` - Partition.
  `hash` - Hash.
  `keyBytes` - Key bytes.
Returns:
  `True` if key is contained in the map.

#### get

    public byte[] get(int p,
                      int hash,
                      byte[] keyBytes)

Gets value bytes for given key.

Specified by:
  `get` in interface `GridOffHeapPartitionedMap`
Parameters:
  `p` - Partition.
  `hash` - Hash.
  `keyBytes` - Key bytes.
Returns:
  Value bytes.

#### valuePointer

    public IgniteBiTuple<Long,Integer> valuePointer(int p,
                                                    int hash,
                                                    byte[] keyBytes)

Gets value pointer for given key. While pointer is in use eviction is disabled for corresponding entry. Eviction for entry is enabled when `GridOffHeapPartitionedMap.put(int, int, byte[], byte[])` or `GridOffHeapPartitionedMap.enableEviction(int, int, byte[])` is called.

Specified by:
  `valuePointer` in interface `GridOffHeapPartitionedMap`
Parameters:
  `p` - Partition.
  `hash` - Hash.
  `keyBytes` - Key bytes.
Returns:
  Value pointer.

#### enableEviction

    public void enableEviction(int p,
                               int hash,
                               byte[] keyBytes)

Enables eviction for entry.

Specified by:
  `enableEviction` in interface `GridOffHeapPartitionedMap`
Parameters:
  `p` - Partition.
  `hash` - Hash.
  `keyBytes` - Key bytes.

#### remove

    public byte[] remove(int p,
                         int hash,
                         byte[] keyBytes)

Removes value from off-heap map.

Specified by:
  `remove` in interface `GridOffHeapPartitionedMap`
Parameters:
  `p` - Partition.
  `hash` - Hash.
  `keyBytes` - Key bytes.
Returns:
  Removed value bytes.

#### removex

    public boolean removex(int p,
                           int hash,
                           byte[] keyBytes)

Removes value from off-heap map without returning it.

Specified by:
  `removex` in interface `GridOffHeapPartitionedMap`
Parameters:
  `p` - Partition.
  `hash` - Hash.
  `keyBytes` - Key bytes.
Returns:
  `True` if value was removed.

#### removex

    public boolean removex(int part,
                           int hash,
                           byte[] keyBytes,
                           IgniteBiPredicate<Long,Integer> p)

Removes value from off-heap map without returning it.

Specified by:
  `removex` in interface `GridOffHeapPartitionedMap`
Parameters:
  `part` - Partition.
  `hash` - Hash.
  `keyBytes` - Key bytes.
  `p` - Value predicate (arguments are value address and value length).
Returns:
  `True` if value was removed.

#### put

    public boolean put(int p,
                       int hash,
                       byte[] keyBytes,
                       byte[] valBytes)

Puts key and value bytes into the map potentially replacing existing entry.

Specified by:
  `put` in interface `GridOffHeapPartitionedMap`
Parameters:
  `p` - Partition.
  `hash` - Hash.
  `keyBytes` - Key bytes.
  `valBytes` - Value bytes.
Returns:
  `True` if new entry was created, `false` if existing value was updated.

#### insert

    public void insert(int p,
                       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:
  `insert` in interface `GridOffHeapPartitionedMap`
Parameters:
  `p` - Partition.
  `hash` - Hash.
  `keyBytes` - Key bytes.
  `valBytes` - Value bytes.

#### size

    public long size()

Gets number of elements in the map.

Specified by:
  `size` in interface `GridOffHeapPartitionedMap`
Returns:
  Number of elements in the map.

#### size

    public long size(Set<Integer> parts)

Gets number of elements in the map.

Specified by:
  `size` in interface `GridOffHeapPartitionedMap`
Parameters:
  `parts` - Partitions.
Returns:
  Number of elements in the map.

#### memorySize

    public long memorySize()

Gets total available memory size.

Specified by:
  `memorySize` in interface `GridOffHeapPartitionedMap`
Returns:
  Memory size.

#### allocatedSize

    public long allocatedSize()

Gets size of a memory allocated for map entries so far.

Specified by:
  `allocatedSize` in interface `GridOffHeapPartitionedMap`
Returns:
  Allocated memory size.

#### systemAllocatedSize

    public long systemAllocatedSize()

Gets memory allocated for map internal structure so far.

Specified by:
  `systemAllocatedSize` in interface `GridOffHeapPartitionedMap`
Returns:
  Allocated memory.

#### freeSize

    public long freeSize()

Gets available memory.

Specified by:
  `freeSize` in interface `GridOffHeapPartitionedMap`
Returns:
  Available memory.

#### eventListener

    public boolean eventListener(GridOffHeapEventListener evtLsnr)

Adds off-heap event listener.

Specified by:
  `eventListener` in interface `GridOffHeapPartitionedMap`
Parameters:
  `evtLsnr` - Listener.
Returns:
  `True` if event listener was added, `false` if 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:
  `evictListener` in interface `GridOffHeapPartitionedMap`
Parameters:
  `evictLsnr` - Evict listener.
Returns:
  `True` if evict listener was added, `false` if another listener already exists or `LRU` is disabled.

#### destruct

    public void destruct()

Destructs this map and deallocates all memory.

Specified by:
  `destruct` in interface `GridOffHeapPartitionedMap`

#### iterator

    public GridCloseableIterator<IgniteBiTuple<byte[],byte[]>> iterator()

Gets iterator over the whole map.

Specified by:
  `iterator` in interface `GridOffHeapPartitionedMap`
Returns:
  Iterator over the whole map.

#### iterator

    public <T> GridCloseableIterator<T> iterator(CX2<T2<Long,Integer>,T2<Long,Integer>,T> c)

Gets iterator over the whole map.

Specified by:
  `iterator` in interface `GridOffHeapPartitionedMap`
Parameters:
  `c` - Key/value closure.
Returns:
  Iterator over the whole map.

#### iterator

    public <T> GridCloseableIterator<T> iterator(CX2<T2<Long,Integer>,T2<Long,Integer>,T> c,
                                                 int part)

Gets iterator over the partition.

Specified by:
  `iterator` in interface `GridOffHeapPartitionedMap`
Parameters:
  `c` - Key/value closure.
  `part` - Partition.
Returns:
  Iterator over the partition.

#### iterator

    public GridCloseableIterator<IgniteBiTuple<byte[],byte[]>> iterator(int p)

Gets iterator over certain partition.

Specified by:
  `iterator` in interface `GridOffHeapPartitionedMap`
Parameters:
  `p` - Partition.
Returns:
  Iterator over certain partition.

#### 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.

${current.year} Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Database and Caching Platform | : ver. 2.13.0
Release Date | : April 20 2022