Package org.infinispan.container.offheap
Class OffHeapEntryFactoryImpl
- java.lang.Object
-
- org.infinispan.container.offheap.OffHeapEntryFactoryImpl
-
- All Implemented Interfaces:
org.infinispan.container.impl.KeyValueMetadataSizeCalculator<WrappedBytes,WrappedBytes>
,OffHeapEntryFactory
public class OffHeapEntryFactoryImpl extends Object implements OffHeapEntryFactory
Factory that can create CacheEntry instances from off-heap memory.- Since:
- 9.0
- Author:
- wburns
-
-
Constructor Summary
Constructors Constructor Description OffHeapEntryFactoryImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description long
calculateSize(WrappedBytes key, WrappedBytes value, Metadata metadata)
Method used to calculate how much memory in size the key, value and metadata use.long
create(WrappedBytes key, WrappedBytes value, Metadata metadata)
Create an entry off-heap.boolean
equalsKey(long address, WrappedBytes wrappedBytes)
Assumes the address points to the entry excluding the pointer reference at the beginningInternalCacheEntry<WrappedBytes,WrappedBytes>
fromMemory(long address)
Assumes the address doesn't contain the linked pointer at the beginningint
getHashCode(long entryAddress)
Returns the hashCode of the address.byte[]
getKey(long address)
Returns the key of the address.long
getNext(long entryAddress)
Returns the address to the next linked pointer if there is one for this bucket or 0 if there isn't onelong
getSize(long entryAddress, boolean includeAllocationOverhead)
Returns how many bytes in memory this address location uses assuming it is anInternalCacheEntry
.boolean
isExpired(long address)
Returns whether entry is expired.void
setNext(long entryAddress, long value)
Called to update the next pointer index when a collision occurs requiring a linked list within the entries themselvesvoid
start()
-
-
-
Method Detail
-
start
public void start()
-
create
public long create(WrappedBytes key, WrappedBytes value, Metadata metadata)
Create an entry off-heap. The first 8 bytes will always be 0, reserved for a future reference to another entry- Specified by:
create
in interfaceOffHeapEntryFactory
- Parameters:
key
- the key to usevalue
- the value to usemetadata
- the metadata to use- Returns:
- the address of the entry created off heap
-
getSize
public long getSize(long entryAddress, boolean includeAllocationOverhead)
Description copied from interface:OffHeapEntryFactory
Returns how many bytes in memory this address location uses assuming it is anInternalCacheEntry
.- Specified by:
getSize
in interfaceOffHeapEntryFactory
- Parameters:
entryAddress
- the address of the entryincludeAllocationOverhead
- if true, align to 8 bytes and add 16 bytes allocation overhead- Returns:
- how many bytes this address was estimated to be
-
getNext
public long getNext(long entryAddress)
Description copied from interface:OffHeapEntryFactory
Returns the address to the next linked pointer if there is one for this bucket or 0 if there isn't one- Specified by:
getNext
in interfaceOffHeapEntryFactory
- Parameters:
entryAddress
- the address of the entry- Returns:
- the next address entry for this bucket or 0
-
setNext
public void setNext(long entryAddress, long value)
Description copied from interface:OffHeapEntryFactory
Called to update the next pointer index when a collision occurs requiring a linked list within the entries themselves- Specified by:
setNext
in interfaceOffHeapEntryFactory
- Parameters:
entryAddress
- the address of the entry to updatevalue
- the value of the linked node to set
-
getHashCode
public int getHashCode(long entryAddress)
Description copied from interface:OffHeapEntryFactory
Returns the hashCode of the address. This- Specified by:
getHashCode
in interfaceOffHeapEntryFactory
- Parameters:
entryAddress
- the address of the entry- Returns:
- the has code of the entry
-
getKey
public byte[] getKey(long address)
Description copied from interface:OffHeapEntryFactory
Returns the key of the address.- Specified by:
getKey
in interfaceOffHeapEntryFactory
- Parameters:
address
- the address of the entry- Returns:
- the bytes for the key
-
fromMemory
public InternalCacheEntry<WrappedBytes,WrappedBytes> fromMemory(long address)
Assumes the address doesn't contain the linked pointer at the beginning- Specified by:
fromMemory
in interfaceOffHeapEntryFactory
- Parameters:
address
- the address to read the entry from- Returns:
- the entry at the memory location
-
equalsKey
public boolean equalsKey(long address, WrappedBytes wrappedBytes)
Assumes the address points to the entry excluding the pointer reference at the beginning- Specified by:
equalsKey
in interfaceOffHeapEntryFactory
- Parameters:
address
- the address of an entry to readwrappedBytes
- the key to check if it equals- Returns:
- whether the key and address are equal
-
isExpired
public boolean isExpired(long address)
Returns whether entry is expired.- Specified by:
isExpired
in interfaceOffHeapEntryFactory
- Parameters:
address
- the address of the entry to check- Returns:
true
if the entry is expired,false
otherwise
-
calculateSize
public long calculateSize(WrappedBytes key, WrappedBytes value, Metadata metadata)
Description copied from interface:OffHeapEntryFactory
Method used to calculate how much memory in size the key, value and metadata use.- Specified by:
calculateSize
in interfaceorg.infinispan.container.impl.KeyValueMetadataSizeCalculator<WrappedBytes,WrappedBytes>
- Specified by:
calculateSize
in interfaceOffHeapEntryFactory
- Parameters:
key
- The key for this entry to be used in size calculationvalue
- The value for this entry to be used in size calculationmetadata
- The metadata for this entry to be used in size calculation- Returns:
- The size approximately in memory the key, value and metadata use.
-
-