Package org.infinispan.container.impl
Class AbstractInternalDataContainer<K,V>
java.lang.Object
org.infinispan.container.impl.AbstractInternalDataContainer<K,V>
- All Implemented Interfaces:
Iterable<InternalCacheEntry<K,
,V>> DataContainer<K,
,V> InternalDataContainer<K,
V>
- Direct Known Subclasses:
DefaultDataContainer
,DefaultSegmentedDataContainer
,OffHeapDataContainer
public abstract class AbstractInternalDataContainer<K,V>
extends Object
implements InternalDataContainer<K,V>
Abstract class implemenation for a segmented data container. All methods delegate to
getSegmentForKey(Object)
for methods that don't provide a segment and implementors can provide what
map we should look into for a given segment via getMapForSegment(int)
.- Since:
- 9.3
- Author:
- wburns
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.infinispan.container.DataContainer
DataContainer.ComputeAction<K,
V> -
Field Summary
Modifier and TypeFieldDescriptionprotected Configuration
protected InternalEntryFactory
protected EvictionManager<K,
V> protected InternalExpirationManager<K,
V> protected KeyPartitioner
protected DataOperationOrderer
protected ComponentRef<PassivationManager>
protected TimeService
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addRemovalListener
(Consumer<Iterable<InternalCacheEntry<K, V>>> listener) Adds a listener that is invoked wheneverInternalDataContainer.removeSegments(IntSet)
is invoked providing a way for the listener to see what actual entries were removed from the container.protected com.github.benmanes.caffeine.cache.Caffeine<K,
InternalCacheEntry<K, V>> applyListener
(com.github.benmanes.caffeine.cache.Caffeine<K, InternalCacheEntry<K, V>> caffeine, AbstractInternalDataContainer<K, V>.org.infinispan.container.impl.AbstractInternalDataContainer.DefaultEvictionListener listener) void
Removes entries from the container whose key maps to one of the provided segmentscompute
(int segment, K key, DataContainer.ComputeAction<K, V> action) Same asDataContainer.compute(Object, ComputeAction)
except that the segment of the key can provided to update entries without calculating the segment for the given key.compute
(K key, DataContainer.ComputeAction<K, V> action) Computes the new value for the key.protected void
computeEntryRemoved
(K key, InternalCacheEntry<K, V> value) This method is invoked every time an entry is removed inside a compute blockprotected void
computeEntryWritten
(K key, InternalCacheEntry<K, V> value) This method is invoked every time an entry is written inside a compute blockboolean
containsKey
(int segment, Object k) Same asDataContainer.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.boolean
Tests whether an entry exists in the containerprotected final void
entryAdded
(InternalCacheEntry<K, V> ice) protected final void
entryRemoved
(InternalCacheEntry<K, V> ice) protected final void
entryUpdated
(InternalCacheEntry<K, V> curr, InternalCacheEntry<K, V> prev) Same asDataContainer.evict(Object)
except that the segment of the key can provided to remove the entry without calculating the segment for the given key.void
Atomically, it removes the key fromDataContainer
and passivates it to persistence.protected Predicate<InternalCacheEntry<K,
V>> expiredIterationPredicate
(long accessTime) Returns a predicate that will return false when an entry is expired.protected Spliterator<InternalCacheEntry<K,
V>> filterExpiredEntries
(Spliterator<InternalCacheEntry<K, V>> spliterator) Returns a new spliterator that will not return entries that have expired.Same asDataContainer.get(Object)
except that the segment of the key can provided to lookup entries without calculating the segment for the given keyRetrieves a cached entryprotected abstract PeekableTouchableMap<K,
V> getMapForSegment
(int segment) protected abstract int
getSegmentForKey
(Object key) static <K,
V> CompletionStage<Void> handleEviction
(InternalCacheEntry<K, V> entry, DataOperationOrderer orderer, PassivationManager passivator, EvictionManager<K, V> evictionManager, DataContainer<K, V> dataContainer, Executor nonBlockingExecutor, CompletionStage<Void> selfDelay) Performs the eviction logic, except it doesn't actually remove the entry from the data container.boolean
Verify if the container has entries that can expire.Same asDataContainer.peek(Object)
except that the segment of the key can provided to lookup entries without calculating the segment for the given keyRetrieves a cache entry in the same way asDataContainer.get(Object)
} except that it does not update or reorder any of the internal constructs.void
put
(int segment, K k, V v, Metadata metadata, PrivateMetadata internalMetadata, long createdTimestamp, long lastUseTimestamp) Same asDataContainer.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.void
Puts an entry in the cache along with metadata adding information such lifespan of entry, max idle time, version information...etc.protected void
putEntryInMap
(PeekableTouchableMap<K, V> map, int segment, K key, InternalCacheEntry<K, V> ice) Same asDataContainer.remove(Object)
except that the segment of the key can provided to remove the entry without calculating the segment for the given key.Removes an entry from the cacheprotected InternalCacheEntry<K,
V> removeEntryInMap
(PeekableTouchableMap<K, V> map, int segment, Object key) void
removeRemovalListener
(Object listener) Removes a previously registered listener viaInternalDataContainer.addRemovalListener(Consumer)
.protected final void
segmentRemoved
(Map<K, InternalCacheEntry<K, V>> segment) boolean
Touches an entry in the data container.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.infinispan.container.DataContainer
capacity, clear, evictionSize, iterator, iteratorIncludingExpired, resize, size, sizeIncludingExpired, spliterator, spliteratorIncludingExpired
Methods inherited from interface org.infinispan.container.impl.InternalDataContainer
addSegments, cleanUp, forEach, forEachSegment, iterator, iteratorIncludingExpired, publisher, publisher, removeSegments, size, sizeIncludingExpired, spliterator, spliteratorIncludingExpired
-
Field Details
-
timeService
-
evictionManager
-
expirationManager
-
entryFactory
-
passivator
-
configuration
-
keyPartitioner
-
orderer
-
listeners
-
-
Constructor Details
-
AbstractInternalDataContainer
public AbstractInternalDataContainer()
-
-
Method Details
-
getMapForSegment
-
getSegmentForKey
-
get
Description copied from interface:InternalDataContainer
Same asDataContainer.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 interfaceInternalDataContainer<K,
V> - Parameters:
segment
- segment for the keyk
- key under which entry is stored- Returns:
- entry, if it exists and has not expired, or null if not
-
get
Description copied from interface:InternalDataContainer
Retrieves a cached entryWe should only ever be using the non blocking variant
InternalDataContainer.peek(int, Object)
in Infinispan- Specified by:
get
in interfaceDataContainer<K,
V> - Specified by:
get
in interfaceInternalDataContainer<K,
V> - Parameters:
k
- key under which entry is stored- Returns:
- entry, if it exists and has not expired, or null if not
-
peek
Description copied from interface:InternalDataContainer
Same asDataContainer.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 interfaceInternalDataContainer<K,
V> - Parameters:
segment
- segment for the keyk
- key under which entry is stored- Returns:
- entry, if it exists, or null if not
-
peek
Description copied from interface:DataContainer
Retrieves a cache entry in the same way asDataContainer.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 ofDataContainer.get(Object)
} when called while iterating through the data container using methods likeDataContainer.iterator()
to avoid changing the underlying collection's order.- Specified by:
peek
in interfaceDataContainer<K,
V> - Parameters:
k
- key under which entry is stored- Returns:
- entry, if it exists, or null if not
-
touch
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 interfaceInternalDataContainer<K,
V> - Parameters:
segment
- segment for the keyk
- key under which entry is storedcurrentTimeMillis
- 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 asDataContainer.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 interfaceInternalDataContainer<K,
V> - Parameters:
segment
- segment for the keyk
- key under which to store entryv
- value to storemetadata
- metadata of the entrycreatedTimestamp
- creation timestamp, or-1
to use the current timelastUseTimestamp
- last use timestamp, or-1
to use the current time
-
put
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 interfaceDataContainer<K,
V> - Parameters:
k
- key under which to store entryv
- value to storemetadata
- metadata of the entry
-
containsKey
Description copied from interface:InternalDataContainer
Same asDataContainer.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 interfaceInternalDataContainer<K,
V> - Parameters:
segment
- segment for the keyk
- key under which entry is stored- Returns:
- true if entry exists and has not expired; false otherwise
-
containsKey
Description copied from interface:DataContainer
Tests whether an entry exists in the container- Specified by:
containsKey
in interfaceDataContainer<K,
V> - Parameters:
k
- key to test- Returns:
- true if entry exists and has not expired; false otherwise
-
remove
Description copied from interface:InternalDataContainer
Same asDataContainer.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 interfaceInternalDataContainer<K,
V> - Parameters:
segment
- segment for the keyk
- key to remove- Returns:
- entry removed, or null if it didn't exist or had expired
-
remove
Description copied from interface:DataContainer
Removes an entry from the cache- Specified by:
remove
in interfaceDataContainer<K,
V> - Parameters:
k
- key to remove- Returns:
- entry removed, or null if it didn't exist or had expired
-
evict
Description copied from interface:InternalDataContainer
Same asDataContainer.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 interfaceInternalDataContainer<K,
V> - Parameters:
segment
- segment for the keykey
- The key to evict.
-
evict
Description copied from interface:DataContainer
Atomically, it removes the key fromDataContainer
and passivates it to persistence. The passivation must be done by invoking the methodPassivationManager.passivateAsync(InternalCacheEntry)
.- Specified by:
evict
in interfaceDataContainer<K,
V> - Parameters:
key
- The key to evict.
-
compute
Description copied from interface:InternalDataContainer
Same asDataContainer.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 interfaceInternalDataContainer<K,
V> - Parameters:
segment
- segment for the keykey
- The key.action
- The action that will compute the new value.- Returns:
- The
InternalCacheEntry
associated to the key.
-
compute
Description copied from interface:DataContainer
Computes the new value for the key. SeeDataContainer.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 interfaceDataContainer<K,
V> - Parameters:
key
- The key.action
- The action that will compute the new value.- Returns:
- The
InternalCacheEntry
associated to the key.
-
clear
Description copied from interface:InternalDataContainer
Removes entries from the container whose key maps to one of the provided segments- Specified by:
clear
in interfaceInternalDataContainer<K,
V> - Parameters:
segments
- segments of entries to remove
-
computeEntryWritten
This method is invoked every time an entry is written inside a compute block- Parameters:
key
- key passed to compute methodvalue
- the new value
-
computeEntryRemoved
This method is invoked every time an entry is removed inside a compute block- Parameters:
key
- key passed to compute methodvalue
- the old value
-
putEntryInMap
protected void putEntryInMap(PeekableTouchableMap<K, V> map, int segment, K key, InternalCacheEntry<K, V> ice) -
removeEntryInMap
protected InternalCacheEntry<K,V> removeEntryInMap(PeekableTouchableMap<K, V> map, int segment, Object key) -
addRemovalListener
Description copied from interface:InternalDataContainer
Adds a listener that is invoked wheneverInternalDataContainer.removeSegments(IntSet)
is invoked providing a way for the listener to see what actual entries were removed from the container.- Specified by:
addRemovalListener
in interfaceInternalDataContainer<K,
V> - Parameters:
listener
- listener that invoked of removed entries
-
removeRemovalListener
Description copied from interface:InternalDataContainer
Removes a previously registered listener viaInternalDataContainer.addRemovalListener(Consumer)
.- Specified by:
removeRemovalListener
in interfaceInternalDataContainer<K,
V> - Parameters:
listener
- the listener to remove
-
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 interfaceInternalDataContainer<K,
V> - Returns:
- true if any entry can expire, false otherwise.
-
entryAdded
-
entryUpdated
-
entryRemoved
-
segmentRemoved
-
applyListener
protected com.github.benmanes.caffeine.cache.Caffeine<K,InternalCacheEntry<K, applyListenerV>> (com.github.benmanes.caffeine.cache.Caffeine<K, InternalCacheEntry<K, V>> caffeine, AbstractInternalDataContainer<K, V>.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, Executor nonBlockingExecutor, 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 entryV
- value type of the entry- Parameters:
entry
- evicted entryorderer
- used to guarantee ordering between other operations. May be null when an operation is already orderedpassivator
- Passivates the entry to the store if necessaryevictionManager
- Handles additional eviction logic. May be null if eviction is also not requireddataContainer
- container to check if the key has already been removednonBlockingExecutor
- executor to use to run code that may not be able to be ran while holding the write lockselfDelay
- 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
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
-