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
protected class
AbstractInternalDataContainer.Values
Deprecated.This is to removed whenentrySet()
is removed-
Nested classes/interfaces inherited from interface org.infinispan.container.DataContainer
DataContainer.ComputeAction<K,V>
-
-
Field Summary
Fields Modifier and Type Field Description protected ActivationManager
activator
protected Configuration
configuration
protected InternalEntryFactory
entryFactory
protected EvictionManager
evictionManager
protected InternalExpirationManager<K,V>
expirationManager
protected KeyPartitioner
keyPartitioner
protected List<Consumer<Iterable<InternalCacheEntry<K,V>>>>
listeners
protected ComponentRef<PassivationManager>
passivator
protected org.infinispan.commons.time.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 static <K,V>
com.github.benmanes.caffeine.cache.Caffeine<K,InternalCacheEntry<K,V>>applyListener(com.github.benmanes.caffeine.cache.Caffeine<K,InternalCacheEntry<K,V>> caffeine, org.infinispan.commons.util.EvictionListener<K,InternalCacheEntry<K,V>> listener, com.github.benmanes.caffeine.cache.CacheWriter<K,InternalCacheEntry<K,V>> additionalWriter)
void
clear(org.infinispan.commons.util.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 containerSet<InternalCacheEntry<K,V>>
entrySet()
Returns a mutable set of immutable cache entries exposed as immutable Map.Entry instances.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,InternalCacheEntry<K,V>>
getMapForSegment(int segment)
protected abstract int
getSegmentForKey(Object key)
Set<K>
keySet()
Returns a set of keys in the container.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, 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.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 cachevoid
removeRemovalListener(Object listener)
Removes a previously registered listener viaInternalDataContainer.addRemovalListener(Consumer)
.boolean
touch(int segment, Object k, long currentTimeMillis)
Touches an entry in the data container.Collection<V>
values()
This returns all values in the container including expired entries.-
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, executeTask, executeTask, iterator, iteratorIncludingExpired, resize, size, sizeIncludingExpired, spliterator, spliteratorIncludingExpired
-
Methods inherited from interface org.infinispan.container.impl.InternalDataContainer
addSegments, forEach, iterator, iteratorIncludingExpired, removeSegments, size, sizeIncludingExpired, spliterator, spliteratorIncludingExpired
-
-
-
-
Field Detail
-
timeService
protected org.infinispan.commons.time.TimeService timeService
-
evictionManager
protected EvictionManager evictionManager
-
expirationManager
protected InternalExpirationManager<K,V> expirationManager
-
entryFactory
protected InternalEntryFactory entryFactory
-
activator
protected ActivationManager activator
-
passivator
protected ComponentRef<PassivationManager> passivator
-
configuration
protected Configuration configuration
-
keyPartitioner
protected KeyPartitioner keyPartitioner
-
-
Method Detail
-
getMapForSegment
protected abstract PeekableTouchableMap<K,InternalCacheEntry<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, 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.onUpdate(Object, 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.onRemove(Object, boolean)
.- 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 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.passivate(org.infinispan.container.entries.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 activate by invokingActivationManager.onRemove(Object, boolean)
orActivationManager.onUpdate(Object, boolean)
depending if the value returned by theDataContainer.ComputeAction
is null or not respectively.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(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 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
-
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
-
keySet
public Set<K> keySet()
Description copied from interface:DataContainer
Returns a set of keys in the container. When iterating through the container using this method, clients should never callDataContainer.get(Object)
method but insteadDataContainer.peek(Object)
, in order to avoid changing the order of the underlying collection as a side of effect of iterating through it.This set of keys will include expired entries. If you wish to only retrieve non expired keys please use the
DataContainer.iterator()
method and retrieve keys from there.- Specified by:
keySet
in interfaceDataContainer<K,V>
- Returns:
- a set of keys
-
values
public Collection<V> values()
Description copied from interface:DataContainer
This returns all values in the container including expired entries. If you wish to only receive values that are not expired it is recommended to useDataContainer.entrySet()
and pull values from there directly.- Specified by:
values
in interfaceDataContainer<K,V>
- Returns:
- a set of values contained in the container
-
entrySet
public Set<InternalCacheEntry<K,V>> entrySet()
Description copied from interface:DataContainer
Returns a mutable set of immutable cache entries exposed as immutable Map.Entry instances. Clients of this method such as Cache.entrySet() operation implementors are free to convert the set into an immutable set if needed, which is the most common use case. If a client needs to iterate through a mutable set of mutable cache entries, it should iterate the container itself rather than iterating through the return of entrySet().This set is a read only backed view of the entries underneath. This set will only show non expired entries when invoked. The size method of the set will count expired entries for the purpose of having a O(1) time cost compared to O(N) if it is to not count expired entries.
- Specified by:
entrySet
in interfaceDataContainer<K,V>
- Returns:
- a set of immutable cache entries
-
applyListener
protected static <K,V> com.github.benmanes.caffeine.cache.Caffeine<K,InternalCacheEntry<K,V>> applyListener(com.github.benmanes.caffeine.cache.Caffeine<K,InternalCacheEntry<K,V>> caffeine, org.infinispan.commons.util.EvictionListener<K,InternalCacheEntry<K,V>> listener, com.github.benmanes.caffeine.cache.CacheWriter<K,InternalCacheEntry<K,V>> additionalWriter)
-
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
-
-