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>, AsyncCache<K,V>, BasicCache<K,V>, BatchingCache, Lifecycle, TransactionalCache, FilteringListenable<K,V>, Listenable

public class StatsCollectingCache<K,V> extends SimpleCacheImpl<K,V>
Wraps existing AdvancedCache to collect statistics
Author:
Radim Vansa <rvansa@redhat.com>
  • Constructor Details

    • StatsCollectingCache

      public StatsCollectingCache(String cacheName)
  • Method Details

    • 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 should also consider saving the decorated cache, as this allows for more readable code. E.g.:

          AdvancedCache<?, ?> forceWriteLockCache = cache.withFlags(Flag.FORCE_WRITE_LOCK);
          forceWriteLockCache.get(key1);
          forceWriteLockCache.get(key2);
          forceWriteLockCache.get(key3);
       
      Specified by:
      withFlags in interface AdvancedCache<K,V>
      Overrides:
      withFlags in class SimpleCacheImpl<K,V>
      Parameters:
      flags - a set of flags to apply. See the Flag 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)
      Specified by:
      with in interface AdvancedCache<K,V>
      Overrides:
      with in class SimpleCacheImpl<K,V>
    • getStats

      public Stats getStats()
      Description copied from interface: AdvancedCache
      Returns a Stats object that allows several statistics associated with this cache at runtime.
      Specified by:
      getStats in interface AdvancedCache<K,V>
      Overrides:
      getStats in class SimpleCacheImpl<K,V>
      Returns:
      this cache's Stats object
    • get

      public V get(Object key)
      Specified by:
      get in interface Map<K,V>
      Overrides:
      get in class SimpleCacheImpl<K,V>
    • 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 interface AdvancedCache<K,V>
      Overrides:
      getCacheEntry in class SimpleCacheImpl<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 as Map 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 interface AdvancedCache<K,V>
      Overrides:
      getAll in class SimpleCacheImpl<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 the AdvancedCache, returning them as Map 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 interface AdvancedCache<K,V>
      Overrides:
      getAllCacheEntries in class SimpleCacheImpl<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 of Map.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). Use BasicCache.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.

      Specified by:
      evict in interface Cache<K,V>
      Overrides:
      evict in class SimpleCacheImpl<K,V>
      Parameters:
      key - key to evict
    • getAndPutInternal

      protected V getAndPutInternal(K key, V value, Metadata metadata)
      Overrides:
      getAndPutInternal in class SimpleCacheImpl<K,V>
    • getAndReplaceInternal

      protected V getAndReplaceInternal(K key, V value, Metadata metadata)
      Overrides:
      getAndReplaceInternal in class SimpleCacheImpl<K,V>
    • putForExternalReadInternal

      protected void putForExternalReadInternal(K key, V value, Metadata metadata, ByRef.Boolean isCreatedRef)
      Overrides:
      putForExternalReadInternal in class SimpleCacheImpl<K,V>
    • putIfAbsentInternal

      protected V putIfAbsentInternal(K key, V value, Metadata metadata)
      Overrides:
      putIfAbsentInternal in class SimpleCacheImpl<K,V>
    • remove

      public V remove(Object key)
      Description copied from interface: BasicCache
      If the return value of this operation will be ignored by the application, the user is strongly encouraged to use the Flag.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).
      Specified by:
      remove in interface BasicCache<K,V>
      Specified by:
      remove in interface Map<K,V>
      Overrides:
      remove in class SimpleCacheImpl<K,V>
    • remove

      public boolean remove(Object key, Object value)
      Specified by:
      remove in interface ConcurrentMap<K,V>
      Specified by:
      remove in interface Map<K,V>
      Overrides:
      remove in class SimpleCacheImpl<K,V>
    • replaceInternal

      protected boolean replaceInternal(K key, V oldValue, V value, Metadata metadata)
      Overrides:
      replaceInternal in class SimpleCacheImpl<K,V>
    • computeIfAbsentInternal

      protected V computeIfAbsentInternal(K key, Function<? super K,? extends V> mappingFunction, ByRef<V> newValueRef)
      Overrides:
      computeIfAbsentInternal in class SimpleCacheImpl<K,V>
    • computeIfPresentInternal

      protected V computeIfPresentInternal(K key, BiFunction<? super K,? super V,? extends V> remappingFunction, SimpleCacheImpl.CacheEntryChange<K,V> ref)
      Overrides:
      computeIfPresentInternal in class SimpleCacheImpl<K,V>
    • computeInternal

      protected V computeInternal(K key, BiFunction<? super K,? super V,? extends V> remappingFunction, SimpleCacheImpl.CacheEntryChange<K,V> ref)
      Overrides:
      computeInternal in class SimpleCacheImpl<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 class SimpleCacheImpl<K,V>
    • toString

      public String toString()
      Overrides:
      toString in class SimpleCacheImpl<K,V>