Class AbstractDelegatingDataContainer<K,V>
- java.lang.Object
-
- org.infinispan.container.impl.AbstractDelegatingDataContainer<K,V>
-
- All Implemented Interfaces:
Iterable<InternalCacheEntry<K,V>>
,DataContainer<K,V>
- Direct Known Subclasses:
AbstractDelegatingInternalDataContainer
,InternalDataContainerAdapter
public abstract class AbstractDelegatingDataContainer<K,V> extends Object implements DataContainer<K,V>
Delegating data container that delegates all calls to the container returned fromdelegate()
- Since:
- 9.3
- Author:
- wburns
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.infinispan.container.DataContainer
DataContainer.ComputeAction<K,V>
-
-
Constructor Summary
Constructors Constructor Description AbstractDelegatingDataContainer()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description long
capacity()
Returns the capacity of the underlying container.void
clear()
Removes all entries in the containerInternalCacheEntry<K,V>
compute(K key, DataContainer.ComputeAction<K,V> action)
Computes the new value for the 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(K key)
Atomically, it removes the key fromDataContainer
and passivates it to persistence.long
evictionSize()
Returns how large the eviction size is currently.void
executeTask(KeyFilter<? super K> filter, BiConsumer<? super K,InternalCacheEntry<K,V>> action)
Executes task specified by the given action on the container key/values filtered using the specified key filter.void
executeTask(KeyValueFilter<? super K,? super V> filter, BiConsumer<? super K,InternalCacheEntry<K,V>> action)
Executes task specified by the given action on the container key/values filtered using the specified keyvalue filter.void
forEach(Consumer<? super InternalCacheEntry<K,V>> action)
InternalCacheEntry<K,V>
get(Object k)
Retrieves a cached entryIterator<InternalCacheEntry<K,V>>
iterator()
Iterator<InternalCacheEntry<K,V>>
iteratorIncludingExpired()
Same asDataContainer.iterator()
except that is also returns expired entries.Set<K>
keySet()
Returns a set of keys in the container.InternalCacheEntry<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(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(Object k)
Removes an entry from the cachevoid
resize(long newSize)
Resizes the capacity of the underlying container.int
size()
int
sizeIncludingExpired()
Spliterator<InternalCacheEntry<K,V>>
spliterator()
Spliterator<InternalCacheEntry<K,V>>
spliteratorIncludingExpired()
Same asDataContainer.spliterator()
except that is also returns expired entries.Collection<V>
values()
This returns all values in the container including expired entries.
-
-
-
Method Detail
-
get
public InternalCacheEntry<K,V> get(Object k)
Description copied from interface:DataContainer
Retrieves a cached entry- Specified by:
get
in interfaceDataContainer<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(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
-
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(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(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
-
size
public int size()
- Specified by:
size
in interfaceDataContainer<K,V>
- Returns:
- count of the number of entries in the container excluding expired entries
-
sizeIncludingExpired
public int sizeIncludingExpired()
- Specified by:
sizeIncludingExpired
in interfaceDataContainer<K,V>
- Returns:
- count of the number of entries in the container including expired entries
-
clear
public void clear()
Description copied from interface:DataContainer
Removes all entries in the container- Specified by:
clear
in interfaceDataContainer<K,V>
-
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(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.
-
iterator
public Iterator<InternalCacheEntry<K,V>> iterator()
Description copied from interface:DataContainer
This iterator only returns entries that are not expired, however it will not remove them while doing so.
-
iteratorIncludingExpired
public Iterator<InternalCacheEntry<K,V>> iteratorIncludingExpired()
Description copied from interface:DataContainer
Same asDataContainer.iterator()
except that is also returns expired entries.- Specified by:
iteratorIncludingExpired
in interfaceDataContainer<K,V>
- Returns:
- iterator that returns all entries including expired ones
-
spliterator
public Spliterator<InternalCacheEntry<K,V>> spliterator()
Description copied from interface:DataContainer
This spliterator only returns entries that are not expired, however it will not remove them while doing so.
- Specified by:
spliterator
in interfaceDataContainer<K,V>
- Specified by:
spliterator
in interfaceIterable<K>
- Returns:
- spliterator that doesn't produce expired entries
-
spliteratorIncludingExpired
public Spliterator<InternalCacheEntry<K,V>> spliteratorIncludingExpired()
Description copied from interface:DataContainer
Same asDataContainer.spliterator()
except that is also returns expired entries.- Specified by:
spliteratorIncludingExpired
in interfaceDataContainer<K,V>
- Returns:
- spliterator that returns all entries including expired ones
-
capacity
public long capacity()
Description copied from interface:DataContainer
Returns the capacity of the underlying container. This is only supported if the container is bounded. AnUnsupportedOperationException
is thrown otherwise.- Specified by:
capacity
in interfaceDataContainer<K,V>
- Returns:
-
evictionSize
public long evictionSize()
Description copied from interface:DataContainer
Returns how large the eviction size is currently. This is only supported if the container is bounded. AnUnsupportedOperationException
is thrown otherwise. This value will always be lower than the value returned fromDataContainer.capacity()
- Specified by:
evictionSize
in interfaceDataContainer<K,V>
- Returns:
- how large the counted eviction is
-
resize
public void resize(long newSize)
Description copied from interface:DataContainer
Resizes the capacity of the underlying container. This is only supported if the container is bounded. AnUnsupportedOperationException
is thrown otherwise.- Specified by:
resize
in interfaceDataContainer<K,V>
- Parameters:
newSize
- the new size
-
forEach
public void forEach(Consumer<? super InternalCacheEntry<K,V>> action)
-
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
-
executeTask
public void executeTask(KeyFilter<? super K> filter, BiConsumer<? super K,InternalCacheEntry<K,V>> action) throws InterruptedException
Description copied from interface:DataContainer
Executes task specified by the given action on the container key/values filtered using the specified key filter.- Specified by:
executeTask
in interfaceDataContainer<K,V>
- Parameters:
filter
- the filter for the container keysaction
- the specified action to execute on filtered key/values- Throws:
InterruptedException
-
executeTask
public void executeTask(KeyValueFilter<? super K,? super V> filter, BiConsumer<? super K,InternalCacheEntry<K,V>> action) throws InterruptedException
Description copied from interface:DataContainer
Executes task specified by the given action on the container key/values filtered using the specified keyvalue filter.- Specified by:
executeTask
in interfaceDataContainer<K,V>
- Parameters:
filter
- the filter for the container key/valuesaction
- the specified action to execute on filtered key/values- Throws:
InterruptedException
-
-