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 ClassesNested classes/interfaces inherited from interface org.infinispan.container.DataContainer
DataContainer.ComputeAction<K,V> -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Configurationprotected InternalEntryFactoryprotected EvictionManager<K,V> protected InternalExpirationManager<K,V> protected KeyPartitionerprotected DataOperationOrdererprotected ComponentRef<PassivationManager>protected TimeService -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddRemovalListener(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) voidRemoves 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 voidcomputeEntryRemoved(K key, InternalCacheEntry<K, V> value) This method is invoked every time an entry is removed inside a compute blockprotected voidcomputeEntryWritten(K key, InternalCacheEntry<K, V> value) This method is invoked every time an entry is written inside a compute blockbooleancontainsKey(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.booleanTests whether an entry exists in the containerprotected final voidentryAdded(InternalCacheEntry<K, V> ice) protected final voidentryRemoved(InternalCacheEntry<K, V> ice) protected final voidentryUpdated(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.voidAtomically, it removes the key fromDataContainerand 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 intgetSegmentForKey(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.booleanVerify 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.voidput(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.voidPuts an entry in the cache along with metadata adding information such lifespan of entry, max idle time, version information...etc.protected voidputEntryInMap(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) voidremoveRemovalListener(Object listener) Removes a previously registered listener viaInternalDataContainer.addRemovalListener(Consumer).protected final voidsegmentRemoved(Map<K, InternalCacheEntry<K, V>> segment) booleanTouches an entry in the data container.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.infinispan.container.DataContainer
capacity, clear, evictionSize, iterator, iteratorIncludingExpired, resize, size, sizeIncludingExpired, spliterator, spliteratorIncludingExpiredMethods 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:InternalDataContainerSame 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:
getin 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:InternalDataContainerRetrieves a cached entryWe should only ever be using the non blocking variant
InternalDataContainer.peek(int, Object)in Infinispan- Specified by:
getin interfaceDataContainer<K,V> - Specified by:
getin 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:InternalDataContainerSame 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:
peekin 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:DataContainerRetrieves 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:
peekin 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:InternalDataContainerTouches 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:
touchin 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:InternalDataContainerSame 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:
putin 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-1to use the current timelastUseTimestamp- last use timestamp, or-1to use the current time
-
put
Description copied from interface:DataContainerPuts an entry in the cache along with metadata adding information such lifespan of entry, max idle time, version information...etc.- Specified by:
putin interfaceDataContainer<K,V> - Parameters:
k- key under which to store entryv- value to storemetadata- metadata of the entry
-
containsKey
Description copied from interface:InternalDataContainerSame 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:
containsKeyin 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:DataContainerTests whether an entry exists in the container- Specified by:
containsKeyin interfaceDataContainer<K,V> - Parameters:
k- key to test- Returns:
- true if entry exists and has not expired; false otherwise
-
remove
Description copied from interface:InternalDataContainerSame 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:
removein 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:DataContainerRemoves an entry from the cache- Specified by:
removein 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:InternalDataContainerSame 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:
evictin interfaceInternalDataContainer<K,V> - Parameters:
segment- segment for the keykey- The key to evict.
-
evict
Description copied from interface:DataContainerAtomically, it removes the key fromDataContainerand passivates it to persistence. The passivation must be done by invoking the methodPassivationManager.passivateAsync(InternalCacheEntry).- Specified by:
evictin interfaceDataContainer<K,V> - Parameters:
key- The key to evict.
-
compute
Description copied from interface:InternalDataContainerSame 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:
computein interfaceInternalDataContainer<K,V> - Parameters:
segment- segment for the keykey- The key.action- The action that will compute the new value.- Returns:
- The
InternalCacheEntryassociated to the key.
-
compute
Description copied from interface:DataContainerComputes the new value for the key. SeeDataContainer.ComputeAction.compute(Object, org.infinispan.container.entries.InternalCacheEntry, InternalEntryFactory).Note the entry provided to
DataContainer.ComputeActionmay be expired as these entries are not filtered as many other methods do.- Specified by:
computein interfaceDataContainer<K,V> - Parameters:
key- The key.action- The action that will compute the new value.- Returns:
- The
InternalCacheEntryassociated to the key.
-
clear
Description copied from interface:InternalDataContainerRemoves entries from the container whose key maps to one of the provided segments- Specified by:
clearin 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:InternalDataContainerAdds 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:
addRemovalListenerin interfaceInternalDataContainer<K,V> - Parameters:
listener- listener that invoked of removed entries
-
removeRemovalListener
Description copied from interface:InternalDataContainerRemoves a previously registered listener viaInternalDataContainer.addRemovalListener(Consumer).- Specified by:
removeRemovalListenerin interfaceInternalDataContainer<K,V> - Parameters:
listener- the listener to remove
-
hasExpirable
public boolean hasExpirable()Description copied from interface:InternalDataContainerVerify 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:
hasExpirablein 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
-