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