Package org.infinispan.container.offheap
Class BoundedOffHeapDataContainer
- java.lang.Object
-
- org.infinispan.container.impl.AbstractDelegatingInternalDataContainer<WrappedBytes,WrappedBytes>
-
- org.infinispan.container.offheap.SegmentedBoundedOffHeapDataContainer
-
- org.infinispan.container.offheap.BoundedOffHeapDataContainer
-
- All Implemented Interfaces:
java.lang.Iterable<InternalCacheEntry<WrappedBytes,WrappedBytes>>
,DataContainer<WrappedBytes,WrappedBytes>
,org.infinispan.container.impl.InternalDataContainer<WrappedBytes,WrappedBytes>
public class BoundedOffHeapDataContainer extends SegmentedBoundedOffHeapDataContainer
- Since:
- 9.4
- Author:
- wburns
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.infinispan.container.DataContainer
DataContainer.ComputeAction<K,V>
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.List<java.util.function.Consumer<java.lang.Iterable<InternalCacheEntry<WrappedBytes,WrappedBytes>>>>
listeners
-
Fields inherited from class org.infinispan.container.offheap.SegmentedBoundedOffHeapDataContainer
allocator, currentSize, dataContainer, evictionManager, firstAddress, lastAddress, lruLock, maxSize, numSegments, offHeapEntryFactory, orderer, passivator, useCount
-
-
Constructor Summary
Constructors Constructor Description BoundedOffHeapDataContainer(long maxSize, EvictionType type)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addRemovalListener(java.util.function.Consumer<java.lang.Iterable<InternalCacheEntry<WrappedBytes,WrappedBytes>>> 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.void
addSegments(IntSet segments)
Sets what segments this data container should be using.InternalCacheEntry<WrappedBytes,WrappedBytes>
compute(int segment, WrappedBytes key, DataContainer.ComputeAction<WrappedBytes,WrappedBytes> 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<WrappedBytes,WrappedBytes>
compute(WrappedBytes key, DataContainer.ComputeAction<WrappedBytes,WrappedBytes> action)
Computes the new value for the key.boolean
containsKey(int segment, java.lang.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(java.lang.Object k)
Tests whether an entry exists in the containerjava.util.concurrent.CompletionStage<java.lang.Void>
evict(int segment, WrappedBytes 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(WrappedBytes key)
Atomically, it removes the key fromDataContainer
and passivates it to persistence.InternalCacheEntry<WrappedBytes,WrappedBytes>
get(int segment, java.lang.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<WrappedBytes,WrappedBytes>
get(java.lang.Object k)
Retrieves a cached entryprotected OffHeapConcurrentMap
getMapThatContainsKey(byte[] key)
java.util.Iterator<InternalCacheEntry<WrappedBytes,WrappedBytes>>
iterator(IntSet segments)
Same asDataContainer.iterator()
except that only entries that map to the provided segments are returned via the iterator.java.util.Iterator<InternalCacheEntry<WrappedBytes,WrappedBytes>>
iteratorIncludingExpired(IntSet segments)
Same asDataContainer.iteratorIncludingExpired()
except that only entries that map to the provided segments are returned via the iterator.InternalCacheEntry<WrappedBytes,WrappedBytes>
peek(int segment, java.lang.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<WrappedBytes,WrappedBytes>
peek(java.lang.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, WrappedBytes key, WrappedBytes value, 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(WrappedBytes key, WrappedBytes value, Metadata metadata)
Puts an entry in the cache along with metadata adding information such lifespan of entry, max idle time, version information...etc.InternalCacheEntry<WrappedBytes,WrappedBytes>
remove(int segment, java.lang.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<WrappedBytes,WrappedBytes>
remove(java.lang.Object k)
Removes an entry from the cachevoid
removeRemovalListener(java.lang.Object listener)
Removes a previously registered listener viaInternalDataContainer.addRemovalListener(Consumer)
.void
removeSegments(IntSet segments)
Removes and un-associates the given segments.int
size(IntSet segments)
Returns how many entries are present in the data container that map to the given segments without counting entries that are currently expired.int
sizeIncludingExpired(IntSet segments)
Returns how many entries are present in the data container that map to the given segments including any entries that may be expiredjava.util.Spliterator<InternalCacheEntry<WrappedBytes,WrappedBytes>>
spliterator(IntSet segments)
Same asDataContainer.spliterator()
except that only entries that map to the provided segments are returned via this spliterator.java.util.Spliterator<InternalCacheEntry<WrappedBytes,WrappedBytes>>
spliteratorIncludingExpired(IntSet segments)
Same asDataContainer.spliteratorIncludingExpired()
except that only entries that map to the provided segments are returned via this spliterator.-
Methods inherited from class org.infinispan.container.offheap.SegmentedBoundedOffHeapDataContainer
capacity, delegate, evictionSize, getSize, start, stop
-
Methods inherited from class org.infinispan.container.impl.AbstractDelegatingInternalDataContainer
clear, clear, forEach, forEach, iterator, iteratorIncludingExpired, resize, size, sizeIncludingExpired, spliterator, spliteratorIncludingExpired
-
-
-
-
Field Detail
-
listeners
protected final java.util.List<java.util.function.Consumer<java.lang.Iterable<InternalCacheEntry<WrappedBytes,WrappedBytes>>>> listeners
-
-
Constructor Detail
-
BoundedOffHeapDataContainer
public BoundedOffHeapDataContainer(long maxSize, EvictionType type)
-
-
Method Detail
-
getMapThatContainsKey
protected OffHeapConcurrentMap getMapThatContainsKey(byte[] key)
- Overrides:
getMapThatContainsKey
in classSegmentedBoundedOffHeapDataContainer
-
containsKey
public boolean containsKey(java.lang.Object k)
Description copied from interface:DataContainer
Tests whether an entry exists in the container- Specified by:
containsKey
in interfaceDataContainer<WrappedBytes,WrappedBytes>
- Overrides:
containsKey
in classorg.infinispan.container.impl.AbstractDelegatingInternalDataContainer<WrappedBytes,WrappedBytes>
- Parameters:
k
- key to test- Returns:
- true if entry exists and has not expired; false otherwise
-
peek
public InternalCacheEntry<WrappedBytes,WrappedBytes> peek(java.lang.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<WrappedBytes,WrappedBytes>
- Overrides:
peek
in classorg.infinispan.container.impl.AbstractDelegatingInternalDataContainer<WrappedBytes,WrappedBytes>
- Parameters:
k
- key under which entry is stored- Returns:
- entry, if it exists, or null if not
-
get
public InternalCacheEntry<WrappedBytes,WrappedBytes> get(java.lang.Object k)
Description copied from interface:DataContainer
Retrieves a cached entry- Specified by:
get
in interfaceDataContainer<WrappedBytes,WrappedBytes>
- Overrides:
get
in classorg.infinispan.container.impl.AbstractDelegatingInternalDataContainer<WrappedBytes,WrappedBytes>
- Parameters:
k
- key under which entry is stored- Returns:
- entry, if it exists and has not expired, or null if not
-
compute
public InternalCacheEntry<WrappedBytes,WrappedBytes> compute(WrappedBytes key, DataContainer.ComputeAction<WrappedBytes,WrappedBytes> 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<WrappedBytes,WrappedBytes>
- Overrides:
compute
in classSegmentedBoundedOffHeapDataContainer
- Parameters:
key
- The key.action
- The action that will compute the new value.- Returns:
- The
InternalCacheEntry
associated to the key.
-
remove
public InternalCacheEntry<WrappedBytes,WrappedBytes> remove(java.lang.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<WrappedBytes,WrappedBytes>
- Overrides:
remove
in classorg.infinispan.container.impl.AbstractDelegatingInternalDataContainer<WrappedBytes,WrappedBytes>
- Parameters:
k
- key to remove- Returns:
- entry removed, or null if it didn't exist or had expired
-
evict
public void evict(WrappedBytes 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<WrappedBytes,WrappedBytes>
- Overrides:
evict
in classorg.infinispan.container.impl.AbstractDelegatingInternalDataContainer<WrappedBytes,WrappedBytes>
- Parameters:
key
- The key to evict.
-
put
public void put(WrappedBytes key, WrappedBytes value, 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<WrappedBytes,WrappedBytes>
- Overrides:
put
in classSegmentedBoundedOffHeapDataContainer
- Parameters:
key
- key under which to store entryvalue
- value to storemetadata
- metadata of the entry
-
containsKey
public boolean containsKey(int segment, java.lang.Object k)
Description copied from interface:org.infinispan.container.impl.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 interfaceorg.infinispan.container.impl.InternalDataContainer<WrappedBytes,WrappedBytes>
- Overrides:
containsKey
in classorg.infinispan.container.impl.AbstractDelegatingInternalDataContainer<WrappedBytes,WrappedBytes>
- Parameters:
segment
- segment for the keyk
- key under which entry is stored- Returns:
- true if entry exists and has not expired; false otherwise
-
peek
public InternalCacheEntry<WrappedBytes,WrappedBytes> peek(int segment, java.lang.Object k)
Description copied from interface:org.infinispan.container.impl.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 interfaceorg.infinispan.container.impl.InternalDataContainer<WrappedBytes,WrappedBytes>
- Overrides:
peek
in classorg.infinispan.container.impl.AbstractDelegatingInternalDataContainer<WrappedBytes,WrappedBytes>
- Parameters:
segment
- segment for the keyk
- key under which entry is stored- Returns:
- entry, if it exists, or null if not
-
get
public InternalCacheEntry<WrappedBytes,WrappedBytes> get(int segment, java.lang.Object k)
Description copied from interface:org.infinispan.container.impl.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 interfaceorg.infinispan.container.impl.InternalDataContainer<WrappedBytes,WrappedBytes>
- Overrides:
get
in classorg.infinispan.container.impl.AbstractDelegatingInternalDataContainer<WrappedBytes,WrappedBytes>
- 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
-
compute
public InternalCacheEntry<WrappedBytes,WrappedBytes> compute(int segment, WrappedBytes key, DataContainer.ComputeAction<WrappedBytes,WrappedBytes> action)
Description copied from interface:org.infinispan.container.impl.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 interfaceorg.infinispan.container.impl.InternalDataContainer<WrappedBytes,WrappedBytes>
- Overrides:
compute
in classSegmentedBoundedOffHeapDataContainer
- Parameters:
segment
- segment for the keykey
- The key.action
- The action that will compute the new value.- Returns:
- The
InternalCacheEntry
associated to the key.
-
remove
public InternalCacheEntry<WrappedBytes,WrappedBytes> remove(int segment, java.lang.Object k)
Description copied from interface:org.infinispan.container.impl.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 interfaceorg.infinispan.container.impl.InternalDataContainer<WrappedBytes,WrappedBytes>
- Overrides:
remove
in classorg.infinispan.container.impl.AbstractDelegatingInternalDataContainer<WrappedBytes,WrappedBytes>
- Parameters:
segment
- segment for the keyk
- key to remove- Returns:
- entry removed, or null if it didn't exist or had expired
-
evict
public java.util.concurrent.CompletionStage<java.lang.Void> evict(int segment, WrappedBytes key)
Description copied from interface:org.infinispan.container.impl.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 interfaceorg.infinispan.container.impl.InternalDataContainer<WrappedBytes,WrappedBytes>
- Overrides:
evict
in classorg.infinispan.container.impl.AbstractDelegatingInternalDataContainer<WrappedBytes,WrappedBytes>
- Parameters:
segment
- segment for the keykey
- The key to evict.
-
put
public void put(int segment, WrappedBytes key, WrappedBytes value, Metadata metadata, long createdTimestamp, long lastUseTimestamp)
Description copied from interface:org.infinispan.container.impl.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 interfaceorg.infinispan.container.impl.InternalDataContainer<WrappedBytes,WrappedBytes>
- Overrides:
put
in classSegmentedBoundedOffHeapDataContainer
- Parameters:
segment
- segment for the keykey
- key under which to store entryvalue
- 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
-
spliterator
public java.util.Spliterator<InternalCacheEntry<WrappedBytes,WrappedBytes>> spliterator(IntSet segments)
Description copied from interface:org.infinispan.container.impl.InternalDataContainer
Same asDataContainer.spliterator()
except that only entries that map to the provided segments are returned via this spliterator. The spliterator will not return expired entries.- Specified by:
spliterator
in interfaceorg.infinispan.container.impl.InternalDataContainer<WrappedBytes,WrappedBytes>
- Overrides:
spliterator
in classorg.infinispan.container.impl.AbstractDelegatingInternalDataContainer<WrappedBytes,WrappedBytes>
- Parameters:
segments
- segments of entries to return- Returns:
- spliterator containing entries mapping to those segments that aren't expired
-
spliteratorIncludingExpired
public java.util.Spliterator<InternalCacheEntry<WrappedBytes,WrappedBytes>> spliteratorIncludingExpired(IntSet segments)
Description copied from interface:org.infinispan.container.impl.InternalDataContainer
Same asDataContainer.spliteratorIncludingExpired()
except that only entries that map to the provided segments are returned via this spliterator. The spliterator will return expired entries as well.- Specified by:
spliteratorIncludingExpired
in interfaceorg.infinispan.container.impl.InternalDataContainer<WrappedBytes,WrappedBytes>
- Overrides:
spliteratorIncludingExpired
in classorg.infinispan.container.impl.AbstractDelegatingInternalDataContainer<WrappedBytes,WrappedBytes>
- Parameters:
segments
- segments of entries to use- Returns:
- spliterator containing entries mapping to those segments that could be expired
-
iterator
public java.util.Iterator<InternalCacheEntry<WrappedBytes,WrappedBytes>> iterator(IntSet segments)
Description copied from interface:org.infinispan.container.impl.InternalDataContainer
Same asDataContainer.iterator()
except that only entries that map to the provided segments are returned via the iterator. The iterator will not return expired entries.- Specified by:
iterator
in interfaceorg.infinispan.container.impl.InternalDataContainer<WrappedBytes,WrappedBytes>
- Overrides:
iterator
in classorg.infinispan.container.impl.AbstractDelegatingInternalDataContainer<WrappedBytes,WrappedBytes>
- Parameters:
segments
- segments of entries to use- Returns:
- iterator that returns all entries mapped to the given segments
-
iteratorIncludingExpired
public java.util.Iterator<InternalCacheEntry<WrappedBytes,WrappedBytes>> iteratorIncludingExpired(IntSet segments)
Description copied from interface:org.infinispan.container.impl.InternalDataContainer
Same asDataContainer.iteratorIncludingExpired()
except that only entries that map to the provided segments are returned via the iterator. The iterator can return expired entries.- Specified by:
iteratorIncludingExpired
in interfaceorg.infinispan.container.impl.InternalDataContainer<WrappedBytes,WrappedBytes>
- Overrides:
iteratorIncludingExpired
in classorg.infinispan.container.impl.AbstractDelegatingInternalDataContainer<WrappedBytes,WrappedBytes>
- Parameters:
segments
- segments of entries to use- Returns:
- iterator that returns all entries mapped to the given segments that could be expired
-
sizeIncludingExpired
public int sizeIncludingExpired(IntSet segments)
Description copied from interface:org.infinispan.container.impl.InternalDataContainer
Returns how many entries are present in the data container that map to the given segments including any entries that may be expired- Specified by:
sizeIncludingExpired
in interfaceorg.infinispan.container.impl.InternalDataContainer<WrappedBytes,WrappedBytes>
- Overrides:
sizeIncludingExpired
in classorg.infinispan.container.impl.AbstractDelegatingInternalDataContainer<WrappedBytes,WrappedBytes>
- Parameters:
segments
- segments of entries to count- Returns:
- count of the number of entries in the container including expired entries
-
size
public int size(IntSet segments)
Description copied from interface:org.infinispan.container.impl.InternalDataContainer
Returns how many entries are present in the data container that map to the given segments without counting entries that are currently expired.- Specified by:
size
in interfaceorg.infinispan.container.impl.InternalDataContainer<WrappedBytes,WrappedBytes>
- Overrides:
size
in classorg.infinispan.container.impl.AbstractDelegatingInternalDataContainer<WrappedBytes,WrappedBytes>
- Parameters:
segments
- segments of entries to count- Returns:
- count of the number of entries in the container excluding expired entries
-
addRemovalListener
public void addRemovalListener(java.util.function.Consumer<java.lang.Iterable<InternalCacheEntry<WrappedBytes,WrappedBytes>>> listener)
Description copied from interface:org.infinispan.container.impl.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 interfaceorg.infinispan.container.impl.InternalDataContainer<WrappedBytes,WrappedBytes>
- Overrides:
addRemovalListener
in classorg.infinispan.container.impl.AbstractDelegatingInternalDataContainer<WrappedBytes,WrappedBytes>
- Parameters:
listener
- listener that invoked of removed entries
-
removeRemovalListener
public void removeRemovalListener(java.lang.Object listener)
Description copied from interface:org.infinispan.container.impl.InternalDataContainer
Removes a previously registered listener viaInternalDataContainer.addRemovalListener(Consumer)
.- Specified by:
removeRemovalListener
in interfaceorg.infinispan.container.impl.InternalDataContainer<WrappedBytes,WrappedBytes>
- Overrides:
removeRemovalListener
in classorg.infinispan.container.impl.AbstractDelegatingInternalDataContainer<WrappedBytes,WrappedBytes>
- Parameters:
listener
- the listener to remove
-
addSegments
public void addSegments(IntSet segments)
Description copied from interface:org.infinispan.container.impl.InternalDataContainer
Sets what segments this data container should be using. Already associated segments are unaffected by this and takes a union of existing and new segments.- Specified by:
addSegments
in interfaceorg.infinispan.container.impl.InternalDataContainer<WrappedBytes,WrappedBytes>
- Overrides:
addSegments
in classorg.infinispan.container.impl.AbstractDelegatingInternalDataContainer<WrappedBytes,WrappedBytes>
- Parameters:
segments
- segments to associate with this container
-
removeSegments
public void removeSegments(IntSet segments)
Description copied from interface:org.infinispan.container.impl.InternalDataContainer
Removes and un-associates the given segments. This will notify any listeners registered viaInternalDataContainer.addRemovalListener(Consumer)
of entries that were removed due to no longer being associated with this container. There is no guarantee if the consumer is invoked once or multiple times for a given group of segments and could be in any order.When this method is invoked an implementation is free to remove any entries that don't map to segments currently associated with this container. Note that entries that were removed due to their segments never being associated with this container do not notify listeners registered via
InternalDataContainer.addRemovalListener(Consumer)
.- Specified by:
removeSegments
in interfaceorg.infinispan.container.impl.InternalDataContainer<WrappedBytes,WrappedBytes>
- Overrides:
removeSegments
in classorg.infinispan.container.impl.AbstractDelegatingInternalDataContainer<WrappedBytes,WrappedBytes>
- Parameters:
segments
- segments that should no longer be associated with this container
-
-