Class AbstractDelegatingInternalDataContainer<K,V>

java.lang.Object
org.infinispan.container.impl.AbstractDelegatingInternalDataContainer<K,V>
All Implemented Interfaces:
Iterable<InternalCacheEntry<K,V>>, DataContainer<K,V>, InternalDataContainer<K,V>
Direct Known Subclasses:
SegmentedBoundedOffHeapDataContainer

public abstract class AbstractDelegatingInternalDataContainer<K,V> extends Object implements InternalDataContainer<K,V>
Delegating data container that delegates all calls to the container returned from delegate()
Since:
9.0
Author:
wburns
  • Constructor Details

    • AbstractDelegatingInternalDataContainer

      public AbstractDelegatingInternalDataContainer()
  • Method Details

    • delegate

      protected abstract InternalDataContainer<K,V> delegate()
    • get

      public InternalCacheEntry<K,V> get(Object k)
      Description copied from interface: DataContainer
      Retrieves a cache entry. This will update or reorder internal constructs if necessary such as eviction.
      Specified by:
      get in interface DataContainer<K,V>
      Parameters:
      k - key under which entry is stored
      Returns:
      entry, if it exists, or null if not
    • peek

      public InternalCacheEntry<K,V> peek(Object k)
      Description copied from interface: DataContainer
      Retrieves a cache entry. This method 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.
      Specified by:
      peek in interface DataContainer<K,V>
      Parameters:
      k - key under which entry is stored
      Returns:
      entry, if it exists, or null if not
    • get

      public InternalCacheEntry<K,V> get(int segment, Object k)
      Description copied from interface: InternalDataContainer
      Retrieves from the underlying container, same as InternalDataContainer.peek(int, Object) but also updates any reference for eviction. Note this also doesn't affect expiration in any manner either.
      Specified by:
      get in interface InternalDataContainer<K,V>
      Parameters:
      segment - segment for the key
      k - key under which entry is stored
      Returns:
      entry, if it exists, or null if not
    • peek

      public InternalCacheEntry<K,V> 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<K,V>
      Parameters:
      segment - segment for the key
      k - key under which entry is stored
      Returns:
      entry, if it exists, or null if not
    • touch

      public boolean touch(int segment, Object k, long currentTimeMillis)
      Description copied from interface: InternalDataContainer
      Touches an entry in the data container. This will update the last access time of the entry as well as count this as a access for eviction based recency.
      Specified by:
      touch in interface InternalDataContainer<K,V>
      Parameters:
      segment - segment for the key
      k - key under which entry is stored
      currentTimeMillis - the current time in milliseconds to touch the entry with
      Returns:
      true if the entry timestamp was touched
    • put

      public void put(K k, V v, 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.
      Specified by:
      put in interface DataContainer<K,V>
      Parameters:
      k - key under which to store entry
      v - value to store
      metadata - metadata of the entry
    • put

      public void put(int segment, K k, V v, 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<K,V>
      Parameters:
      segment - segment for the key
      k - key under which to store entry
      v - value to store
      metadata - metadata of the entry
      internalMetadata -
      createdTimestamp - creation timestamp, or -1 to use the current time
      lastUseTimestamp - last use timestamp, or -1 to use the current time
    • 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<K,V>
      Parameters:
      k - key to test
      Returns:
      true if entry exists and has not expired; false otherwise
    • 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<K,V>
      Parameters:
      segment - segment for the key
      k - key under which entry is stored
      Returns:
      true if entry exists and has not expired; false otherwise
    • remove

      public InternalCacheEntry<K,V> remove(Object k)
      Description copied from interface: DataContainer
      Removes an entry from the cache
      Specified by:
      remove in interface DataContainer<K,V>
      Parameters:
      k - key to remove
      Returns:
      entry removed, or null if it didn't exist or had expired
    • remove

      public InternalCacheEntry<K,V> 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<K,V>
      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 void evict(K 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<K,V>
      Parameters:
      key - The key to evict.
    • evict

      public CompletionStage<Void> evict(int segment, K 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<K,V>
      Parameters:
      segment - segment for the key
      key - The key to evict.
    • compute

      public InternalCacheEntry<K,V> compute(K key, DataContainer.ComputeAction<K,V> action)
      Description copied from interface: DataContainer
      Computes the new value for the key. See DataContainer.ComputeAction.compute(Object, org.infinispan.container.entries.InternalCacheEntry, InternalEntryFactory).

      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<K,V>
      Parameters:
      key - The key.
      action - The action that will compute the new value.
      Returns:
      The InternalCacheEntry associated to the key.
    • compute

      public InternalCacheEntry<K,V> compute(int segment, K key, DataContainer.ComputeAction<K,V> 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<K,V>
      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.
    • clear

      public void clear()
      Description copied from interface: DataContainer
      Removes all entries in the container
      Specified by:
      clear in interface DataContainer<K,V>
    • clear

      public void clear(org.infinispan.commons.util.IntSet segments)
      Description copied from interface: InternalDataContainer
      Removes entries from the container whose key maps to one of the provided segments
      Specified by:
      clear in interface InternalDataContainer<K,V>
      Parameters:
      segments - segments of entries to remove
    • spliterator

      public Spliterator<InternalCacheEntry<K,V>> spliterator()
      Description copied from interface: DataContainer

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

      Specified by:
      spliterator in interface DataContainer<K,V>
      Specified by:
      spliterator in interface Iterable<K>
      Returns:
      spliterator that doesn't produce expired entries
    • spliterator

      public Spliterator<InternalCacheEntry<K,V>> 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<K,V>
      Parameters:
      segments - segments of entries to return
      Returns:
      spliterator containing entries mapping to those segments that aren't expired
    • spliteratorIncludingExpired

      public Spliterator<InternalCacheEntry<K,V>> spliteratorIncludingExpired()
      Description copied from interface: DataContainer
      Same as DataContainer.spliterator() except that is also returns expired entries.
      Specified by:
      spliteratorIncludingExpired in interface DataContainer<K,V>
      Returns:
      spliterator that returns all entries including expired ones
    • spliteratorIncludingExpired

      public Spliterator<InternalCacheEntry<K,V>> 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<K,V>
      Parameters:
      segments - segments of entries to use
      Returns:
      spliterator containing entries mapping to those segments that could be expired
    • iterator

      public Iterator<InternalCacheEntry<K,V>> 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<K,V>
      Specified by:
      iterator in interface Iterable<K>
      Returns:
      iterator that doesn't produce expired entries
    • iterator

      public Iterator<InternalCacheEntry<K,V>> 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<K,V>
      Parameters:
      segments - segments of entries to use
      Returns:
      iterator that returns all entries mapped to the given segments
    • iteratorIncludingExpired

      public Iterator<InternalCacheEntry<K,V>> iteratorIncludingExpired()
      Description copied from interface: DataContainer
      Same as DataContainer.iterator() except that is also returns expired entries.
      Specified by:
      iteratorIncludingExpired in interface DataContainer<K,V>
      Returns:
      iterator that returns all entries including expired ones
    • iteratorIncludingExpired

      public Iterator<InternalCacheEntry<K,V>> 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<K,V>
      Parameters:
      segments - segments of entries to use
      Returns:
      iterator that returns all entries mapped to the given segments that could be expired
    • forEach

      public void forEach(Consumer<? super InternalCacheEntry<K,V>> action)
      Specified by:
      forEach in interface Iterable<K>
    • forEach

      public void forEach(org.infinispan.commons.util.IntSet segments, Consumer<? super InternalCacheEntry<K,V>> action)
      Description copied from interface: InternalDataContainer
      Performs the given action for each element of the container that maps to the given set of segments until all elements have been processed or the action throws an exception. Unless otherwise specified by the implementing class, actions are performed in the order of iteration (if an iteration order is specified). Exceptions thrown by the action are relayed to the caller.

      The default implementation behaves as if:

        for (Iterator<InternalCacheEntry<K, V>> iter = iterator(segments) ; iter.hasNext() ; ) {
           InternalCacheEntry<K, V> ice = iter.next();
           action.accept(ice);
        }
      
      Specified by:
      forEach in interface InternalDataContainer<K,V>
      Parameters:
      action - The action to be performed for each element
    • forEachSegment

      public void forEachSegment(ObjIntConsumer<PeekableTouchableMap<K,V>> segmentMapConsumer)
      Description copied from interface: InternalDataContainer
      Performs the given consumer for each map inside this container, once for each segment until all maps have been processed or the action throws an exception. Exceptions thrown by the action are relayed to the caller. The consumer will be provided with the segment as well that maps to the given segment.
      Specified by:
      forEachSegment in interface InternalDataContainer<K,V>
      Parameters:
      segmentMapConsumer - The action to be performed for each element map
    • size

      public int size()
      Specified by:
      size in interface DataContainer<K,V>
      Returns:
      count of the number of entries in the container excluding expired entries Default method invokes the DataContainer.iterator() method and just counts 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<K,V>
      Parameters:
      segments - segments of entries to count
      Returns:
      count of the number of entries in the container excluding expired entries Default method invokes the InternalDataContainer.iterator(IntSet) method and just counts entries.
    • sizeIncludingExpired

      public int sizeIncludingExpired()
      Specified by:
      sizeIncludingExpired in interface DataContainer<K,V>
      Returns:
      count of the number of entries in the container including expired entries
    • 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<K,V>
      Parameters:
      segments - segments of entries to count
      Returns:
      count of the number of entries in the container including expired entries
    • 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<K,V>
      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<K,V>
      Parameters:
      segments - segments that should no longer be associated with this container
    • addRemovalListener

      public void addRemovalListener(Consumer<Iterable<InternalCacheEntry<K,V>>> 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<K,V>
      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<K,V>
      Parameters:
      listener - the listener to remove
    • 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.
      Specified by:
      capacity in interface DataContainer<K,V>
      Returns:
      the capacity of a bounded container
    • 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<K,V>
      Returns:
      how large the counted eviction is
    • resize

      public void resize(long newSize)
      Description copied from interface: DataContainer
      Resizes the capacity of the underlying container. This is only supported if the container is bounded. An UnsupportedOperationException is thrown otherwise.
      Specified by:
      resize in interface DataContainer<K,V>
      Parameters:
      newSize - the new size
    • hasExpirable

      public boolean hasExpirable()
      Description copied from interface: InternalDataContainer
      Verify if the container has entries that can expire. This is __not__ the same thing as verifying for expired entries. This method can return true even if entries are not expired.
      Specified by:
      hasExpirable in interface InternalDataContainer<K,V>
      Returns:
      true if any entry can expire, false otherwise.