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()
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.
|
String |
toString() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
disabledStatsCounter, guardedStatsCounter
public ConcurrentStatsCounter()
public void recordHits(int count)
StatsCounter
recordHits
in interface StatsCounter
count
- the number of hits to recordpublic void recordMisses(int count)
StatsCounter
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.recordMisses
in interface StatsCounter
count
- the number of misses to recordpublic void recordLoadSuccess(long loadTime)
StatsCounter
Cache.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 StatsCounter
loadTime
- the number of nanoseconds the cache spent computing or retrieving the new valuepublic void recordLoadFailure(long loadTime)
StatsCounter
Cache.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 StatsCounter
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 thrownpublic void recordEviction()
StatsCounter
invalidations
.recordEviction
in interface StatsCounter
public void recordEviction(int weight)
StatsCounter
invalidations
.recordEviction
in interface StatsCounter
weight
- the weight of the evicted entrypublic CacheStats snapshot()
StatsCounter
snapshot
in interface StatsCounter
public void incrementBy(@NonNull StatsCounter other)
other
.other
- the counter to increment from