public final class ConcurrentStatsCounter extends Object implements StatsCounter
StatsCounter implementation for use by Cache implementors.| Constructor and Description |
|---|
ConcurrentStatsCounter()
Constructs an instance with all counts initialized to zero.
|
| Modifier and Type | Method and Description |
|---|---|
void |
incrementBy(@NonNull StatsCounter other)
Increments all counters by the values in
other. |
void |
recordEviction()
Deprecated.
|
void |
recordEviction(int weight)
Deprecated.
|
void |
recordEviction(int weight,
RemovalCause cause)
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.
|
String |
toString() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitdisabledStatsCounter, guardedStatsCounterpublic ConcurrentStatsCounter()
public void recordHits(int count)
StatsCounterrecordHits in interface StatsCountercount - the number of hits to recordpublic void recordMisses(int count)
StatsCounterCache 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.recordMisses in interface StatsCountercount - the number of misses to recordpublic void recordLoadSuccess(long loadTime)
StatsCounterCache.get(K, java.util.function.Function<? super K, ? extends V>) or Map.computeIfAbsent(K, java.util.function.Function<? super K, ? extends V>)) and
the loading completes successfully. In contrast to StatsCounter.recordMisses(int), this method should
only be called by the loading thread.recordLoadSuccess in interface StatsCounterloadTime - the number of nanoseconds the cache spent computing or retrieving the new valuepublic void recordLoadFailure(long loadTime)
StatsCounterCache.get(K, java.util.function.Function<? super K, ? extends V>) or Map.computeIfAbsent(K, java.util.function.Function<? super K, ? extends V>)), but
an exception is thrown while loading the entry or the loading function returns null. In
contrast to StatsCounter.recordMisses(int), this method should only be called by the loading thread.recordLoadFailure in interface StatsCounterloadTime - 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@Deprecated public void recordEviction()
StatsCounterinvalidations.recordEviction in interface StatsCounter@Deprecated public void recordEviction(int weight)
StatsCounterinvalidations.recordEviction in interface StatsCounterweight - the weight of the evicted entrypublic void recordEviction(int weight,
RemovalCause cause)
StatsCounterinvalidations.recordEviction in interface StatsCounterweight - the weight of the evicted entrycause - the reason for which the entry was removedpublic CacheStats snapshot()
StatsCounterNote: 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.
snapshot in interface StatsCounterpublic void incrementBy(@NonNull StatsCounter other)
other.other - the counter to increment from