Class 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
    • Field Detail

      • maxSize

        protected final long maxSize
      • lruLock

        protected final Lock lruLock
      • 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.

        The key must be activate by invoking ActivationManager.onUpdate(Object, boolean).

        Specified by:
        put in interface DataContainer<org.infinispan.commons.marshall.WrappedBytes,​org.infinispan.commons.marshall.WrappedBytes>
        Overrides:
        put in class OffHeapDataContainer
        Parameters:
        key - key under which to store entry
        value - value to store
        metadata - metadata of the entry
      • 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 class OffHeapDataContainer
        Parameters:
        newAddress - the address just created that will be the new entry
        oldAddress - 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 class OffHeapDataContainer
        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 class OffHeapDataContainer
        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 class OffHeapDataContainer
      • 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. An UnsupportedOperationException is thrown otherwise.
        Returns: