A thread-safe StatsCounter implementation for use by Cache implementors. @since 10.0
| 222 | |
| 223 | |
| 224 | public static final class SimpleStatsCounter implements StatsCounter { |
| 225 | private final LongAddable hitCount = LongAddables.create(); |
| 226 | private final LongAddable missCount = LongAddables.create(); |
| 227 | private final LongAddable loadSuccessCount = LongAddables.create(); |
| 228 | private final LongAddable loadExceptionCount = LongAddables.create(); |
| 229 | private final LongAddable totalLoadTime = LongAddables.create(); |
| 230 | private final LongAddable evictionCount = LongAddables.create(); |
| 231 | |
| 232 | /** |
| 233 | * Constructs an instance with all counts initialized to zero. |
| 234 | */ |
| 235 | |
| 236 | |
| 237 | public SimpleStatsCounter() {} |
| 238 | |
| 239 | /** |
| 240 | * @since 11.0 |
| 241 | */ |
| 242 | |
| 243 | @Override |
| 244 | public void recordHits(int count) { |
| 245 | hitCount.add(count); |
| 246 | } |
| 247 | |
| 248 | /** |
| 249 | * @since 11.0 |
| 250 | */ |
| 251 | |
| 252 | @Override |
| 253 | public void recordMisses(int count) { |
| 254 | missCount.add(count); |
| 255 | } |
| 256 | |
| 257 | @Override |
| 258 | public void recordLoadSuccess(long loadTime) { |
| 259 | loadSuccessCount.increment(); |
| 260 | totalLoadTime.add(loadTime); |
| 261 | } |
| 262 | |
| 263 | @Override |
| 264 | public void recordLoadException(long loadTime) { |
| 265 | loadExceptionCount.increment(); |
| 266 | totalLoadTime.add(loadTime); |
| 267 | } |
| 268 | |
| 269 | @Override |
| 270 | public void recordEviction() { |
| 271 | evictionCount.increment(); |
| 272 | } |
| 273 | |
| 274 | @Override |
| 275 | public CacheStats snapshot() { |
| 276 | return new CacheStats( |
| 277 | hitCount.sum(), |
| 278 | missCount.sum(), |
| 279 | loadSuccessCount.sum(), |
| 280 | loadExceptionCount.sum(), |
| 281 | totalLoadTime.sum(), |