Class AbstractInternalDataContainer<K,​V>

    • Constructor Detail

      • AbstractInternalDataContainer

        public AbstractInternalDataContainer()
    • Method Detail

      • getSegmentForKey

        protected abstract int getSegmentForKey​(Object key)
      • peek

        public InternalCacheEntry<K,​V> 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<K,​V>
        Parameters:
        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​(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
        createdTimestamp - creation timestamp, or -1 to use the current time
        lastUseTimestamp - last use timestamp, or -1 to use the current time
      • 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.

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

        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
      • 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
      • 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
      • clear

        public void clear​(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
      • computeEntryWritten

        protected void computeEntryWritten​(K key,
                                           InternalCacheEntry<K,​V> value)
        This method is invoked every time an entry is written inside a compute block
        Parameters:
        key - key passed to compute method
        value - the new value
      • computeEntryRemoved

        protected void computeEntryRemoved​(K key,
                                           InternalCacheEntry<K,​V> value)
        This method is invoked every time an entry is removed inside a compute block
        Parameters:
        key - key passed to compute method
        value - the old value
      • 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.
      • applyListener

        protected com.github.benmanes.caffeine.cache.Caffeine<K,​InternalCacheEntry<K,​V>> applyListener​(com.github.benmanes.caffeine.cache.Caffeine<K,​InternalCacheEntry<K,​V>> caffeine,
                                                                                                                   org.infinispan.container.impl.AbstractInternalDataContainer.DefaultEvictionListener listener)
      • handleEviction

        public static <K,​V> CompletionStage<Void> handleEviction​(InternalCacheEntry<K,​V> entry,
                                                                       DataOperationOrderer orderer,
                                                                       PassivationManager passivator,
                                                                       EvictionManager<K,​V> evictionManager,
                                                                       DataContainer<K,​V> dataContainer,
                                                                       CompletionStage<Void> selfDelay)
        Performs the eviction logic, except it doesn't actually remove the entry from the data container. It will acquire the orderer for the key if necessary (not null), passivate the entry, and notify the listeners, all in a non blocking fashion. The caller MUST hold the data container key lock. If the orderer is null, it means a concurrent write/remove is impossible, so we always passivate and notify the listeners. If the orderer is non-null and the self delay is null, when the orderer stage completes we know both the eviction operation removed the entry from the data container and the other operation removed/updated/inserted the entry, but we don't know the order. We don't care about the order for removals, we always skip passivation. We don't care about the order for activations/other evictions (READ) either, we always perform passivation. For writes we want to passivate only if the entry is no longer in the data container, i.e. the eviction removed the entry last. If the self delay is non-null, we may also acquire the orderer before the eviction operation removes the entry. We have to wait for the delay to complete before passivating the entry, but the scenarios are the same. It doesn't make sense to have a null orderer and a non-null self delay.
        Type Parameters:
        K - key type of the entry
        V - value type of the entry
        Parameters:
        entry - evicted entry
        orderer - used to guarantee ordering between other operations. May be null when an operation is already ordered
        passivator - Passivates the entry to the store if necessary
        evictionManager - Handles additional eviction logic. May be null if eviction is also not required
        dataContainer - container to check if the key has already been removed
        selfDelay - if null, the entry was already removed; if non-null, completes after the eviction finishes removing the entry
        Returns:
        stage that when complete all of the eviction logic is complete
      • filterExpiredEntries

        protected Spliterator<InternalCacheEntry<K,​V>> filterExpiredEntries​(Spliterator<InternalCacheEntry<K,​V>> spliterator)
        Returns a new spliterator that will not return entries that have expired.
        Parameters:
        spliterator - the spliterator to filter expired entries out of
        Returns:
        new spliterator with expired entries filtered
      • expiredIterationPredicate

        protected Predicate<InternalCacheEntry<K,​V>> expiredIterationPredicate​(long accessTime)
        Returns a predicate that will return false when an entry is expired. This predicate assumes this is invoked from an iteration process.
        Parameters:
        accessTime - the access time to base expiration off of
        Returns:
        predicate that returns true if an entry is not expired