Package org.infinispan.container.offheap
Class BoundedOffHeapDataContainer
- java.lang.Object
-
- org.infinispan.container.offheap.OffHeapDataContainer
-
- org.infinispan.container.offheap.BoundedOffHeapDataContainer
-
- All Implemented Interfaces:
Iterable<InternalCacheEntry<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>>
,DataContainer<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>
public class BoundedOffHeapDataContainer extends OffHeapDataContainer
Data Container implementation that stores entries in native memory (off-heap) that is also bounded. This implementation uses a simple LRU doubly linked list off-heap guarded by a single lock.The link list is represented by firstAddress as the had of the list and lastAddress as the tail of the list. Each entry in the list consists of 28 bytes (3 longs and 1 int), the first long is the actual entry address, the second is a pointer to the previous element in the list, the third is the next pointer and lastly the int is the hashCode of the key to retrieve the lock. The hashCode is required to know which lock to use when trying to read the entry.
- Since:
- 9.0
- Author:
- wburns
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.infinispan.container.DataContainer
DataContainer.ComputeAction<K,V>
-
-
Field Summary
Fields Modifier and Type Field Description protected long
currentSize
protected long
firstAddress
protected long
initialSize
protected long
lastAddress
protected Lock
lruLock
protected long
maxSize
protected LongUnaryOperator
sizeCalculator
-
Fields inherited from class org.infinispan.container.offheap.OffHeapDataContainer
activator, allocator, evictionManager, internalEntryFactory, lockCount, locks, memoryAddressCount, memoryLookup, offHeapEntryFactory, passivator, size, timeService, trace
-
-
Constructor Summary
Constructors Constructor Description BoundedOffHeapDataContainer(int desiredSize, long maxSize, EvictionType type)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description long
capacity()
Returns the capacity of the underlying container.InternalCacheEntry<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>
compute(org.infinispan.commons.marshall.WrappedBytes key, DataContainer.ComputeAction<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes> action)
Computes the new value for the key.protected void
entryCreated(long newAddress)
Invoked when an entry is about to be created.protected void
entryRemoved(long removedAddress)
Invoked when an entry is about to be removed.protected void
entryReplaced(long newAddress, long oldAddress)
Invoked when an entry is about to be replaced with a new one.protected void
entryRetrieved(long entryAddress)
Invoked when an entry is successfully retrieved.long
evictionSize()
Returns how large the eviction size is currently.Log
getLog()
protected void
performClear()
void
put(org.infinispan.commons.marshall.WrappedBytes key, org.infinispan.commons.marshall.WrappedBytes value, Metadata metadata)
Puts an entry in the cache along with metadata adding information such lifespan of entry, max idle time, version information...etc.-
Methods inherited from class org.infinispan.container.offheap.OffHeapDataContainer
checkDeallocation, clear, containsKey, entrySet, evict, executeTask, executeTask, get, getActualAddressCount, iterator, iteratorIncludingExpired, keySet, peek, performGet, performPut, performRemove, remove, size, sizeIncludingExpired, start, stop, values
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.infinispan.container.DataContainer
resize, spliterator, spliteratorIncludingExpired
-
-
-
-
Field Detail
-
maxSize
protected final long maxSize
-
lruLock
protected final Lock lruLock
-
sizeCalculator
protected final LongUnaryOperator sizeCalculator
-
initialSize
protected final long initialSize
-
currentSize
protected long currentSize
-
firstAddress
protected long firstAddress
-
lastAddress
protected long lastAddress
-
-
Constructor Detail
-
BoundedOffHeapDataContainer
public BoundedOffHeapDataContainer(int desiredSize, long maxSize, EvictionType type)
-
-
Method Detail
-
put
public void put(org.infinispan.commons.marshall.WrappedBytes key, org.infinispan.commons.marshall.WrappedBytes value, Metadata metadata)
Description copied from interface:DataContainer
Puts an entry in the cache along with metadata adding information such lifespan of entry, max idle time, version information...etc. Thekey
must be activate by invokingActivationManager.onUpdate(Object, boolean)
.- Specified by:
put
in interfaceDataContainer<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>
- Overrides:
put
in classOffHeapDataContainer
- Parameters:
key
- key under which to store entryvalue
- value to storemetadata
- metadata of the entry
-
compute
public InternalCacheEntry<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes> compute(org.infinispan.commons.marshall.WrappedBytes key, DataContainer.ComputeAction<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes> action)
Description copied from interface:DataContainer
Computes the new value for the key. SeeDataContainer.ComputeAction.compute(Object, org.infinispan.container.entries.InternalCacheEntry, InternalEntryFactory)
. Thekey
must be activate by invokingActivationManager.onRemove(Object, boolean)
orActivationManager.onUpdate(Object, boolean)
depending if the value returned by theDataContainer.ComputeAction
is null or not respectively.Note the entry provided to
DataContainer.ComputeAction
may be expired as these entries are not filtered as many other methods do.- Specified by:
compute
in interfaceDataContainer<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>
- Overrides:
compute
in classOffHeapDataContainer
- Parameters:
key
- The key.action
- The action that will compute the new value.- Returns:
- The
InternalCacheEntry
associated to the key.
-
entryReplaced
protected void entryReplaced(long newAddress, long oldAddress)
Description copied from class:OffHeapDataContainer
Invoked when an entry is about to be replaced with a new one. The old and new address are both addressable, however oldAddress may be freed after this method returns. The write lock will already be acquired for the given segment the key mapped to.- Overrides:
entryReplaced
in classOffHeapDataContainer
- Parameters:
newAddress
- the address just created that will be the new entryoldAddress
- the old address for this entry that will be soon removed
-
entryCreated
protected void entryCreated(long newAddress)
Description copied from class:OffHeapDataContainer
Invoked when an entry is about to be created. The new address is fully addressable, The write lock will already be acquired for the given segment the key mapped to.- Overrides:
entryCreated
in classOffHeapDataContainer
- Parameters:
newAddress
- the address just created that will be the new entry
-
entryRemoved
protected void entryRemoved(long removedAddress)
Description copied from class:OffHeapDataContainer
Invoked when an entry is about to be removed. You can read values from this but after this method is completed this memory address may be freed. The write lock will already be acquired for the given segment the key mapped to.- Overrides:
entryRemoved
in classOffHeapDataContainer
- Parameters:
removedAddress
- the address about to be removed
-
entryRetrieved
protected void entryRetrieved(long entryAddress)
Description copied from class:OffHeapDataContainer
Invoked when an entry is successfully retrieved. The read lock will already be acquired for the given segment the key mapped to.- Overrides:
entryRetrieved
in classOffHeapDataContainer
-
performClear
protected void performClear()
- Overrides:
performClear
in classOffHeapDataContainer
-
capacity
public long capacity()
Description copied from interface:DataContainer
Returns the capacity of the underlying container. This is only supported if the container is bounded. AnUnsupportedOperationException
is thrown otherwise.- Returns:
-
evictionSize
public long evictionSize()
Description copied from interface:DataContainer
Returns how large the eviction size is currently. This is only supported if the container is bounded. AnUnsupportedOperationException
is thrown otherwise. This value will always be lower than the value returned fromDataContainer.capacity()
- Specified by:
evictionSize
in interfaceDataContainer<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>
- Overrides:
evictionSize
in classOffHeapDataContainer
- Returns:
- how large the counted eviction is
-
getLog
public Log getLog()
- Overrides:
getLog
in classOffHeapDataContainer
-
-