Interface DataContainer<K,V>
-
- All Superinterfaces:
Iterable<InternalCacheEntry<K,V>>
- All Known Implementing Classes:
org.infinispan.container.impl.AbstractDelegatingDataContainer
,org.infinispan.container.impl.AbstractDelegatingInternalDataContainer
,org.infinispan.container.impl.AbstractInternalDataContainer
,BoundedOffHeapDataContainer
,OffHeapDataContainer
,SegmentedBoundedOffHeapDataContainer
public interface DataContainer<K,V> extends Iterable<InternalCacheEntry<K,V>>
The main internal data structure which stores entries. Care should be taken when using this directly as entries could be stored in a different way than they were given to aCache
. If you wish to convert entries to the stored format, you should use the providedDataConversion
such ascache.getAdvancedCache().getKeyDataConversion().toStorage(key);
when dealing with keys or the following when dealing with valuescache.getAdvancedCache().getValueDataConversion().toStorage(value);
You can also convert from storage to the user provided type by using theDataConversion.fromStorage(Object)
method on any value returned from the DataContainer- Since:
- 4.0
- Author:
- Manik Surtani (manik@jboss.org), Galder ZamarreƱo, Vladimir Blagojevic
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
DataContainer.ComputeAction<K,V>
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description default 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 containerdefault Set<InternalCacheEntry<K,V>>
entrySet()
Deprecated.Please use iterator method if bulk operations are required.void
evict(K key)
Atomically, it removes the key fromDataContainer
and passivates it to persistence.default long
evictionSize()
Returns how large the eviction size is currently.default void
executeTask(KeyFilter<? super K> filter, BiConsumer<? super K,InternalCacheEntry<K,V>> action)
Deprecated.since 9.3 Please use theiterator()
method and apply filtering manuallydefault void
executeTask(KeyValueFilter<? super K,? super V> filter, BiConsumer<? super K,InternalCacheEntry<K,V>> action)
Deprecated.since 9.3 Please use theiterator()
method and apply filtering manuallyInternalCacheEntry<K,V>
get(Object k)
Deprecated.since 10.1 - Please usepeek(Object)
instead.Iterator<InternalCacheEntry<K,V>>
iterator()
Iterator<InternalCacheEntry<K,V>>
iteratorIncludingExpired()
Same asiterator()
except that is also returns expired entries.default Set<K>
keySet()
Deprecated.Please use iterator method if bulk operations are required.InternalCacheEntry<K,V>
peek(Object k)
Retrieves a cache entry in the same way asget(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 cachedefault void
resize(long newSize)
Resizes the capacity of the underlying container.default int
size()
int
sizeIncludingExpired()
default Spliterator<InternalCacheEntry<K,V>>
spliterator()
default Spliterator<InternalCacheEntry<K,V>>
spliteratorIncludingExpired()
Same asspliterator()
except that is also returns expired entries.default Collection<V>
values()
Deprecated.Please use iterator method if bulk operations are required.
-
-
-
Method Detail
-
get
@Deprecated InternalCacheEntry<K,V> get(Object k)
Deprecated.since 10.1 - Please usepeek(Object)
instead.Retrieves a cached entry- Parameters:
k
- key under which entry is stored- Returns:
- entry, if it exists and has not expired, or null if not
-
peek
InternalCacheEntry<K,V> peek(Object k)
Retrieves a cache entry in the same way asget(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 ofget(Object)
} when called while iterating through the data container using methods likeiterator()
to avoid changing the underlying collection's order.- Parameters:
k
- key under which entry is stored- Returns:
- entry, if it exists, or null if not
-
put
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. Thekey
must be activate by invokingActivationManager.onUpdate(Object, boolean)
.- Parameters:
k
- key under which to store entryv
- value to storemetadata
- metadata of the entry
-
containsKey
boolean containsKey(Object k)
Tests whether an entry exists in the container- Parameters:
k
- key to test- Returns:
- true if entry exists and has not expired; false otherwise
-
remove
InternalCacheEntry<K,V> remove(Object k)
Removes an entry from the cache Thekey
must be activate by invokingActivationManager.onRemove(Object, boolean)
.- Parameters:
k
- key to remove- Returns:
- entry removed, or null if it didn't exist or had expired
-
size
default int size()
- Returns:
- count of the number of entries in the container excluding expired entries
-
sizeIncludingExpired
int sizeIncludingExpired()
- Returns:
- count of the number of entries in the container including expired entries
-
clear
void clear()
Removes all entries in the container
-
keySet
@Deprecated default Set<K> keySet()
Deprecated.Please use iterator method if bulk operations are required.Returns a set of keys in the container. When iterating through the container using this method, clients should never callget(Object)
method but insteadpeek(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
iterator()
method and retrieve keys from there.- Returns:
- a set of keys
-
values
@Deprecated default Collection<V> values()
Deprecated.Please use iterator method if bulk operations are required.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 useentrySet()
and pull values from there directly.- Returns:
- a set of values contained in the container
-
entrySet
@Deprecated default Set<InternalCacheEntry<K,V>> entrySet()
Deprecated.Please use iterator method if bulk operations are required.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.
- Returns:
- a set of immutable cache entries
-
evict
void evict(K key)
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)
.- Parameters:
key
- The key to evict.
-
compute
InternalCacheEntry<K,V> compute(K key, DataContainer.ComputeAction<K,V> action)
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.- Parameters:
key
- The key.action
- The action that will compute the new value.- Returns:
- The
InternalCacheEntry
associated to the key.
-
executeTask
@Deprecated default void executeTask(KeyFilter<? super K> filter, BiConsumer<? super K,InternalCacheEntry<K,V>> action) throws InterruptedException
Deprecated.since 9.3 Please use theiterator()
method and apply filtering manuallyExecutes task specified by the given action on the container key/values filtered using the specified key filter.- Parameters:
filter
- the filter for the container keysaction
- the specified action to execute on filtered key/values- Throws:
InterruptedException
-
executeTask
@Deprecated default void executeTask(KeyValueFilter<? super K,? super V> filter, BiConsumer<? super K,InternalCacheEntry<K,V>> action) throws InterruptedException
Deprecated.since 9.3 Please use theiterator()
method and apply filtering manuallyExecutes task specified by the given action on the container key/values filtered using the specified keyvalue filter.- Parameters:
filter
- the filter for the container key/valuesaction
- the specified action to execute on filtered key/values- Throws:
InterruptedException
-
iterator
Iterator<InternalCacheEntry<K,V>> iterator()
This iterator only returns entries that are not expired, however it will not remove them while doing so.
-
spliterator
default Spliterator<InternalCacheEntry<K,V>> spliterator()
This spliterator only returns entries that are not expired, however it will not remove them while doing so.
- Specified by:
spliterator
in interfaceIterable<K>
- Returns:
- spliterator that doesn't produce expired entries
-
iteratorIncludingExpired
Iterator<InternalCacheEntry<K,V>> iteratorIncludingExpired()
Same asiterator()
except that is also returns expired entries.- Returns:
- iterator that returns all entries including expired ones
-
spliteratorIncludingExpired
default Spliterator<InternalCacheEntry<K,V>> spliteratorIncludingExpired()
Same asspliterator()
except that is also returns expired entries.- Returns:
- spliterator that returns all entries including expired ones
-
resize
default void resize(long newSize)
Resizes the capacity of the underlying container. This is only supported if the container is bounded. AnUnsupportedOperationException
is thrown otherwise.- Parameters:
newSize
- the new size
-
capacity
default long capacity()
Returns the capacity of the underlying container. This is only supported if the container is bounded. AnUnsupportedOperationException
is thrown otherwise.- Returns:
-
evictionSize
default long evictionSize()
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 fromcapacity()
- Returns:
- how large the counted eviction is
-
-