Class BoundedOffHeapDataContainer

java.lang.Object
org.infinispan.container.impl.AbstractDelegatingInternalDataContainer<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>
org.infinispan.container.offheap.SegmentedBoundedOffHeapDataContainer
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>, InternalDataContainer<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>

public class BoundedOffHeapDataContainer extends SegmentedBoundedOffHeapDataContainer
Since:
9.4
Author:
wburns
  • Field Details

  • Constructor Details

    • BoundedOffHeapDataContainer

      public BoundedOffHeapDataContainer(long maxSize, EvictionType type)
  • Method Details

    • getMapThatContainsKey

      protected OffHeapConcurrentMap getMapThatContainsKey(byte[] key)
      Overrides:
      getMapThatContainsKey in class SegmentedBoundedOffHeapDataContainer
    • 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>
      Overrides:
      containsKey in class AbstractDelegatingInternalDataContainer<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
    • 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>
      Overrides:
      peek in class AbstractDelegatingInternalDataContainer<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
    • get

      public InternalCacheEntry<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes> get(Object k)
      Description copied from interface: InternalDataContainer
      Retrieves a cached entry

      We should only ever be using the non blocking variant InternalDataContainer.peek(int, Object) in Infinispan

      Specified by:
      get in interface DataContainer<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>
      Specified by:
      get in interface InternalDataContainer<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>
      Overrides:
      get in class AbstractDelegatingInternalDataContainer<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
    • 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.

      See DataContainer.ComputeAction.compute(Object, org.infinispan.container.entries.InternalCacheEntry, InternalEntryFactory).

      The key must be activated by invoking ActivationManager.activateAsync(Object, int).

      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 interface DataContainer<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>
      Overrides:
      compute in class SegmentedBoundedOffHeapDataContainer
      Parameters:
      key - The key.
      action - The action that will compute the new value.
      Returns:
      The InternalCacheEntry associated to the key.
    • remove

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

      The key must be activate by invoking ActivationManager.activateAsync(Object, int)

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

      public void evict(org.infinispan.commons.marshall.WrappedBytes key)
      Description copied from interface: DataContainer
      Atomically, it removes the key from DataContainer and passivates it to persistence.

      The passivation must be done by invoking the method PassivationManager.passivateAsync(InternalCacheEntry).

      Specified by:
      evict in interface DataContainer<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>
      Overrides:
      evict in class AbstractDelegatingInternalDataContainer<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>
      Parameters:
      key - The key to evict.
    • 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.activateAsync(Object, int) boolean)}.

      Specified by:
      put in interface DataContainer<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>
      Overrides:
      put in class SegmentedBoundedOffHeapDataContainer
      Parameters:
      key - key under which to store entry
      value - value to store
      metadata - metadata of the entry
    • containsKey

      public boolean containsKey(int segment, Object k)
      Description copied from interface: InternalDataContainer
      Same as DataContainer.containsKey(Object) except that the segment of the key can provided to lookup if the entry exists without calculating the segment for the given key.
      Specified by:
      containsKey in interface InternalDataContainer<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>
      Overrides:
      containsKey in class AbstractDelegatingInternalDataContainer<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>
      Parameters:
      segment - segment for the key
      k - key under which entry is stored
      Returns:
      true if entry exists and has not expired; false otherwise
    • peek

      public InternalCacheEntry<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes> peek(int segment, Object k)
      Description copied from interface: InternalDataContainer
      Same as DataContainer.peek(Object) except that the segment of the key can provided to lookup entries without calculating the segment for the given key
      Specified by:
      peek in interface InternalDataContainer<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>
      Overrides:
      peek in class AbstractDelegatingInternalDataContainer<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>
      Parameters:
      segment - segment for the key
      k - key under which entry is stored
      Returns:
      entry, if it exists, or null if not
    • get

      public InternalCacheEntry<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes> get(int segment, Object k)
      Description copied from interface: InternalDataContainer
      Same as DataContainer.get(Object) except that the segment of the key can provided to lookup entries without calculating the segment for the given key
      Specified by:
      get in interface InternalDataContainer<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>
      Overrides:
      get in class AbstractDelegatingInternalDataContainer<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>
      Parameters:
      segment - segment for the key
      k - key under which entry is stored
      Returns:
      entry, if it exists and has not expired, or null if not
    • compute

      public InternalCacheEntry<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes> compute(int segment, org.infinispan.commons.marshall.WrappedBytes key, DataContainer.ComputeAction<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes> action)
      Description copied from interface: InternalDataContainer
      Same as DataContainer.compute(Object, ComputeAction) except that the segment of the key can provided to update entries without calculating the segment for the given key.
      Specified by:
      compute in interface InternalDataContainer<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>
      Overrides:
      compute in class SegmentedBoundedOffHeapDataContainer
      Parameters:
      segment - segment for the key
      key - The key.
      action - The action that will compute the new value.
      Returns:
      The InternalCacheEntry associated to the key.
    • remove

      public InternalCacheEntry<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes> remove(int segment, Object k)
      Description copied from interface: InternalDataContainer
      Same as DataContainer.remove(Object) except that the segment of the key can provided to remove the entry without calculating the segment for the given key.
      Specified by:
      remove in interface InternalDataContainer<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>
      Overrides:
      remove in class AbstractDelegatingInternalDataContainer<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>
      Parameters:
      segment - segment for the key
      k - key to remove
      Returns:
      entry removed, or null if it didn't exist or had expired
    • evict

      public CompletionStage<Void> evict(int segment, org.infinispan.commons.marshall.WrappedBytes key)
      Description copied from interface: InternalDataContainer
      Same as DataContainer.evict(Object) except that the segment of the key can provided to remove the entry without calculating the segment for the given key.
      Specified by:
      evict in interface InternalDataContainer<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>
      Overrides:
      evict in class AbstractDelegatingInternalDataContainer<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>
      Parameters:
      segment - segment for the key
      key - The key to evict.
    • put

      public void put(int segment, org.infinispan.commons.marshall.WrappedBytes key, org.infinispan.commons.marshall.WrappedBytes value, Metadata metadata, PrivateMetadata internalMetadata, long createdTimestamp, long lastUseTimestamp)
      Description copied from interface: InternalDataContainer
      Same as DataContainer.put(Object, Object, Metadata) except that the segment of the key can provided to write/lookup entries without calculating the segment for the given key.

      Note: The timestamps ignored if the entry already exists in the data container.

      Specified by:
      put in interface InternalDataContainer<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>
      Overrides:
      put in class SegmentedBoundedOffHeapDataContainer
      Parameters:
      segment - segment for the key
      key - key under which to store entry
      value - value to store
      metadata - metadata of the entry
      createdTimestamp - creation timestamp, or -1 to use the current time
      lastUseTimestamp - last use timestamp, or -1 to use the current time
    • spliterator

      public Spliterator<InternalCacheEntry<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>> spliterator(org.infinispan.commons.util.IntSet segments)
      Description copied from interface: InternalDataContainer
      Same as DataContainer.spliterator() except that only entries that map to the provided segments are returned via this spliterator. The spliterator will not return expired entries.
      Specified by:
      spliterator in interface InternalDataContainer<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>
      Overrides:
      spliterator in class AbstractDelegatingInternalDataContainer<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>
      Parameters:
      segments - segments of entries to return
      Returns:
      spliterator containing entries mapping to those segments that aren't expired
    • spliteratorIncludingExpired

      public Spliterator<InternalCacheEntry<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>> spliteratorIncludingExpired(org.infinispan.commons.util.IntSet segments)
      Description copied from interface: InternalDataContainer
      Same as DataContainer.spliteratorIncludingExpired() except that only entries that map to the provided segments are returned via this spliterator. The spliterator will return expired entries as well.
      Specified by:
      spliteratorIncludingExpired in interface InternalDataContainer<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>
      Overrides:
      spliteratorIncludingExpired in class AbstractDelegatingInternalDataContainer<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>
      Parameters:
      segments - segments of entries to use
      Returns:
      spliterator containing entries mapping to those segments that could be expired
    • iterator

      public Iterator<InternalCacheEntry<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>> iterator(org.infinispan.commons.util.IntSet segments)
      Description copied from interface: InternalDataContainer
      Same as DataContainer.iterator() except that only entries that map to the provided segments are returned via the iterator. The iterator will not return expired entries.
      Specified by:
      iterator in interface InternalDataContainer<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>
      Overrides:
      iterator in class AbstractDelegatingInternalDataContainer<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>
      Parameters:
      segments - segments of entries to use
      Returns:
      iterator that returns all entries mapped to the given segments
    • iteratorIncludingExpired

      public Iterator<InternalCacheEntry<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>> iteratorIncludingExpired(org.infinispan.commons.util.IntSet segments)
      Description copied from interface: InternalDataContainer
      Same as DataContainer.iteratorIncludingExpired() except that only entries that map to the provided segments are returned via the iterator. The iterator can return expired entries.
      Specified by:
      iteratorIncludingExpired in interface InternalDataContainer<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>
      Overrides:
      iteratorIncludingExpired in class AbstractDelegatingInternalDataContainer<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>
      Parameters:
      segments - segments of entries to use
      Returns:
      iterator that returns all entries mapped to the given segments that could be expired
    • sizeIncludingExpired

      public int sizeIncludingExpired(org.infinispan.commons.util.IntSet segments)
      Description copied from interface: InternalDataContainer
      Returns how many entries are present in the data container that map to the given segments including any entries that may be expired
      Specified by:
      sizeIncludingExpired in interface InternalDataContainer<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>
      Overrides:
      sizeIncludingExpired in class AbstractDelegatingInternalDataContainer<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>
      Parameters:
      segments - segments of entries to count
      Returns:
      count of the number of entries in the container including expired entries
    • size

      public int size(org.infinispan.commons.util.IntSet segments)
      Description copied from interface: InternalDataContainer
      Returns how many entries are present in the data container that map to the given segments without counting entries that are currently expired.
      Specified by:
      size in interface InternalDataContainer<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>
      Overrides:
      size in class AbstractDelegatingInternalDataContainer<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>
      Parameters:
      segments - segments of entries to count
      Returns:
      count of the number of entries in the container excluding expired entries
    • addRemovalListener

      public void addRemovalListener(Consumer<Iterable<InternalCacheEntry<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>>> listener)
      Description copied from interface: InternalDataContainer
      Adds a listener that is invoked whenever InternalDataContainer.removeSegments(IntSet) is invoked providing a way for the listener to see what actual entries were removed from the container.
      Specified by:
      addRemovalListener in interface InternalDataContainer<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>
      Overrides:
      addRemovalListener in class AbstractDelegatingInternalDataContainer<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>
      Parameters:
      listener - listener that invoked of removed entries
    • removeRemovalListener

      public void removeRemovalListener(Object listener)
      Description copied from interface: InternalDataContainer
      Removes a previously registered listener via InternalDataContainer.addRemovalListener(Consumer).
      Specified by:
      removeRemovalListener in interface InternalDataContainer<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>
      Overrides:
      removeRemovalListener in class AbstractDelegatingInternalDataContainer<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>
      Parameters:
      listener - the listener to remove
    • addSegments

      public void addSegments(org.infinispan.commons.util.IntSet segments)
      Description copied from interface: InternalDataContainer
      Sets what segments this data container should be using. Already associated segments are unaffected by this and takes a union of existing and new segments.
      Specified by:
      addSegments in interface InternalDataContainer<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>
      Overrides:
      addSegments in class AbstractDelegatingInternalDataContainer<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>
      Parameters:
      segments - segments to associate with this container
    • removeSegments

      public void removeSegments(org.infinispan.commons.util.IntSet segments)
      Description copied from interface: InternalDataContainer
      Removes and un-associates the given segments. This will notify any listeners registered via InternalDataContainer.addRemovalListener(Consumer) of entries that were removed due to no longer being associated with this container. There is no guarantee if the consumer is invoked once or multiple times for a given group of segments and could be in any order.

      When this method is invoked an implementation is free to remove any entries that don't map to segments currently associated with this container. Note that entries that were removed due to their segments never being associated with this container do not notify listeners registered via InternalDataContainer.addRemovalListener(Consumer).

      Specified by:
      removeSegments in interface InternalDataContainer<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>
      Overrides:
      removeSegments in class AbstractDelegatingInternalDataContainer<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>
      Parameters:
      segments - segments that should no longer be associated with this container