ehcache

net.sf.ehcache.statistics.sampled
Class SampledCacheStatisticsImpl

java.lang.Object
  extended by net.sf.ehcache.statistics.sampled.SampledCacheStatisticsImpl
All Implemented Interfaces:
CacheUsageListener, SampledCacheStatistics

public class SampledCacheStatisticsImpl
extends java.lang.Object
implements CacheUsageListener, SampledCacheStatistics

An implementation of SampledCacheStatistics This also implements CacheUsageListener and depends on the notification received from these to update the stats

Since:
1.7
Author:
Abhishek Sanoujam

Constructor Summary
SampledCacheStatisticsImpl(FailSafeTimer timer)
          Constructor that accepts a timer which will be used to schedule the sampled counters
 
Method Summary
 void clearStatistics()
          Clears the collected statistics.
 java.lang.Object clone()
          
 void dispose()
          Called to dispose off the listener
 long getAverageGetTimeMostRecentSample()
          Get most recent value for average time taken for get() operation in the cache
 long getCacheElementEvictedMostRecentSample()
          Get most recent value element evicted from cache
 long getCacheElementExpiredMostRecentSample()
          Get most recent value element expired from cache
 long getCacheElementPutMostRecentSample()
          Get most recent value element puts in the cache
 long getCacheElementRemovedMostRecentSample()
          Get most recent value element removed from cache
 long getCacheElementUpdatedMostRecentSample()
          Get most recent value element updates , i.e.
 long getCacheHitInMemoryMostRecentSample()
          Get most recent value for in-memory cache hit
 long getCacheHitMostRecentSample()
          Get most recent value for cache hit
 long getCacheHitOnDiskMostRecentSample()
          Get most recent value for on-disk cache hit
 long getCacheMissExpiredMostRecentSample()
          Get most recent value for cache miss as result of the element getting expired
 long getCacheMissMostRecentSample()
          Get most recent value for cache miss
 long getCacheMissNotFoundMostRecentSample()
          Get most recent value for cache miss as result of the element not found in cache
 int getStatisticsAccuracy()
          Get value for statisticsAccuracy
 java.lang.String getStatisticsAccuracyDescription()
          Get Description for statisticsAccuracy
 boolean isSampledStatisticsEnabled()
          Returns true if statistics collection is enabled for cache, otherwise false
 void notifyCacheElementEvicted()
          Called when an element is expired in the cache
 void notifyCacheElementExpired()
          Called when an element in the cache expires
 void notifyCacheElementPut()
          Called when an element is inserted in the cache
 void notifyCacheElementRemoved()
          Called when an element is removed from the cache
 void notifyCacheElementUpdated()
          Called when an element is updated in the cache, i.e.
 void notifyCacheHitInMemory()
          Called on a cache hit in the MemoryStore
 void notifyCacheHitOnDisk()
          Called on a cache hit in the DiskStore
 void notifyCacheMissedWithExpired()
          Called when an element is found in the cache but already expired
 void notifyCacheMissedWithNotFound()
          Called when an element is not found in the cache
 void notifyRemoveAll()
          Called when Cache.removeAll() is called
 void notifyStatisticsAccuracyChanged(int statisticsAccuracyValue)
          Notified when the statistics accuracy is changed.
 void notifyStatisticsCleared()
          Called when statistics is cleared
 void notifyStatisticsEnabledChanged(boolean enableStatistics)
          Called when statistics is enabled/disabled
 void notifyTimeTakenForGet(long millis)
          Notified with time taken for a get operation in the cache
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SampledCacheStatisticsImpl

public SampledCacheStatisticsImpl(FailSafeTimer timer)
Constructor that accepts a timer which will be used to schedule the sampled counters

Method Detail

clearStatistics

public void clearStatistics()
Clears the collected statistics. Resets all counters to zero

Specified by:
clearStatistics in interface SampledCacheStatistics

notifyCacheElementEvicted

public void notifyCacheElementEvicted()
Called when an element is expired in the cache

Specified by:
notifyCacheElementEvicted in interface CacheUsageListener

notifyCacheHitInMemory

public void notifyCacheHitInMemory()
Called on a cache hit in the MemoryStore

Specified by:
notifyCacheHitInMemory in interface CacheUsageListener

notifyCacheHitOnDisk

public void notifyCacheHitOnDisk()
Called on a cache hit in the DiskStore

Specified by:
notifyCacheHitOnDisk in interface CacheUsageListener

notifyCacheMissedWithExpired

public void notifyCacheMissedWithExpired()
Called when an element is found in the cache but already expired

Specified by:
notifyCacheMissedWithExpired in interface CacheUsageListener

notifyCacheMissedWithNotFound

public void notifyCacheMissedWithNotFound()
Called when an element is not found in the cache

Specified by:
notifyCacheMissedWithNotFound in interface CacheUsageListener

dispose

public void dispose()
Called to dispose off the listener

Specified by:
dispose in interface CacheUsageListener
Specified by:
dispose in interface SampledCacheStatistics

notifyCacheElementExpired

public void notifyCacheElementExpired()
Called when an element in the cache expires

Specified by:
notifyCacheElementExpired in interface CacheUsageListener

notifyCacheElementPut

public void notifyCacheElementPut()
                           throws CacheException
Called when an element is inserted in the cache

Specified by:
notifyCacheElementPut in interface CacheUsageListener
Throws:
CacheException

notifyCacheElementRemoved

public void notifyCacheElementRemoved()
                               throws CacheException
Called when an element is removed from the cache

Specified by:
notifyCacheElementRemoved in interface CacheUsageListener
Throws:
CacheException

notifyCacheElementUpdated

public void notifyCacheElementUpdated()
                               throws CacheException
Called when an element is updated in the cache, i.e. a put for an already existing key

Specified by:
notifyCacheElementUpdated in interface CacheUsageListener
Throws:
CacheException

notifyTimeTakenForGet

public void notifyTimeTakenForGet(long millis)
Notified with time taken for a get operation in the cache

Specified by:
notifyTimeTakenForGet in interface CacheUsageListener

notifyRemoveAll

public void notifyRemoveAll()
Called when Cache.removeAll() is called

Specified by:
notifyRemoveAll in interface CacheUsageListener

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException

Overrides:
clone in class java.lang.Object
Throws:
java.lang.CloneNotSupportedException

notifyStatisticsEnabledChanged

public void notifyStatisticsEnabledChanged(boolean enableStatistics)
Called when statistics is enabled/disabled

Specified by:
notifyStatisticsEnabledChanged in interface CacheUsageListener

notifyStatisticsAccuracyChanged

public void notifyStatisticsAccuracyChanged(int statisticsAccuracyValue)
Notified when the statistics accuracy is changed.

Specified by:
notifyStatisticsAccuracyChanged in interface CacheUsageListener
Parameters:
statisticsAccuracyValue - one of Statistics#STATISTICS_ACCURACY_BEST_EFFORT, Statistics#STATISTICS_ACCURACY_GUARANTEED, Statistics#STATISTICS_ACCURACY_NONE

notifyStatisticsCleared

public void notifyStatisticsCleared()
Called when statistics is cleared

Specified by:
notifyStatisticsCleared in interface CacheUsageListener

getCacheHitMostRecentSample

public long getCacheHitMostRecentSample()
Get most recent value for cache hit

Specified by:
getCacheHitMostRecentSample in interface SampledCacheStatistics
Returns:
Most recent sample for cache hit count

getAverageGetTimeMostRecentSample

public long getAverageGetTimeMostRecentSample()
Get most recent value for average time taken for get() operation in the cache

Specified by:
getAverageGetTimeMostRecentSample in interface SampledCacheStatistics
Returns:
Most recent sample of average get time taken for a get operation

getCacheElementEvictedMostRecentSample

public long getCacheElementEvictedMostRecentSample()
Get most recent value element evicted from cache

Specified by:
getCacheElementEvictedMostRecentSample in interface SampledCacheStatistics
Returns:
Most recent sample for element evicted count

getCacheHitInMemoryMostRecentSample

public long getCacheHitInMemoryMostRecentSample()
Get most recent value for in-memory cache hit

Specified by:
getCacheHitInMemoryMostRecentSample in interface SampledCacheStatistics
Returns:
Most recent sample for cache hit count in memory

getCacheHitOnDiskMostRecentSample

public long getCacheHitOnDiskMostRecentSample()
Get most recent value for on-disk cache hit

Specified by:
getCacheHitOnDiskMostRecentSample in interface SampledCacheStatistics
Returns:
Most recent sample for cache hit count on disk

getCacheMissExpiredMostRecentSample

public long getCacheMissExpiredMostRecentSample()
Get most recent value for cache miss as result of the element getting expired

Specified by:
getCacheMissExpiredMostRecentSample in interface SampledCacheStatistics
Returns:
Most recent sample for cache miss count and the reason for miss being the element got expired

getCacheMissMostRecentSample

public long getCacheMissMostRecentSample()
Get most recent value for cache miss

Specified by:
getCacheMissMostRecentSample in interface SampledCacheStatistics
Returns:
Most recent sample for cache miss count

getCacheMissNotFoundMostRecentSample

public long getCacheMissNotFoundMostRecentSample()
Get most recent value for cache miss as result of the element not found in cache

Specified by:
getCacheMissNotFoundMostRecentSample in interface SampledCacheStatistics
Returns:
Most recent sample for cache miss not found count

getCacheElementExpiredMostRecentSample

public long getCacheElementExpiredMostRecentSample()
Get most recent value element expired from cache

Specified by:
getCacheElementExpiredMostRecentSample in interface SampledCacheStatistics
Returns:
Most recent value for element expired count

getCacheElementPutMostRecentSample

public long getCacheElementPutMostRecentSample()
Get most recent value element puts in the cache

Specified by:
getCacheElementPutMostRecentSample in interface SampledCacheStatistics
Returns:
Most recent sample for number of element puts

getCacheElementRemovedMostRecentSample

public long getCacheElementRemovedMostRecentSample()
Get most recent value element removed from cache

Specified by:
getCacheElementRemovedMostRecentSample in interface SampledCacheStatistics
Returns:
Most recent sample for element removed count

getCacheElementUpdatedMostRecentSample

public long getCacheElementUpdatedMostRecentSample()
Get most recent value element updates , i.e. put() on elements with already existing keys in the cache

Specified by:
getCacheElementUpdatedMostRecentSample in interface SampledCacheStatistics
Returns:
Most recent sampled value for element update count

getStatisticsAccuracy

public int getStatisticsAccuracy()
Get value for statisticsAccuracy

Specified by:
getStatisticsAccuracy in interface SampledCacheStatistics
Returns:
one of Statistics#STATISTICS_ACCURACY_BEST_EFFORT, Statistics#STATISTICS_ACCURACY_GUARANTEED, Statistics#STATISTICS_ACCURACY_NONE

getStatisticsAccuracyDescription

public java.lang.String getStatisticsAccuracyDescription()
Get Description for statisticsAccuracy

Specified by:
getStatisticsAccuracyDescription in interface SampledCacheStatistics

isSampledStatisticsEnabled

public boolean isSampledStatisticsEnabled()
Returns true if statistics collection is enabled for cache, otherwise false

Specified by:
isSampledStatisticsEnabled in interface SampledCacheStatistics
Returns:
true if sampled statistics is enabled, false otherwise

ehcache

true