StagemonitorCacheUsageListener implements CacheUsageListener { @Override public void notifyGetTimeNanos(long nanos) { if (timeGet) { registry.timer(getMetricName).update(nanos, TimeUnit.NANOSECONDS); } else { registry.meter(getMetricName).mark(); } } StagemonitorCacheUsageListener(String cacheName, Metric2Registry registry, boolean timeGet); @Override void notifyStatisticsEnabledChanged(boolean enableStatistics); @Override void notifyStatisticsCleared(); @Override void notifyCacheHitInMemory(); @Override void notifyCacheHitOffHeap(); @Override void notifyCacheHitOnDisk(); @Override void notifyCacheElementPut(); @Override void notifyCacheElementUpdated(); @Override void notifyCacheMissedWithNotFound(); @Override void notifyCacheMissedWithExpired(); Ratio getHitRatio1Min(); @Override void notifyCacheMissInMemory(); @Override void notifyCacheMissOffHeap(); @Override void notifyCacheMissOnDisk(); @Override @Deprecated void notifyTimeTakenForGet(long millis); @Override void notifyGetTimeNanos(long nanos); @Override void notifyCacheElementEvicted(); @Override void notifyCacheElementExpired(); @Override void notifyCacheElementRemoved(); @Override void notifyRemoveAll(); @Override void notifyStatisticsAccuracyChanged(int statisticsAccuracy); @Override void dispose(); @Override void notifyCacheSearch(long executeTime); @Override void notifyXaCommit(); @Override void notifyXaRollback();  }
@Test public void testGet() { cacheUsageListener.notifyGetTimeNanos(1); assertNotNull(registry.getTimers().get(name("cache_get").tag("cache_name", "cache").tier("All").build())); }
@Test public void testGetMeter() { cacheUsageListener = new StagemonitorCacheUsageListener("cache", registry, false); cacheUsageListener.notifyGetTimeNanos(1); final MetricName name = name("cache_get").tag("cache_name", "cache").tier("All").build(); assertNull(registry.getTimers().get(name)); assertNotNull(registry.getMeters().get(name)); }