Interface StatsCounter

  • All Known Implementing Classes:
    ConcurrentStatsCounter

    public interface StatsCounter
    Accumulates statistics during the operation of a Cache for presentation by Cache.stats(). This is solely intended for consumption by Cache implementors.
    • Method Detail

      • recordHits

        void recordHits​(@org.checkerframework.checker.index.qual.NonNegative int count)
        Records cache hits. This should be called when a cache request returns a cached value.
        Parameters:
        count - the number of hits to record
      • recordMisses

        void recordMisses​(@org.checkerframework.checker.index.qual.NonNegative int count)
        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.
        Parameters:
        count - the number of misses to record
      • recordEviction

        void recordEviction​(@org.checkerframework.checker.index.qual.NonNegative int weight,
                            RemovalCause cause)
        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.
        Parameters:
        weight - the weight of the evicted entry
        cause - the reason for which the entry was removed
      • snapshot

        CacheStats snapshot()
        Returns a snapshot of this counter's values. Note that this may be an inconsistent view, as it may be interleaved with update operations.

        Note: the values of the metrics are undefined in case of overflow (though it is guaranteed not to throw an exception). If you require specific handling, we recommend implementing your own stats collector.

        Returns:
        a snapshot of this counter's values
      • disabledStatsCounter

        static StatsCounter disabledStatsCounter()
        Returns an accumulator that does not record any cache events.
        Returns:
        an accumulator that does not record metrics
      • guardedStatsCounter

        static StatsCounter guardedStatsCounter​(StatsCounter statsCounter)
        Returns an accumulator that suppresses and logs any exception thrown by the delegate statsCounter.
        Parameters:
        statsCounter - the accumulator to delegate to
        Returns:
        an accumulator that suppresses and logs any exception thrown by the delegate