Class OffHeapDataContainer

  • 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>
    Direct Known Subclasses:
    BoundedOffHeapDataContainer

    public class OffHeapDataContainer
    extends Object
    implements DataContainer<org.infinispan.commons.marshall.WrappedBytes,​org.infinispan.commons.marshall.WrappedBytes>
    Data Container implementation that stores entries in native memory (off-heap).
    Since:
    9.0
    Author:
    wburns
    • Constructor Detail

      • OffHeapDataContainer

        public OffHeapDataContainer​(int desiredSize)
    • Method Detail

      • getActualAddressCount

        public static int getActualAddressCount​(int desiredSize)
      • start

        public void start()
      • stop

        public void stop()
        Clears the memory lookups and cache data.
      • checkDeallocation

        protected void checkDeallocation()
      • get

        public InternalCacheEntry<org.infinispan.commons.marshall.WrappedBytes,​org.infinispan.commons.marshall.WrappedBytes> get​(Object k)
        Description copied from interface: DataContainer
        Retrieves a cached entry
        Specified by:
        get in interface DataContainer<org.infinispan.commons.marshall.WrappedBytes,​org.infinispan.commons.marshall.WrappedBytes>
        Parameters:
        k - key under which entry is stored
        Returns:
        entry, if it exists and has not expired, or null if not
      • peek

        public InternalCacheEntry<org.infinispan.commons.marshall.WrappedBytes,​org.infinispan.commons.marshall.WrappedBytes> peek​(Object k)
        Description copied from interface: DataContainer
        Retrieves a cache entry in the same way as DataContainer.get(Object)} except that it does not update or reorder any of the internal constructs. I.e., expiration does not happen, and in the case of the LRU container, the entry is not moved to the end of the chain.

        This method should be used instead of DataContainer.get(Object)} when called while iterating through the data container using methods like DataContainer.iterator() to avoid changing the underlying collection's order.

        Specified by:
        peek in interface DataContainer<org.infinispan.commons.marshall.WrappedBytes,​org.infinispan.commons.marshall.WrappedBytes>
        Parameters:
        k - key under which entry is stored
        Returns:
        entry, if it exists, or null if not
      • performGet

        protected long performGet​(long bucketHeadAddress,
                                  Object k,
                                  boolean returnExpired)
        Gets the actual address for the given key in the given bucket or 0 if it isn't present or expired
        Parameters:
        bucketHeadAddress - the starting address of the address hash
        k - the key to retrieve the address for it if matches
        Returns:
        the address matching the key or 0
      • 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>
        Parameters:
        key - key under which to store entry
        value - value to store
        metadata - metadata of the entry
      • performPut

        protected boolean performPut​(long bucketHeadAddress,
                                     long actualAddress,
                                     long newAddress,
                                     org.infinispan.commons.marshall.WrappedBytes key)
        Performs the actual put operation putting the new address into the memory lookups. The write lock for the given key must be held before calling this method.
        Parameters:
        bucketHeadAddress - the entry address of the first element in the lookup
        actualAddress - the actual address if it is known or 0. By passing this != 0 equality checks can be bypassed. If a value of 0 is provided this will use key equality.
        newAddress - the address of the new entry
        key - the key of the entry
        Returns:
        true if the entry doesn't exists in memory and was newly create, false otherwise
      • entryCreated

        protected void entryCreated​(long newAddress)
        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.
        Parameters:
        newAddress - the address just created that will be the new entry
      • entryReplaced

        protected void entryReplaced​(long newAddress,
                                     long oldAddress)
        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.
        Parameters:
        newAddress - the address just created that will be the new entry
        oldAddress - the old address for this entry that will be soon removed
      • entryRemoved

        protected void entryRemoved​(long removedAddress)
        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.
        Parameters:
        removedAddress - the address about to be removed
      • containsKey

        public boolean containsKey​(Object k)
        Description copied from interface: DataContainer
        Tests whether an entry exists in the container
        Specified by:
        containsKey in interface DataContainer<org.infinispan.commons.marshall.WrappedBytes,​org.infinispan.commons.marshall.WrappedBytes>
        Parameters:
        k - key to test
        Returns:
        true if entry exists and has not expired; false otherwise
      • entryRetrieved

        protected void entryRetrieved​(long entryAddress)
        Invoked when an entry is successfully retrieved. The read lock will already be acquired for the given segment the key mapped to.
        Parameters:
        entryAddress -
      • remove

        public InternalCacheEntry<org.infinispan.commons.marshall.WrappedBytes,​org.infinispan.commons.marshall.WrappedBytes> remove​(Object key)
        Description copied from interface: DataContainer
        Removes an entry from the cache

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

        Specified by:
        remove in interface DataContainer<org.infinispan.commons.marshall.WrappedBytes,​org.infinispan.commons.marshall.WrappedBytes>
        Parameters:
        key - key to remove
        Returns:
        entry removed, or null if it didn't exist or had expired
      • performRemove

        protected InternalCacheEntry<org.infinispan.commons.marshall.WrappedBytes,​org.infinispan.commons.marshall.WrappedBytes> performRemove​(long bucketHeadAddress,
                                                                                                                                                    long actualAddress,
                                                                                                                                                    Object key,
                                                                                                                                                    boolean requireReturn)
        Performs the actual remove operation removing the new address from the memory lookups. The write lock for the given key must be held before calling this method.
        Parameters:
        bucketHeadAddress - the starting address of the address hash
        actualAddress - the actual address if it is known or 0. By passing this != 0 equality checks can be bypassed. If a value of 0 is provided this will use key equality.
        key - the key of the entry
        requireReturn - whether this method is forced to return the entry removed (optimizations can be done if the entry is not needed)
      • size

        public int size()
        Specified by:
        size in interface DataContainer<org.infinispan.commons.marshall.WrappedBytes,​org.infinispan.commons.marshall.WrappedBytes>
        Returns:
        count of the number of entries in the container excluding expired entries
      • sizeIncludingExpired

        public int sizeIncludingExpired()
        Specified by:
        sizeIncludingExpired in interface DataContainer<org.infinispan.commons.marshall.WrappedBytes,​org.infinispan.commons.marshall.WrappedBytes>
        Returns:
        count of the number of entries in the container including expired entries
      • clear

        public void clear()
        Description copied from interface: DataContainer
        Removes all entries in the container
        Specified by:
        clear in interface DataContainer<org.infinispan.commons.marshall.WrappedBytes,​org.infinispan.commons.marshall.WrappedBytes>
      • performClear

        protected void performClear()
      • keySet

        public Set<org.infinispan.commons.marshall.WrappedBytes> keySet()
        Description copied from interface: DataContainer
        Returns a set of keys in the container. When iterating through the container using this method, clients should never call DataContainer.get(Object) method but instead DataContainer.peek(Object), in order to avoid changing the order of the underlying collection as a side of effect of iterating through it.

        This set of keys will include expired entries. If you wish to only retrieve non expired keys please use the DataContainer.iterator() method and retrieve keys from there.

        Specified by:
        keySet in interface DataContainer<org.infinispan.commons.marshall.WrappedBytes,​org.infinispan.commons.marshall.WrappedBytes>
        Returns:
        a set of keys
      • values

        public Collection<org.infinispan.commons.marshall.WrappedBytes> values()
        Description copied from interface: DataContainer
        This returns all values in the container including expired entries. If you wish to only receive values that are not expired it is recommended to use DataContainer.entrySet() and pull values from there directly.
        Specified by:
        values in interface DataContainer<org.infinispan.commons.marshall.WrappedBytes,​org.infinispan.commons.marshall.WrappedBytes>
        Returns:
        a set of values contained in the container
      • entrySet

        public Set<InternalCacheEntry<org.infinispan.commons.marshall.WrappedBytes,​org.infinispan.commons.marshall.WrappedBytes>> entrySet()
        Description copied from interface: DataContainer
        Returns a mutable set of immutable cache entries exposed as immutable Map.Entry instances. Clients of this method such as Cache.entrySet() operation implementors are free to convert the set into an immutable set if needed, which is the most common use case.

        If a client needs to iterate through a mutable set of mutable cache entries, it should iterate the container itself rather than iterating through the return of entrySet().

        This set is a read only backed view of the entries underneath. This set will only show non expired entries when invoked. The size method of the set will count expired entries for the purpose of having a O(1) time cost compared to O(N) if it is to not count expired entries.

        Specified by:
        entrySet in interface DataContainer<org.infinispan.commons.marshall.WrappedBytes,​org.infinispan.commons.marshall.WrappedBytes>
        Returns:
        a set of immutable cache entries
      • executeTask

        public void executeTask​(KeyFilter<? super org.infinispan.commons.marshall.WrappedBytes> filter,
                                BiConsumer<? super org.infinispan.commons.marshall.WrappedBytes,​InternalCacheEntry<org.infinispan.commons.marshall.WrappedBytes,​org.infinispan.commons.marshall.WrappedBytes>> action)
                         throws InterruptedException
        Description copied from interface: DataContainer
        Executes task specified by the given action on the container key/values filtered using the specified key filter.
        Specified by:
        executeTask in interface DataContainer<org.infinispan.commons.marshall.WrappedBytes,​org.infinispan.commons.marshall.WrappedBytes>
        Parameters:
        filter - the filter for the container keys
        action - the specified action to execute on filtered key/values
        Throws:
        InterruptedException
      • executeTask

        public void executeTask​(KeyValueFilter<? super org.infinispan.commons.marshall.WrappedBytes,​? super org.infinispan.commons.marshall.WrappedBytes> filter,
                                BiConsumer<? super org.infinispan.commons.marshall.WrappedBytes,​InternalCacheEntry<org.infinispan.commons.marshall.WrappedBytes,​org.infinispan.commons.marshall.WrappedBytes>> action)
                         throws InterruptedException
        Description copied from interface: DataContainer
        Executes task specified by the given action on the container key/values filtered using the specified keyvalue filter.
        Specified by:
        executeTask in interface DataContainer<org.infinispan.commons.marshall.WrappedBytes,​org.infinispan.commons.marshall.WrappedBytes>
        Parameters:
        filter - the filter for the container key/values
        action - the specified action to execute on filtered key/values
        Throws:
        InterruptedException
      • iterator

        public Iterator<InternalCacheEntry<org.infinispan.commons.marshall.WrappedBytes,​org.infinispan.commons.marshall.WrappedBytes>> iterator()
        Description copied from interface: DataContainer

        This iterator only returns entries that are not expired, however it will not remove them while doing so.

        Specified by:
        iterator in interface DataContainer<org.infinispan.commons.marshall.WrappedBytes,​org.infinispan.commons.marshall.WrappedBytes>
        Specified by:
        iterator in interface Iterable<InternalCacheEntry<org.infinispan.commons.marshall.WrappedBytes,​org.infinispan.commons.marshall.WrappedBytes>>
        Returns:
        iterator that doesn't produce expired entries
      • iteratorIncludingExpired

        public Iterator<InternalCacheEntry<org.infinispan.commons.marshall.WrappedBytes,​org.infinispan.commons.marshall.WrappedBytes>> iteratorIncludingExpired()
        Description copied from interface: DataContainer
        Same as DataContainer.iterator() except that is also returns expired entries.
        Specified by:
        iteratorIncludingExpired in interface DataContainer<org.infinispan.commons.marshall.WrappedBytes,​org.infinispan.commons.marshall.WrappedBytes>
        Returns:
        iterator that returns all entries including expired ones
      • 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. An UnsupportedOperationException is thrown otherwise. This value will always be lower than the value returned from DataContainer.capacity()
        Specified by:
        evictionSize in interface DataContainer<org.infinispan.commons.marshall.WrappedBytes,​org.infinispan.commons.marshall.WrappedBytes>
        Returns:
        how large the counted eviction is
      • getLog

        public Log getLog()