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 togetSegmentForKey(Object)
for methods that don't provide a segment and implementors can provide what map we should look into for a given segment viagetMapForSegment(int)
.- Since:
- 9.3
- Author:
- wburns
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
AbstractInternalDataContainer.EntryIterator
-
Nested classes/interfaces inherited from interface org.infinispan.container.DataContainer
DataContainer.ComputeAction<K,V>
-
-
Field Summary
Fields Modifier and Type Field Description protected Configuration
configuration
protected InternalEntryFactory
entryFactory
protected EvictionManager<K,V>
evictionManager
protected InternalExpirationManager<K,V>
expirationManager
protected KeyPartitioner
keyPartitioner
protected List<Consumer<Iterable<InternalCacheEntry<K,V>>>>
listeners
protected DataOperationOrderer
orderer
protected ComponentRef<PassivationManager>
passivator
protected TimeService
timeService
-
Constructor Summary
Constructors Constructor Description AbstractInternalDataContainer()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
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, org.infinispan.container.impl.AbstractInternalDataContainer.DefaultEvictionListener listener)
void
clear(IntSet segments)
Removes entries from the container whose key maps to one of the provided segmentsInternalCacheEntry<K,V>
compute(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.InternalCacheEntry<K,V>
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
containsKey(Object k)
Tests whether an entry exists in the containerprotected void
entryAdded(InternalCacheEntry<K,V> ice)
protected void
entryRemoved(InternalCacheEntry<K,V> ice)
protected void
entryUpdated(InternalCacheEntry<K,V> curr, InternalCacheEntry<K,V> prev)
CompletionStage<Void>
evict(int segment, K key)
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
evict(K key)
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.InternalCacheEntry<K,V>
get(int segment, Object k)
Same asDataContainer.get(Object)
except that the segment of the key can provided to lookup entries without calculating the segment for the given keyInternalCacheEntry<K,V>
get(Object k)
Retrieves 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, CompletionStage<Void> selfDelay)
Performs the eviction logic, except it doesn't actually remove the entry from the data container.boolean
hasExpirable()
Verify if the container has entries that can expire.InternalCacheEntry<K,V>
peek(int segment, Object k)
Same asDataContainer.peek(Object)
except that the segment of the key can provided to lookup entries without calculating the segment for the given keyInternalCacheEntry<K,V>
peek(Object k)
Retrieves 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
put(K k, V v, Metadata metadata)
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)
InternalCacheEntry<K,V>
remove(int segment, Object k)
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.InternalCacheEntry<K,V>
remove(Object k)
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 void
segmentRemoved(Map<K,InternalCacheEntry<K,V>> segment)
boolean
touch(int segment, Object k, long currentTimeMillis)
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 Detail
-
timeService
protected TimeService timeService
-
evictionManager
protected EvictionManager<K,V> evictionManager
-
expirationManager
protected InternalExpirationManager<K,V> expirationManager
-
entryFactory
protected InternalEntryFactory entryFactory
-
passivator
protected ComponentRef<PassivationManager> passivator
-
configuration
protected Configuration configuration
-
keyPartitioner
protected KeyPartitioner keyPartitioner
-
orderer
protected DataOperationOrderer orderer
-
-
Method Detail
-
getMapForSegment
protected abstract PeekableTouchableMap<K,V> getMapForSegment(int segment)
-
getSegmentForKey
protected abstract int getSegmentForKey(Object key)
-
get
public InternalCacheEntry<K,V> get(int segment, Object k)
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
public InternalCacheEntry<K,V> get(Object k)
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
public InternalCacheEntry<K,V> peek(int segment, Object k)
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
public InternalCacheEntry<K,V> peek(Object k)
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
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 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
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. Thekey
must be activate by invokingActivationManager.activateAsync(Object, int)
boolean)}.- Specified by:
put
in interfaceDataContainer<K,V>
- Parameters:
k
- key under which to store entryv
- value to storemetadata
- metadata of the entry
-
containsKey
public boolean containsKey(int segment, Object k)
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
public boolean containsKey(Object k)
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
public InternalCacheEntry<K,V> remove(int segment, Object k)
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
public InternalCacheEntry<K,V> remove(Object k)
Description copied from interface:DataContainer
Removes an entry from the cache Thekey
must be activate by invokingActivationManager.activateAsync(Object, int)
- 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
public CompletionStage<Void> evict(int segment, K key)
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
public void evict(K key)
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
public InternalCacheEntry<K,V> compute(int segment, K key, DataContainer.ComputeAction<K,V> action)
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
public InternalCacheEntry<K,V> compute(K key, DataContainer.ComputeAction<K,V> action)
Description copied from interface:DataContainer
Computes the new value for the key. SeeDataContainer.ComputeAction.compute(Object, org.infinispan.container.entries.InternalCacheEntry, InternalEntryFactory)
. Thekey
must be activated by invokingActivationManager.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 interfaceDataContainer<K,V>
- Parameters:
key
- The key.action
- The action that will compute the new value.- Returns:
- The
InternalCacheEntry
associated to the key.
-
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 interfaceInternalDataContainer<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 methodvalue
- 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 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
public void addRemovalListener(Consumer<Iterable<InternalCacheEntry<K,V>>> listener)
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
public void removeRemovalListener(Object listener)
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
protected final void entryAdded(InternalCacheEntry<K,V> ice)
-
entryUpdated
protected final void entryUpdated(InternalCacheEntry<K,V> curr, InternalCacheEntry<K,V> prev)
-
entryRemoved
protected final void entryRemoved(InternalCacheEntry<K,V> ice)
-
segmentRemoved
protected final void segmentRemoved(Map<K,InternalCacheEntry<K,V>> segment)
-
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 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 removedselfDelay
- 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
-
-