Class AbstractDelegatingCache<K,V>
- java.lang.Object
-
- org.infinispan.cache.impl.AbstractDelegatingCache<K,V>
-
- All Implemented Interfaces:
ConcurrentMap<K,V>
,Map<K,V>
,Cache<K,V>
,org.infinispan.commons.api.AsyncCache<K,V>
,org.infinispan.commons.api.BasicCache<K,V>
,org.infinispan.commons.api.BatchingCache
,org.infinispan.commons.api.Lifecycle
,FilteringListenable<K,V>
,Listenable
- Direct Known Subclasses:
AbstractDelegatingAdvancedCache
@MBean(objectName="Cache", description="Component that represents an individual cache instance.") public abstract class AbstractDelegatingCache<K,V> extends Object implements Cache<K,V>
This is a convenient base class for implementing a cache delegate. The only constructor takes aCache
argument, to which each method call is delegated. One can extend this class and override the method sub-set it is interested in. There is also an similar implementation forAdvancedCache
:AbstractDelegatingAdvancedCache
.- Author:
- [email protected]
- See Also:
AbstractDelegatingAdvancedCache
-
-
Constructor Summary
Constructors Constructor Description AbstractDelegatingCache(Cache<K,V> cache)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description <C> void
addFilteredListener(Object listener, CacheEventFilter<? super K,? super V> filter, CacheEventConverter<? super K,? super V,C> converter, Set<Class<? extends Annotation>> filterAnnotations)
Registers a listener limiting the cache-entry specific events only to annotations that are passed in as parameter.<C> CompletionStage<Void>
addFilteredListenerAsync(Object listener, CacheEventFilter<? super K,? super V> filter, CacheEventConverter<? super K,? super V,C> converter, Set<Class<? extends Annotation>> filterAnnotations)
Asynchronous version ofFilteringListenable.addFilteredListener(Object, CacheEventFilter, CacheEventConverter, Set)
void
addListener(Object listener)
Adds a listener to the component.<C> void
addListener(Object listener, CacheEventFilter<? super K,? super V> filter, CacheEventConverter<? super K,? super V,C> converter)
Registers a listener that will be notified on events that pass the filter condition.CompletionStage<Void>
addListenerAsync(Object listener)
Asynchronous version ofListenable.addListener(Object)
<C> CompletionStage<Void>
addListenerAsync(Object listener, CacheEventFilter<? super K,? super V> filter, CacheEventConverter<? super K,? super V,C> converter)
Asynchronous version ofFilteringListenable.addListener(Object, CacheEventFilter, CacheEventConverter)
<C> void
addStorageFormatFilteredListener(Object listener, CacheEventFilter<? super K,? super V> filter, CacheEventConverter<? super K,? super V,C> converter, Set<Class<? extends Annotation>> filterAnnotations)
Same asFilteringListenable.addFilteredListener(Object, CacheEventFilter, CacheEventConverter, Set)
, but assumes the filter and/or the converter will be done in the same data format as it's stored in the cache.<C> CompletionStage<Void>
addStorageFormatFilteredListenerAsync(Object listener, CacheEventFilter<? super K,? super V> filter, CacheEventConverter<? super K,? super V,C> converter, Set<Class<? extends Annotation>> filterAnnotations)
void
clear()
Removes all mappings from the cache.CompletableFuture<Void>
clearAsync()
V
compute(K key, BiFunction<? super K,? super V,? extends V> remappingFunction)
V
compute(K key, BiFunction<? super K,? super V,? extends V> remappingFunction, long lifespan, TimeUnit lifespanUnit)
V
compute(K key, BiFunction<? super K,? super V,? extends V> remappingFunction, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit)
CompletableFuture<V>
computeAsync(K key, BiFunction<? super K,? super V,? extends V> remappingFunction)
CompletableFuture<V>
computeAsync(K key, BiFunction<? super K,? super V,? extends V> remappingFunction, long lifespan, TimeUnit lifespanUnit)
CompletableFuture<V>
computeAsync(K key, BiFunction<? super K,? super V,? extends V> remappingFunction, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit)
V
computeIfAbsent(K key, Function<? super K,? extends V> mappingFunction)
V
computeIfAbsent(K key, Function<? super K,? extends V> mappingFunction, long lifespan, TimeUnit lifespanUnit)
V
computeIfAbsent(K key, Function<? super K,? extends V> mappingFunction, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit)
CompletableFuture<V>
computeIfAbsentAsync(K key, Function<? super K,? extends V> mappingFunction)
CompletableFuture<V>
computeIfAbsentAsync(K key, Function<? super K,? extends V> mappingFunction, long lifespan, TimeUnit lifespanUnit)
CompletableFuture<V>
computeIfAbsentAsync(K key, Function<? super K,? extends V> mappingFunction, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit)
V
computeIfPresent(K key, BiFunction<? super K,? super V,? extends V> remappingFunction)
V
computeIfPresent(K key, BiFunction<? super K,? super V,? extends V> remappingFunction, long lifespan, TimeUnit lifespanUnit)
V
computeIfPresent(K key, BiFunction<? super K,? super V,? extends V> remappingFunction, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit)
CompletableFuture<V>
computeIfPresentAsync(K key, BiFunction<? super K,? super V,? extends V> remappingFunction)
CompletableFuture<V>
computeIfPresentAsync(K key, BiFunction<? super K,? super V,? extends V> remappingFunction, long lifespan, TimeUnit lifespanUnit)
CompletableFuture<V>
computeIfPresentAsync(K key, BiFunction<? super K,? super V,? extends V> remappingFunction, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit)
boolean
containsKey(Object key)
boolean
containsValue(Object value)
void
endBatch(boolean successful)
CacheSet<Map.Entry<K,V>>
entrySet()
Returns a set view of the mappings contained in this cache and cache loader across the entire cluster.void
evict(K key)
Evicts an entry from the memory of the cache.void
forEach(BiConsumer<? super K,? super V> action)
V
get(Object key)
AdvancedCache<K,V>
getAdvancedCache()
CompletableFuture<Map<K,V>>
getAllAsync(Set<?> keys)
CompletableFuture<V>
getAsync(K key)
Configuration
getCacheConfiguration()
EmbeddedCacheManager
getCacheManager()
Retrieves the cache manager responsible for creating this cache instance.String
getCacheName()
String
getCacheStatus()
Returns String representation of ComponentStatus enumeration in order to avoid class not found exceptions in JMX tools that don't have access to infinispan classes.Properties
getConfigurationAsProperties()
Cache<K,V>
getDelegate()
Set<Object>
getListeners()
Deprecated.String
getName()
V
getOrDefault(Object key, V defaultValue)
ComponentStatus
getStatus()
String
getVersion()
boolean
isEmpty()
CacheSet<K>
keySet()
Returns a set view of the keys contained in this cache and cache loader across the entire cluster.V
merge(K key, V value, BiFunction<? super V,? super V,? extends V> remappingFunction)
V
merge(K key, V value, BiFunction<? super V,? super V,? extends V> remappingFunction, long lifespan, TimeUnit lifespanUnit)
V
merge(K key, V value, BiFunction<? super V,? super V,? extends V> remappingFunction, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit)
CompletableFuture<V>
mergeAsync(K key, V value, BiFunction<? super V,? super V,? extends V> remappingFunction)
CompletableFuture<V>
mergeAsync(K key, V value, BiFunction<? super V,? super V,? extends V> remappingFunction, long lifespan, TimeUnit lifespanUnit)
CompletableFuture<V>
mergeAsync(K key, V value, BiFunction<? super V,? super V,? extends V> remappingFunction, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit)
V
put(K key, V value)
V
put(K key, V value, long lifespan, TimeUnit unit)
V
put(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit)
void
putAll(Map<? extends K,? extends V> t)
void
putAll(Map<? extends K,? extends V> map, long lifespan, TimeUnit unit)
void
putAll(Map<? extends K,? extends V> map, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit)
CompletableFuture<Void>
putAllAsync(Map<? extends K,? extends V> data)
CompletableFuture<Void>
putAllAsync(Map<? extends K,? extends V> data, long lifespan, TimeUnit unit)
CompletableFuture<Void>
putAllAsync(Map<? extends K,? extends V> data, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit)
CompletableFuture<V>
putAsync(K key, V value)
CompletableFuture<V>
putAsync(K key, V value, long lifespan, TimeUnit unit)
CompletableFuture<V>
putAsync(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit)
void
putForExternalRead(K key, V value)
Under special operating behavior, associates the value with the specified key.void
putForExternalRead(K key, V value, long lifespan, TimeUnit unit)
An overloaded form of#putForExternalRead(K, V)
, which takes in lifespan parameters.void
putForExternalRead(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit)
An overloaded form of#putForExternalRead(K, V)
, which takes in lifespan parameters.V
putIfAbsent(K key, V value)
V
putIfAbsent(K key, V value, long lifespan, TimeUnit unit)
V
putIfAbsent(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit)
CompletableFuture<V>
putIfAbsentAsync(K key, V value)
CompletableFuture<V>
putIfAbsentAsync(K key, V value, long lifespan, TimeUnit unit)
CompletableFuture<V>
putIfAbsentAsync(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit)
V
remove(Object key)
boolean
remove(Object key, Object value)
CompletableFuture<V>
removeAsync(Object key)
CompletableFuture<Boolean>
removeAsync(Object key, Object value)
void
removeListener(Object listener)
Removes a listener from the component.CompletionStage<Void>
removeListenerAsync(Object listener)
Asynchronous version ofListenable.removeListener(Object)
V
replace(K key, V value)
V
replace(K key, V value, long lifespan, TimeUnit unit)
V
replace(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit)
boolean
replace(K key, V oldValue, V newValue)
boolean
replace(K key, V oldValue, V value, long lifespan, TimeUnit unit)
boolean
replace(K key, V oldValue, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit)
void
replaceAll(BiFunction<? super K,? super V,? extends V> function)
CompletableFuture<V>
replaceAsync(K key, V value)
CompletableFuture<V>
replaceAsync(K key, V value, long lifespan, TimeUnit unit)
CompletableFuture<V>
replaceAsync(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit)
CompletableFuture<Boolean>
replaceAsync(K key, V oldValue, V newValue)
CompletableFuture<Boolean>
replaceAsync(K key, V oldValue, V newValue, long lifespan, TimeUnit unit)
CompletableFuture<Boolean>
replaceAsync(K key, V oldValue, V newValue, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit)
protected void
set(K key, V value)
Don't remove.void
shutdown()
Performs a controlled, clustered shutdown of the cache.int
size()
Returns a count of all elements in this cache and cache loader across the entire cluster.CompletableFuture<Long>
sizeAsync()
void
start()
boolean
startBatch()
void
stop()
Stops a cache.String
toString()
static <K,V>
Cache<K,V>unwrapCache(Cache<K,V> cache)
Fully unwraps a given cache returning the base cache.CacheCollection<V>
values()
Returns a collection view of the values contained in this cache across the entire cluster.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.infinispan.Cache
compute, compute, compute, computeAsync, computeAsync, computeAsync, computeIfAbsent, computeIfAbsent, computeIfAbsent, computeIfAbsentAsync, computeIfAbsentAsync, computeIfAbsentAsync, computeIfPresent, computeIfPresentAsync, merge, merge, merge, mergeAsync, mergeAsync, mergeAsync
-
-
-
-
Method Detail
-
putForExternalRead
public void putForExternalRead(K key, V value)
Description copied from interface:Cache
Under special operating behavior, associates the value with the specified key.- Only goes through if the
key specified does not exist; no-op otherwise (similar to
ConcurrentMap.putIfAbsent(Object, Object)
) - Force asynchronous mode for replication to prevent any blocking.
- invalidation does not take place.
- 0ms lock timeout to prevent any blocking here either. If the lock is not acquired, this method is a no-op, and swallows the timeout exception.
- Ongoing transactions are suspended before this call, so failures here will not affect any ongoing transactions.
- Errors and exceptions are 'silent' - logged at a much lower level than normal, and this method does not throw exceptions
- Specified by:
putForExternalRead
in interfaceCache<K,V>
- Parameters:
key
- key with which the specified value is to be associated.value
- value to be associated with the specified key.
- Only goes through if the
key specified does not exist; no-op otherwise (similar to
-
putForExternalRead
public void putForExternalRead(K key, V value, long lifespan, TimeUnit unit)
Description copied from interface:Cache
An overloaded form of#putForExternalRead(K, V)
, which takes in lifespan parameters.- Specified by:
putForExternalRead
in interfaceCache<K,V>
- Parameters:
key
- key to usevalue
- value to storelifespan
- lifespan of the entry. Negative values are interpreted as unlimited lifespan.unit
- unit of measurement for the lifespan
-
putForExternalRead
public void putForExternalRead(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit)
Description copied from interface:Cache
An overloaded form of#putForExternalRead(K, V)
, which takes in lifespan parameters.- Specified by:
putForExternalRead
in interfaceCache<K,V>
- Parameters:
key
- key to usevalue
- value to storelifespan
- lifespan of the entry. Negative values are interpreted as unlimited lifespan.lifespanUnit
- time unit for lifespanmaxIdle
- the maximum amount of time this key is allowed to be idle for before it is considered as expiredmaxIdleUnit
- time unit for max idle time
-
evict
public void evict(K key)
Description copied from interface:Cache
Evicts an entry from the memory of the cache. Note that the entry is not removed from any configured cache stores or any other caches in the cluster (if used in a clustered mode). UseBasicCache.remove(Object)
to remove an entry from the entire cache system. This method is designed to evict an entry from memory to free up memory used by the application. This method uses a 0 lock acquisition timeout so it does not block in attempting to acquire locks. It behaves as a no-op if the lock on the entry cannot be acquired immediately. Important: this method should not be called from within a transaction scope.
-
getCacheConfiguration
public Configuration getCacheConfiguration()
- Specified by:
getCacheConfiguration
in interfaceCache<K,V>
-
startBatch
public boolean startBatch()
- Specified by:
startBatch
in interfaceorg.infinispan.commons.api.BatchingCache
-
endBatch
public void endBatch(boolean successful)
- Specified by:
endBatch
in interfaceorg.infinispan.commons.api.BatchingCache
-
getName
public String getName()
-
getCacheName
@ManagedAttribute(description="Returns the cache name", displayName="Cache name", dataType=TRAIT) public String getCacheName()
-
getVersion
@ManagedAttribute(description="Returns the version of Infinispan", displayName="Infinispan version", dataType=TRAIT) public String getVersion()
-
getCacheManager
public EmbeddedCacheManager getCacheManager()
Description copied from interface:Cache
Retrieves the cache manager responsible for creating this cache instance.- Specified by:
getCacheManager
in interfaceCache<K,V>
- Returns:
- a cache manager
-
put
public V put(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit)
-
putIfAbsent
public V putIfAbsent(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit)
-
putAll
public void putAll(Map<? extends K,? extends V> map, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit)
-
replace
public V replace(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit)
-
replace
public boolean replace(K key, V oldValue, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit)
-
replaceAll
public void replaceAll(BiFunction<? super K,? super V,? extends V> function)
- Specified by:
replaceAll
in interfaceConcurrentMap<K,V>
- Specified by:
replaceAll
in interfaceMap<K,V>
-
putAsync
public CompletableFuture<V> putAsync(K key, V value)
-
putAsync
public CompletableFuture<V> putAsync(K key, V value, long lifespan, TimeUnit unit)
-
putAsync
public CompletableFuture<V> putAsync(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit)
-
putAllAsync
public CompletableFuture<Void> putAllAsync(Map<? extends K,? extends V> data)
-
putAllAsync
public CompletableFuture<Void> putAllAsync(Map<? extends K,? extends V> data, long lifespan, TimeUnit unit)
-
putAllAsync
public CompletableFuture<Void> putAllAsync(Map<? extends K,? extends V> data, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit)
-
clearAsync
public CompletableFuture<Void> clearAsync()
-
putIfAbsentAsync
public CompletableFuture<V> putIfAbsentAsync(K key, V value)
-
putIfAbsentAsync
public CompletableFuture<V> putIfAbsentAsync(K key, V value, long lifespan, TimeUnit unit)
-
putIfAbsentAsync
public CompletableFuture<V> putIfAbsentAsync(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit)
-
removeAsync
public CompletableFuture<V> removeAsync(Object key)
-
removeAsync
public CompletableFuture<Boolean> removeAsync(Object key, Object value)
-
replaceAsync
public CompletableFuture<V> replaceAsync(K key, V value)
-
replaceAsync
public CompletableFuture<V> replaceAsync(K key, V value, long lifespan, TimeUnit unit)
-
replaceAsync
public CompletableFuture<V> replaceAsync(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit)
-
replaceAsync
public CompletableFuture<Boolean> replaceAsync(K key, V oldValue, V newValue)
-
replaceAsync
public CompletableFuture<Boolean> replaceAsync(K key, V oldValue, V newValue, long lifespan, TimeUnit unit)
-
replaceAsync
public CompletableFuture<Boolean> replaceAsync(K key, V oldValue, V newValue, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit)
-
computeAsync
public CompletableFuture<V> computeAsync(K key, BiFunction<? super K,? super V,? extends V> remappingFunction)
-
computeAsync
public CompletableFuture<V> computeAsync(K key, BiFunction<? super K,? super V,? extends V> remappingFunction, long lifespan, TimeUnit lifespanUnit)
-
computeAsync
public CompletableFuture<V> computeAsync(K key, BiFunction<? super K,? super V,? extends V> remappingFunction, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit)
-
computeIfAbsentAsync
public CompletableFuture<V> computeIfAbsentAsync(K key, Function<? super K,? extends V> mappingFunction)
-
computeIfAbsentAsync
public CompletableFuture<V> computeIfAbsentAsync(K key, Function<? super K,? extends V> mappingFunction, long lifespan, TimeUnit lifespanUnit)
-
computeIfAbsentAsync
public CompletableFuture<V> computeIfAbsentAsync(K key, Function<? super K,? extends V> mappingFunction, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit)
-
computeIfPresentAsync
public CompletableFuture<V> computeIfPresentAsync(K key, BiFunction<? super K,? super V,? extends V> remappingFunction)
-
computeIfPresentAsync
public CompletableFuture<V> computeIfPresentAsync(K key, BiFunction<? super K,? super V,? extends V> remappingFunction, long lifespan, TimeUnit lifespanUnit)
-
computeIfPresentAsync
public CompletableFuture<V> computeIfPresentAsync(K key, BiFunction<? super K,? super V,? extends V> remappingFunction, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit)
-
mergeAsync
public CompletableFuture<V> mergeAsync(K key, V value, BiFunction<? super V,? super V,? extends V> remappingFunction)
-
mergeAsync
public CompletableFuture<V> mergeAsync(K key, V value, BiFunction<? super V,? super V,? extends V> remappingFunction, long lifespan, TimeUnit lifespanUnit)
-
mergeAsync
public CompletableFuture<V> mergeAsync(K key, V value, BiFunction<? super V,? super V,? extends V> remappingFunction, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit)
-
getAdvancedCache
public AdvancedCache<K,V> getAdvancedCache()
- Specified by:
getAdvancedCache
in interfaceCache<K,V>
-
getStatus
public ComponentStatus getStatus()
-
getCacheStatus
@ManagedAttribute(description="Returns the cache status", displayName="Cache status", dataType=TRAIT) public String getCacheStatus()
Returns String representation of ComponentStatus enumeration in order to avoid class not found exceptions in JMX tools that don't have access to infinispan classes.
-
putIfAbsent
public V putIfAbsent(K key, V value)
- Specified by:
putIfAbsent
in interfaceConcurrentMap<K,V>
- Specified by:
putIfAbsent
in interfaceMap<K,V>
-
size
public int size()
Description copied from interface:Cache
Returns a count of all elements in this cache and cache loader across the entire cluster. Only a subset of entries is held in memory at a time when using a loader or remote entries, to prevent possible memory issues, however the loading of said entries can still be vary slow. If there are performance concerns then theFlag.SKIP_CACHE_LOAD
flag should be used to avoid hitting the cache loader in case if this is not needed in the size calculation. Also if you want the local contents only you can use theFlag.CACHE_MODE_LOCAL
flag so that other remote nodes are not queried for data. However the loader will still be used unless the previously mentionedFlag.SKIP_CACHE_LOAD
is also configured. If this method is used in a transactional context, note this method will not bring additional values into the transaction context and thus objects that haven't yet been read will act in aIsolationLevel.READ_COMMITTED
behavior irrespective of the configured isolation level. However values that have been previously modified or read that are in the context will be adhered to. e.g. any write modification or any previous read when usingIsolationLevel.REPEATABLE_READ
This method should only be used for debugging purposes such as to verify that the cache contains all the keys entered. Any other use involving execution of this method on a production system is not recommended.
-
sizeAsync
public CompletableFuture<Long> sizeAsync()
-
containsKey
public boolean containsKey(Object key)
- Specified by:
containsKey
in interfaceMap<K,V>
-
containsValue
public boolean containsValue(Object value)
- Specified by:
containsValue
in interfaceMap<K,V>
-
compute
public V compute(K key, BiFunction<? super K,? super V,? extends V> remappingFunction)
Description copied from interface:Cache
When this method is used on a clustered cache, either replicated or distributed, the bifunction will be serialized to owning nodes to perform the operation in the most performant way. However this means the bifunction must have an appropriate
Externalizer
or beSerializable
itself.For transactional caches, whenever the values of the caches are collections, and the mapping function modifies the collection, the collection must be copied and not directly modified, otherwise whenever rollback is called it won't work. This limitation could disappear in following releases if technically possible.
-
compute
public V compute(K key, BiFunction<? super K,? super V,? extends V> remappingFunction, long lifespan, TimeUnit lifespanUnit)
-
compute
public V compute(K key, BiFunction<? super K,? super V,? extends V> remappingFunction, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit)
-
computeIfPresent
public V computeIfPresent(K key, BiFunction<? super K,? super V,? extends V> remappingFunction)
Description copied from interface:Cache
When this method is used on a clustered cache, either replicated or distributed, the bifunction will be serialized to owning nodes to perform the operation in the most performant way. However this means the bifunction must have an appropriate
Externalizer
or beSerializable
itself.For transactional caches, whenever the values of the caches are collections, and the mapping function modifies the collection, the collection must be copied and not directly modified, otherwise whenever rollback is called it won't work. This limitation could disappear in following releases if technically possible.
- Specified by:
computeIfPresent
in interfaceCache<K,V>
- Specified by:
computeIfPresent
in interfaceConcurrentMap<K,V>
- Specified by:
computeIfPresent
in interfaceMap<K,V>
-
computeIfPresent
public V computeIfPresent(K key, BiFunction<? super K,? super V,? extends V> remappingFunction, long lifespan, TimeUnit lifespanUnit)
-
computeIfPresent
public V computeIfPresent(K key, BiFunction<? super K,? super V,? extends V> remappingFunction, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit)
-
computeIfAbsent
public V computeIfAbsent(K key, Function<? super K,? extends V> mappingFunction)
Description copied from interface:Cache
When this method is used on a clustered cache, either replicated or distributed, the function will be serialized to owning nodes to perform the operation in the most performant way. However this means the function must have an appropriate
Externalizer
or beSerializable
itself.For transactional caches, whenever the values of the caches are collections, and the mapping function modifies the collection, the collection must be copied and not directly modified, otherwise whenever rollback is called it won't work. This limitation could disappear in following releases if technically possible.
- Specified by:
computeIfAbsent
in interfaceCache<K,V>
- Specified by:
computeIfAbsent
in interfaceConcurrentMap<K,V>
- Specified by:
computeIfAbsent
in interfaceMap<K,V>
-
computeIfAbsent
public V computeIfAbsent(K key, Function<? super K,? extends V> mappingFunction, long lifespan, TimeUnit lifespanUnit)
-
computeIfAbsent
public V computeIfAbsent(K key, Function<? super K,? extends V> mappingFunction, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit)
-
getOrDefault
public V getOrDefault(Object key, V defaultValue)
- Specified by:
getOrDefault
in interfaceConcurrentMap<K,V>
- Specified by:
getOrDefault
in interfaceMap<K,V>
-
merge
public V merge(K key, V value, BiFunction<? super V,? super V,? extends V> remappingFunction)
Description copied from interface:Cache
When this method is used on a clustered cache, either replicated or distributed, the bifunction will be serialized to owning nodes to perform the operation in the most performant way. However this means the bifunction must have an appropriate
Externalizer
or beSerializable
itself.For transactional caches, whenever the values of the caches are collections, and the mapping function modifies the collection, the collection must be copied and not directly modified, otherwise whenever rollback is called it won't work. This limitation could disappear in following releases if technically possible.
-
merge
public V merge(K key, V value, BiFunction<? super V,? super V,? extends V> remappingFunction, long lifespan, TimeUnit lifespanUnit)
-
merge
public V merge(K key, V value, BiFunction<? super V,? super V,? extends V> remappingFunction, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit)
-
forEach
public void forEach(BiConsumer<? super K,? super V> action)
-
clear
@ManagedOperation(description="Clears the cache", displayName="Clears the cache", name="clear") public void clear()
Description copied from interface:Cache
Removes all mappings from the cache. Note: This should never be invoked in production unless you can guarantee no other invocations are ran concurrently. If the cache is transactional, it will not interact with the transaction.
-
keySet
public CacheSet<K> keySet()
Description copied from interface:Cache
Returns a set view of the keys contained in this cache and cache loader across the entire cluster. Modifications and changes to the cache will be reflected in the set and vice versa. When this method is called nothing is actually queried as the backing set is just returned. Invocation on the set itself is when the various operations are ran.Unsupported Operations
Care should be taken when invokingSet.toArray()
,Set.toArray(Object[])
,Set.size()
,Set.retainAll(Collection)
andSet.iterator()
methods as they will traverse the entire contents of the cluster including a configuredCacheLoader
and remote entries. The former 2 methods especially have a very high likely hood of causing aOutOfMemoryError
due to storing all the keys in the entire cluster in the array. Use involving execution of this method on a production system is not recommended as they can be quite expensive operationsSupported Flags
Note any flag configured for the cache will also be passed along to the backing set when it was created. If additional flags are configured on the cache they will not affect any existing backings sets. If there are performance concerns then theFlag.SKIP_CACHE_LOAD
flag should be used to avoid hitting the cache store as this will cause all entries there to be read in (albeit in a batched form to preventOutOfMemoryError
) Also if you want the local contents only you can use theFlag.CACHE_MODE_LOCAL
flag so that other remote nodes are not queried for data. However the loader will still be used unless the previously mentionedFlag.SKIP_CACHE_LOAD
is also configured.Iterator Use
This class implements theCloseableIteratorSet
interface which creates aCloseableIterator
instead of a regular one. This means this iterator must be explicitly closed either through try with resource or calling the close method directly. Technically this iterator will also close itself if you iterate fully over it, but it is safest to always make sure you close it explicitly.Unsupported Operations
Due to not being able to add null values the following methods are not supported and will throwUnsupportedOperationException
if invoked.Set.add(Object)
Set.addAll(java.util.Collection)
-
entrySet
public CacheSet<Map.Entry<K,V>> entrySet()
Description copied from interface:Cache
Returns a set view of the mappings contained in this cache and cache loader across the entire cluster. Modifications and changes to the cache will be reflected in the set and vice versa. When this method is called nothing is actually queried as the backing set is just returned. Invocation on the set itself is when the various operations are ran. Care should be taken when invokingSet.toArray()
,Set.toArray(Object[])
,Set.size()
,Set.retainAll(Collection)
andSet.iterator()
methods as they will traverse the entire contents of the cluster including a configuredCacheLoader
and remote entries. The former 2 methods especially have a very high likely hood of causing aOutOfMemoryError
due to storing all the keys in the entire cluster in the array. Use involving execution of this method on a production system is not recommended as they can be quite expensive operations *Supported Flags
Note any flag configured for the cache will also be passed along to the backing set when it was created. If additional flags are configured on the cache they will not affect any existing backings sets. If there are performance concerns then theFlag.SKIP_CACHE_LOAD
flag should be used to avoid hitting the cache store as this will cause all entries there to be read in (albeit in a batched form to preventOutOfMemoryError
) Also if you want the local contents only you can use theFlag.CACHE_MODE_LOCAL
flag so that other remote nodes are not queried for data. However the loader will still be used unless the previously mentionedFlag.SKIP_CACHE_LOAD
is also configured.Modifying or Adding Entries
An entry's value is supported to be modified by using theMap.Entry.setValue(Object)
and it will update the cache as well. Also this backing set does allow addition of a new Map.Entry(s) via theSet.add(Object)
orSet.addAll(java.util.Collection)
methods.Iterator Use
This class implements theCloseableIteratorSet
interface which creates aCloseableIterator
instead of a regular one. This means this iterator must be explicitly closed either through try with resource or calling the close method directly. Technically this iterator will also close itself if you iterate fully over it, but it is safest to always make sure you close it explicitly.
-
values
public CacheCollection<V> values()
Description copied from interface:Cache
Returns a collection view of the values contained in this cache across the entire cluster. Modifications and changes to the cache will be reflected in the set and vice versa. When this method is called nothing is actually queried as the backing collection is just returned. Invocation on the collection itself is when the various operations are ran. Care should be taken when invokingCollection.toArray()
,Collection.toArray(Object[])
,Collection.size()
,Collection.retainAll(Collection)
andCollection.iterator()
methods as they will traverse the entire contents of the cluster including a configuredCacheLoader
and remote entries. The former 2 methods especially have a very high likely hood of causing aOutOfMemoryError
due to storing all the keys in the entire cluster in the array. Use involving execution of this method on a production system is not recommended as they can be quite expensive operations *Supported Flags
Note any flag configured for the cache will also be passed along to the backing set when it was created. If additional flags are configured on the cache they will not affect any existing backings sets. If there are performance concerns then theFlag.SKIP_CACHE_LOAD
flag should be used to avoid hitting the cache store as this will cause all entries there to be read in (albeit in a batched form to preventOutOfMemoryError
) Also if you want the local contents only you can use theFlag.CACHE_MODE_LOCAL
flag so that other remote nodes are not queried for data. However the loader will still be used unless the previously mentionedFlag.SKIP_CACHE_LOAD
is also configured.Iterator Use
This class implements the
CloseableIteratorCollection
interface which creates aCloseableIterator
instead of a regular one. This means this iterator must be explicitly closed either through try with resource or calling the close method directly. Technically this iterator will also close itself if you iterate fully over it, but it is safest to always make sure you close it explicitly.The iterator retrieved using
CloseableIteratorCollection.iterator()
supports the remove method, however the iterator retrieved fromCacheStream.iterator()
will not support remove.Unsupported Operations
Due to not being able to add null values the following methods are not supported and will throwUnsupportedOperationException
if invoked.Set.add(Object)
Set.addAll(java.util.Collection)
-
start
@ManagedOperation(description="Starts the cache.", displayName="Starts cache.") public void start()
- Specified by:
start
in interfaceorg.infinispan.commons.api.Lifecycle
-
stop
@ManagedOperation(description="Stops the cache.", displayName="Stops cache.") public void stop()
Description copied from interface:Cache
Stops a cache. If the cache is clustered, this only stops the cache on the node where it is being invoked. If you need to stop the cache across a cluster, use theCache.shutdown()
method.
-
shutdown
@ManagedOperation(description="Shuts down the cache across the cluster", displayName="Clustered cache shutdown") public void shutdown()
Description copied from interface:Cache
Performs a controlled, clustered shutdown of the cache. When invoked, the following operations are performed:- rebalancing for the cache is disabled
- in-memory data is flushed/passivated to any persistent stores
- state is persisted to the location defined in
GlobalStateConfigurationBuilder.persistentLocation(String)
Cache.stop()
only in clustered modes, and only whenGlobalStateConfiguration.enabled()
is true, otherwise it just behaves likeCache.stop()
.
-
addListener
public void addListener(Object listener)
Description copied from interface:Listenable
Adds a listener to the component. Typically, listeners would need to be annotated withListener
and further to that, contain methods annotated appropriately, otherwise the listener will not be registered. See theListener
annotation for more information.- Specified by:
addListener
in interfaceListenable
- Parameters:
listener
- listener to add, must not be null
-
addListenerAsync
public CompletionStage<Void> addListenerAsync(Object listener)
Description copied from interface:Listenable
Asynchronous version ofListenable.addListener(Object)
- Specified by:
addListenerAsync
in interfaceListenable
- Parameters:
listener
- listener to add, must not be null- Returns:
- CompletionStage that when complete the listener is fully installed
-
addListener
public <C> void addListener(Object listener, CacheEventFilter<? super K,? super V> filter, CacheEventConverter<? super K,? super V,C> converter)
Description copied from interface:FilteringListenable
Registers a listener that will be notified on events that pass the filter condition. The value presented in the notifications will be first converted using the provided converter if there is one.Some implementations may provide optimizations when a
CacheEventFilterConverter
is provided as both arguments to the filter and converter arguments. Note the provided object must have reference equality ie. (==) to be recognized. This allows for the filter and conversion step to take place in the same method call reducing possible overhead.- Specified by:
addListener
in interfaceFilteringListenable<K,V>
- Type Parameters:
C
- The type of the resultant value after being converted- Parameters:
listener
- The listener to callback upon event notifications. Must not be null.filter
- The filter to see if the notification should be sent to the listener. Can be null.converter
- The converter to apply to the entry before being sent to the listener. Can be null.
-
addListenerAsync
public <C> CompletionStage<Void> addListenerAsync(Object listener, CacheEventFilter<? super K,? super V> filter, CacheEventConverter<? super K,? super V,C> converter)
Description copied from interface:FilteringListenable
Asynchronous version ofFilteringListenable.addListener(Object, CacheEventFilter, CacheEventConverter)
- Specified by:
addListenerAsync
in interfaceFilteringListenable<K,V>
- Parameters:
listener
- listener to add, must not be null- Returns:
- CompletionStage that when complete the listener is fully installed
-
removeListener
public void removeListener(Object listener)
Description copied from interface:Listenable
Removes a listener from the component.- Specified by:
removeListener
in interfaceListenable
- Parameters:
listener
- listener to remove. Must not be null.
-
removeListenerAsync
public CompletionStage<Void> removeListenerAsync(Object listener)
Description copied from interface:Listenable
Asynchronous version ofListenable.removeListener(Object)
- Specified by:
removeListenerAsync
in interfaceListenable
- Parameters:
listener
- listener to remove, must not be null- Returns:
- CompletionStage that when complete the listener is fully removed
-
getListeners
@Deprecated public Set<Object> getListeners()
Deprecated.- Specified by:
getListeners
in interfaceListenable
- Returns:
- a set of all listeners registered on this component.
-
addFilteredListener
public <C> void addFilteredListener(Object listener, CacheEventFilter<? super K,? super V> filter, CacheEventConverter<? super K,? super V,C> converter, Set<Class<? extends Annotation>> filterAnnotations)
Description copied from interface:FilteringListenable
Registers a listener limiting the cache-entry specific events only to annotations that are passed in as parameter. For example, if the listener passed in contains callbacks forCacheEntryCreated
andCacheEntryModified
, and filtered annotations contains onlyCacheEntryCreated
, then the listener will be registered only forCacheEntryCreated
callbacks. Callback filtering only applies toCacheEntryCreated
,CacheEntryModified
,CacheEntryRemoved
andCacheEntryExpired
annotations. If the listener contains other annotations, these are preserved. This methods enables dynamic registration of listener interests at runtime without the need to create several different listener classes.- Specified by:
addFilteredListener
in interfaceFilteringListenable<K,V>
- Type Parameters:
C
- The type of the resultant value after being converted- Parameters:
listener
- The listener to callback upon event notifications. Must not be null.filter
- The filter to see if the notification should be sent to the listener. Can be null.converter
- The converter to apply to the entry before being sent to the listener. Can be null.filterAnnotations
- cache-entry annotations to allow listener to be registered on. Must not be null.
-
addFilteredListenerAsync
public <C> CompletionStage<Void> addFilteredListenerAsync(Object listener, CacheEventFilter<? super K,? super V> filter, CacheEventConverter<? super K,? super V,C> converter, Set<Class<? extends Annotation>> filterAnnotations)
Description copied from interface:FilteringListenable
Asynchronous version ofFilteringListenable.addFilteredListener(Object, CacheEventFilter, CacheEventConverter, Set)
- Specified by:
addFilteredListenerAsync
in interfaceFilteringListenable<K,V>
-
addStorageFormatFilteredListener
public <C> void addStorageFormatFilteredListener(Object listener, CacheEventFilter<? super K,? super V> filter, CacheEventConverter<? super K,? super V,C> converter, Set<Class<? extends Annotation>> filterAnnotations)
Description copied from interface:FilteringListenable
Same asFilteringListenable.addFilteredListener(Object, CacheEventFilter, CacheEventConverter, Set)
, but assumes the filter and/or the converter will be done in the same data format as it's stored in the cache.- Specified by:
addStorageFormatFilteredListener
in interfaceFilteringListenable<K,V>
-
addStorageFormatFilteredListenerAsync
public <C> CompletionStage<Void> addStorageFormatFilteredListenerAsync(Object listener, CacheEventFilter<? super K,? super V> filter, CacheEventConverter<? super K,? super V,C> converter, Set<Class<? extends Annotation>> filterAnnotations)
Description copied from interface:FilteringListenable
Asynchronous version ofFilteringListenable.addStorageFormatFilteredListener(Object, CacheEventFilter, CacheEventConverter, Set)
- Specified by:
addStorageFormatFilteredListenerAsync
in interfaceFilteringListenable<K,V>
-
getAsync
public CompletableFuture<V> getAsync(K key)
-
getAllAsync
public CompletableFuture<Map<K,V>> getAllAsync(Set<?> keys)
-
getConfigurationAsProperties
@ManagedAttribute(description="Returns the cache configuration in form of properties", displayName="Cache configuration properties", dataType=TRAIT) public Properties getConfigurationAsProperties()
-
-