Class GuardedStatsCounter

  • All Implemented Interfaces:
    StatsCounter

    final class GuardedStatsCounter
    extends java.lang.Object
    implements StatsCounter
    A StatsCounter implementation that suppresses and logs any exception thrown by the delegate statsCounter.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) StatsCounter delegate  
      (package private) static java.util.logging.Logger logger  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void recordEviction()
      Records the eviction of an entry from the cache.
      void recordEviction​(int weight)
      Records the eviction of an entry from the cache.
      void recordHits​(int count)
      Records cache hits.
      void recordLoadFailure​(long loadTime)
      Records the failed load of a new entry.
      void recordLoadSuccess​(long loadTime)
      Records the successful load of a new entry.
      void recordMisses​(int count)
      Records cache misses.
      CacheStats snapshot()
      Returns a snapshot of this counter's values.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • logger

        static final java.util.logging.Logger logger
    • Constructor Detail

      • GuardedStatsCounter

        GuardedStatsCounter​(StatsCounter delegate)
    • Method Detail

      • recordHits

        public void recordHits​(int count)
        Description copied from interface: StatsCounter
        Records cache hits. This should be called when a cache request returns a cached value.
        Specified by:
        recordHits in interface StatsCounter
        Parameters:
        count - the number of hits to record
      • recordMisses

        public void recordMisses​(int count)
        Description copied from interface: StatsCounter
        Records cache misses. This should be called when a cache request returns a value that was not found in the cache. This method should be called by the loading thread, as well as by threads blocking on the load. Multiple concurrent calls to Cache lookup methods with the same key on an absent value should result in a single call to either recordLoadSuccess or recordLoadFailure and multiple calls to this method, despite all being served by the results of a single load operation.
        Specified by:
        recordMisses in interface StatsCounter
        Parameters:
        count - the number of misses to record
      • recordLoadSuccess

        public void recordLoadSuccess​(long loadTime)
        Description copied from interface: StatsCounter
        Records the successful load of a new entry. This should be called when a cache request causes an entry to be loaded, and the loading completes successfully. In contrast to StatsCounter.recordMisses(int), this method should only be called by the loading thread.
        Specified by:
        recordLoadSuccess in interface StatsCounter
        Parameters:
        loadTime - the number of nanoseconds the cache spent computing or retrieving the new value
      • recordLoadFailure

        public void recordLoadFailure​(long loadTime)
        Description copied from interface: StatsCounter
        Records the failed load of a new entry. This should be called when a cache request causes an entry to be loaded, but either no value is found or an exception is thrown while loading the entry. In contrast to StatsCounter.recordMisses(int), this method should only be called by the loading thread.
        Specified by:
        recordLoadFailure in interface StatsCounter
        Parameters:
        loadTime - the number of nanoseconds the cache spent computing or retrieving the new value prior to discovering the value doesn't exist or an exception being thrown
      • recordEviction

        public void recordEviction()
        Description copied from interface: StatsCounter
        Records the eviction of an entry from the cache. This should only been called when an entry is evicted due to the cache's eviction strategy, and not as a result of manual invalidations.
        Specified by:
        recordEviction in interface StatsCounter
      • recordEviction

        public void recordEviction​(int weight)
        Description copied from interface: StatsCounter
        Records the eviction of an entry from the cache. This should only been called when an entry is evicted due to the cache's eviction strategy, and not as a result of manual invalidations.
        Specified by:
        recordEviction in interface StatsCounter
        Parameters:
        weight - the weight of the evicted entry
      • snapshot

        public CacheStats snapshot()
        Description copied from interface: StatsCounter
        Returns a snapshot of this counter's values. Note that this may be an inconsistent view, as it may be interleaved with update operations.
        Specified by:
        snapshot in interface StatsCounter
        Returns:
        a snapshot of this counter's values
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object