Class StatsCollectingCache<K,V>
- java.lang.Object
-
- org.infinispan.cache.impl.SimpleCacheImpl<K,V>
-
- org.infinispan.cache.impl.StatsCollectingCache<K,V>
-
- All Implemented Interfaces:
ConcurrentMap<K,V>
,Map<K,V>
,AdvancedCache<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
,org.infinispan.commons.api.TransactionalCache
,FilteringListenable<K,V>
,Listenable
public class StatsCollectingCache<K,V> extends SimpleCacheImpl<K,V>
Wraps existingAdvancedCache
to collect statistics- Author:
- Radim Vansa <rvansa@redhat.com>
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.infinispan.cache.impl.SimpleCacheImpl
SimpleCacheImpl.CacheEntryChange<K,V>, SimpleCacheImpl.CacheEntrySet, SimpleCacheImpl.EntrySet, SimpleCacheImpl.EntrySetBase<T extends Map.Entry<K,V>>, SimpleCacheImpl.KeySet, SimpleCacheImpl.ValueAndMetadata<V>, SimpleCacheImpl.Values
-
-
Constructor Summary
Constructors Constructor Description StatsCollectingCache(String cacheName)
StatsCollectingCache(String cacheName, DataConversion keyDataConversion, DataConversion valueDataConversion)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected V
computeIfAbsentInternal(K key, Function<? super K,? extends V> mappingFunction, org.infinispan.commons.util.ByRef<V> newValueRef)
protected V
computeIfPresentInternal(K key, BiFunction<? super K,? super V,? extends V> remappingFunction, SimpleCacheImpl.CacheEntryChange<K,V> ref)
protected V
computeInternal(K key, BiFunction<? super K,? super V,? extends V> remappingFunction, SimpleCacheImpl.CacheEntryChange<K,V> ref)
void
evict(K key)
Evicts an entry from the memory of the cache.V
get(Object key)
Map<K,V>
getAll(Set<?> keys)
Gets a collection of entries, returning them asMap
of the values associated with the set of keys requested.Map<K,CacheEntry<K,V>>
getAllCacheEntries(Set<?> keys)
Gets a collection of entries from theAdvancedCache
, returning them asMap
of the cache entries associated with the set of keys requested.Map<K,V>
getAndPutAll(Map<? extends K,? extends V> entries)
Executes an equivalent ofMap.putAll(Map)
, returning previous values of the modified entries.protected V
getAndPutInternal(K key, V value, Metadata metadata)
protected V
getAndReplaceInternal(K key, V value, Metadata metadata)
CacheEntry<K,V>
getCacheEntry(Object k)
Retrieves a CacheEntry corresponding to a specific key.Stats
getStats()
Returns aStats
object that allows several statistics associated with this cache at runtime.protected V
mergeInternal(K key, V value, BiFunction<? super V,? super V,? extends V> remappingFunction, SimpleCacheImpl.CacheEntryChange<K,V> ref, Metadata metadata)
protected void
putForExternalReadInternal(K key, V value, Metadata metadata, org.infinispan.commons.util.ByRef.Boolean isCreatedRef)
protected V
putIfAbsentInternal(K key, V value, Metadata metadata)
V
remove(Object key)
If the return value of this operation will be ignored by the application, the user is strongly encouraged to use theFlag.IGNORE_RETURN_VALUES
flag when invoking this method in order to make it behave as efficiently as possible (i.e.boolean
remove(Object key, Object value)
protected boolean
replaceInternal(K key, V oldValue, V value, Metadata metadata)
String
toString()
AdvancedCache<K,V>
with(ClassLoader classLoader)
Using this operation, users can call anyAdvancedCache
operation with a givenClassLoader
.AdvancedCache<K,V>
withFlags(Flag... flags)
A method that adds flags to any API call.-
Methods inherited from class org.infinispan.cache.impl.SimpleCacheImpl
addFilteredListener, addInterceptor, addInterceptorAfter, addInterceptorBefore, addListener, addListener, addListener, addStorageFormatFilteredListener, applyDelta, cacheEntrySet, checkExpiration, clear, clearAsync, compute, compute, compute, compute, computeAsync, computeAsync, computeAsync, computeAsync, computeIfAbsent, computeIfAbsent, computeIfAbsent, computeIfAbsent, computeIfAbsentAsync, computeIfAbsentAsync, computeIfAbsentAsync, computeIfAbsentAsync, computeIfPresent, computeIfPresent, computeIfPresent, computeIfPresent, computeIfPresentAsync, computeIfPresentAsync, computeIfPresentAsync, computeIfPresentAsync, containsKey, containsValue, endBatch, entrySet, forEach, getAdvancedCache, getAllAsync, getAsync, getAsyncInterceptorChain, getAuthorizationManager, getAvailability, getBatchContainer, getCacheConfiguration, getCacheEntryAsync, getCacheManager, getCacheName, getCacheStatus, getClassLoader, getComponentRegistry, getConfigurationAsProperties, getDataContainer, getDistributionManager, getEvictionManager, getExpirationManager, getGroup, getInterceptorChain, getInvocationContextContainer, getKeyDataConversion, getKeyEncoder, getKeyWrapper, getListeners, getLockManager, getName, getRpcManager, getStatus, getStreamSupplier, getTransactionManager, getValueDataConversion, getValueEncoder, getValueWrapper, getVersion, getXAResource, injectDependencies, isEmpty, keySet, lock, lock, lockAs, lockedStream, merge, merge, merge, merge, mergeAsync, mergeAsync, mergeAsync, mergeAsync, noFlags, put, put, put, put, putAll, putAll, putAll, putAll, putAllAsync, putAllAsync, putAllAsync, putAllAsync, putAllInternal, putAsync, putAsync, putAsync, putAsync, putForExternalRead, putForExternalRead, putForExternalRead, putForExternalRead, putIfAbsent, putIfAbsent, putIfAbsent, putIfAbsent, putIfAbsentAsync, putIfAbsentAsync, putIfAbsentAsync, putIfAbsentAsync, removeAsync, removeAsync, removeGroup, removeInterceptor, removeInterceptor, removeLifespanExpired, removeListener, removeMaxIdleExpired, replace, replace, replace, replace, replace, replace, replace, replace, replaceAll, replaceAsync, replaceAsync, replaceAsync, replaceAsync, replaceAsync, replaceAsync, replaceAsync, replaceAsync, setAvailability, size, start, startBatch, stop, transform, values, withEncoding, withEncoding, withFlags, withKeyEncoding, withMediaType, withSubject, withWrapping, withWrapping
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.infinispan.AdvancedCache
compute, computeAsync, computeIfAbsent, computeIfAbsentAsync, computeIfPresent, computeIfPresentAsync, merge, mergeAsync
-
Methods inherited from interface org.infinispan.Cache
compute, computeIfAbsent, computeIfAbsent, computeIfAbsent, computeIfPresent, merge, shutdown
-
Methods inherited from interface java.util.concurrent.ConcurrentMap
getOrDefault
-
-
-
-
Constructor Detail
-
StatsCollectingCache
public StatsCollectingCache(String cacheName)
-
StatsCollectingCache
public StatsCollectingCache(String cacheName, DataConversion keyDataConversion, DataConversion valueDataConversion)
-
-
Method Detail
-
withFlags
public AdvancedCache<K,V> withFlags(Flag... flags)
Description copied from interface:AdvancedCache
A method that adds flags to any API call. For example, consider the following code snippet:cache.withFlags(Flag.FORCE_WRITE_LOCK).get(key);
will invoke a cache.get() with a write lock forced. Note that for the flag to take effect, the cache operation must be invoked on the instance returned by this method. As an alternative to setting this on every invocation, users could also consider using theDecoratedCache
wrapper, as this allows for more readable code. E.g.:Cache forceWriteLockCache = new DecoratedCache(cache, Flag.FORCE_WRITE_LOCK); forceWriteLockCache.get(key1); forceWriteLockCache.get(key2); forceWriteLockCache.get(key3);
- Specified by:
withFlags
in interfaceAdvancedCache<K,V>
- Overrides:
withFlags
in classSimpleCacheImpl<K,V>
- Parameters:
flags
- a set of flags to apply. See theFlag
documentation.- Returns:
- an
AdvancedCache
instance on which a real operation is to be invoked, if the flags are to be applied.
-
with
public AdvancedCache<K,V> with(ClassLoader classLoader)
Description copied from interface:AdvancedCache
Using this operation, users can call anyAdvancedCache
operation with a givenClassLoader
. This means that anyClassLoader
happening as a result of the cache operation will be done using theClassLoader
given. For example: When users store POJO instances in caches configured withStoreAsBinaryConfiguration
, these instances are transformed into byte arrays. When these entries are read from the cache, a lazy unmarshalling process happens where these byte arrays are transformed back into POJO instances. UsingAdvancedCache.with(ClassLoader)
when reading that enables users to provide the class loader that should be used when trying to locate the classes that are constructed as a result of the unmarshalling process.cache.with(classLoader).get(key);
Note that for the flag to take effect, the cache operation must be invoked on the instance returned by this method. As an alternative to setting this on every invocation, users could also consider using theDecoratedCache
wrapper, as this allows for more readable code. E.g.:Cache classLoaderSpecificCache = new DecoratedCache(cache, classLoader); classLoaderSpecificCache.get(key1); classLoaderSpecificCache.get(key2); classLoaderSpecificCache.get(key3);
- Specified by:
with
in interfaceAdvancedCache<K,V>
- Overrides:
with
in classSimpleCacheImpl<K,V>
- Returns:
- an
AdvancedCache
instance upon which operations can be called with a particularClassLoader
.
-
getStats
public Stats getStats()
Description copied from interface:AdvancedCache
Returns aStats
object that allows several statistics associated with this cache at runtime.- Specified by:
getStats
in interfaceAdvancedCache<K,V>
- Overrides:
getStats
in classSimpleCacheImpl<K,V>
- Returns:
- this cache's
Stats
object
-
getCacheEntry
public CacheEntry<K,V> getCacheEntry(Object k)
Description copied from interface:AdvancedCache
Retrieves a CacheEntry corresponding to a specific key.- Specified by:
getCacheEntry
in interfaceAdvancedCache<K,V>
- Overrides:
getCacheEntry
in classSimpleCacheImpl<K,V>
- Parameters:
k
- the key whose associated cache entry is to be returned- Returns:
- the cache entry to which the specified key is mapped, or
null
if this map contains no mapping for the key
-
getAll
public Map<K,V> getAll(Set<?> keys)
Description copied from interface:AdvancedCache
Gets a collection of entries, returning them asMap
of the values associated with the set of keys requested.If the cache is configured read-through, and a get for a key would return null because an entry is missing from the cache, the Cache's
CacheLoader
is called in an attempt to load the entry. If an entry cannot be loaded for a given key, the returned Map will contain null for value of the key.Unlike other bulk methods if this invoked in an existing transaction all entries will be stored in the current transactional context
The returned
Map
will be a copy and updates to the map will not be reflected in the Cache and vice versa. The keys and values themselves however may not be copies depending on if storeAsBinary is enabled and the value was retrieved from the local node.- Specified by:
getAll
in interfaceAdvancedCache<K,V>
- Overrides:
getAll
in classSimpleCacheImpl<K,V>
- Parameters:
keys
- The keys whose associated values are to be returned.- Returns:
- A map of entries that were found for the given keys. If an entry is not found for a given key, it will not be in the returned map.
-
getAllCacheEntries
public Map<K,CacheEntry<K,V>> getAllCacheEntries(Set<?> keys)
Description copied from interface:AdvancedCache
Gets a collection of entries from theAdvancedCache
, returning them asMap
of the cache entries associated with the set of keys requested.If the cache is configured read-through, and a get for a key would return null because an entry is missing from the cache, the Cache's
CacheLoader
is called in an attempt to load the entry. If an entry cannot be loaded for a given key, the returned Map will contain null for value of the key.Unlike other bulk methods if this invoked in an existing transaction all entries will be stored in the current transactional context
The returned
Map
will be a copy and updates to the map will not be reflected in the Cache and vice versa. The keys and values themselves however may not be copies depending on if storeAsBinary is enabled and the value was retrieved from the local node.- Specified by:
getAllCacheEntries
in interfaceAdvancedCache<K,V>
- Overrides:
getAllCacheEntries
in classSimpleCacheImpl<K,V>
- Parameters:
keys
- The keys whose associated values are to be returned.- Returns:
- A map of entries that were found for the given keys. Keys not found in the cache are present in the map with null values.
-
getAndPutAll
public Map<K,V> getAndPutAll(Map<? extends K,? extends V> entries)
Description copied from interface:AdvancedCache
Executes an equivalent ofMap.putAll(Map)
, returning previous values of the modified entries.- Parameters:
entries
- mappings to be stored in this map- Returns:
- A map of previous values for the given keys. If the previous mapping does not exist it will not be in the returned map.
-
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.
-
getAndPutInternal
protected V getAndPutInternal(K key, V value, Metadata metadata)
- Overrides:
getAndPutInternal
in classSimpleCacheImpl<K,V>
-
getAndReplaceInternal
protected V getAndReplaceInternal(K key, V value, Metadata metadata)
- Overrides:
getAndReplaceInternal
in classSimpleCacheImpl<K,V>
-
putForExternalReadInternal
protected void putForExternalReadInternal(K key, V value, Metadata metadata, org.infinispan.commons.util.ByRef.Boolean isCreatedRef)
- Overrides:
putForExternalReadInternal
in classSimpleCacheImpl<K,V>
-
putIfAbsentInternal
protected V putIfAbsentInternal(K key, V value, Metadata metadata)
- Overrides:
putIfAbsentInternal
in classSimpleCacheImpl<K,V>
-
remove
public V remove(Object key)
Description copied from interface:org.infinispan.commons.api.BasicCache
If the return value of this operation will be ignored by the application, the user is strongly encouraged to use theFlag.IGNORE_RETURN_VALUES
flag when invoking this method in order to make it behave as efficiently as possible (i.e. avoiding needless remote or network calls).
-
replaceInternal
protected boolean replaceInternal(K key, V oldValue, V value, Metadata metadata)
- Overrides:
replaceInternal
in classSimpleCacheImpl<K,V>
-
computeIfAbsentInternal
protected V computeIfAbsentInternal(K key, Function<? super K,? extends V> mappingFunction, org.infinispan.commons.util.ByRef<V> newValueRef)
- Overrides:
computeIfAbsentInternal
in classSimpleCacheImpl<K,V>
-
computeIfPresentInternal
protected V computeIfPresentInternal(K key, BiFunction<? super K,? super V,? extends V> remappingFunction, SimpleCacheImpl.CacheEntryChange<K,V> ref)
- Overrides:
computeIfPresentInternal
in classSimpleCacheImpl<K,V>
-
computeInternal
protected V computeInternal(K key, BiFunction<? super K,? super V,? extends V> remappingFunction, SimpleCacheImpl.CacheEntryChange<K,V> ref)
- Overrides:
computeInternal
in classSimpleCacheImpl<K,V>
-
mergeInternal
protected V mergeInternal(K key, V value, BiFunction<? super V,? super V,? extends V> remappingFunction, SimpleCacheImpl.CacheEntryChange<K,V> ref, Metadata metadata)
- Overrides:
mergeInternal
in classSimpleCacheImpl<K,V>
-
toString
public String toString()
- Overrides:
toString
in classSimpleCacheImpl<K,V>
-
-