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 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.
 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 getAverageSearchTime()
          Get the average search execution time for searches finishing within the last sample period
 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 getCacheHitOffHeapMostRecentSample()
          Get most recent value for off-heap 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 getCacheMissInMemoryMostRecentSample()
          Get most recent value for in-memory cache miss
 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
 long getCacheMissOffHeapMostRecentSample()
          Get most recent value for off-heap cache miss
 long getCacheMissOnDiskMostRecentSample()
          Get most recent value for on-disk cache miss
 long getCacheXaCommitsMostRecentSample()
          Get most recent value of XA commits
 long getCacheXaRollbacksMostRecentSample()
          Get most recent value of XA rollbacks
 long getSearchesPerSecond()
          Get the number of searches that have finished execution in the last second
 int getStatisticsAccuracy()
          Get value for statisticsAccuracy
 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 notifyCacheHitOffHeap()
          Called on a cache hit in the off-heap store
 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 notifyCacheMissInMemory()
          Called on a cache miss in the MemoryStore
 void notifyCacheMissOffHeap()
          Called on a cache miss in the off-heap store
 void notifyCacheMissOnDisk()
          Called on a cache miss in the DiskStore
 void notifyCacheSearch(long executeTime)
          Called when a search finishes execution
 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
 void notifyXaCommit()
          Called when the Cache's XAResource has been asked to commit
 void notifyXaRollback()
          Called when the Cache's XAResource has been asked to rollback
 
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

notifyCacheHitOffHeap

public void notifyCacheHitOffHeap()
Called on a cache hit in the off-heap store

Specified by:
notifyCacheHitOffHeap 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

notifyCacheMissInMemory

public void notifyCacheMissInMemory()
Called on a cache miss in the MemoryStore

Specified by:
notifyCacheMissInMemory in interface CacheUsageListener

notifyCacheMissOffHeap

public void notifyCacheMissOffHeap()
Called on a cache miss in the off-heap store

Specified by:
notifyCacheMissOffHeap in interface CacheUsageListener

notifyCacheMissOnDisk

public void notifyCacheMissOnDisk()
Called on a cache miss in the DiskStore

Specified by:
notifyCacheMissOnDisk 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 Object clone()
             throws CloneNotSupportedException

Overrides:
clone in class Object
Throws:
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

getCacheHitOffHeapMostRecentSample

public long getCacheHitOffHeapMostRecentSample()
Get most recent value for off-heap cache hit

Specified by:
getCacheHitOffHeapMostRecentSample in interface SampledCacheStatistics
Returns:
Most recent sample for cache hit count in off-heap

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

getCacheMissInMemoryMostRecentSample

public long getCacheMissInMemoryMostRecentSample()
Get most recent value for in-memory cache miss

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

getCacheMissOffHeapMostRecentSample

public long getCacheMissOffHeapMostRecentSample()
Get most recent value for off-heap cache miss

Specified by:
getCacheMissOffHeapMostRecentSample in interface SampledCacheStatistics
Returns:
Most recent sample for cache miss count in off-heap

getCacheMissOnDiskMostRecentSample

public long getCacheMissOnDiskMostRecentSample()
Get most recent value for on-disk cache miss

Specified by:
getCacheMissOnDiskMostRecentSample in interface SampledCacheStatistics
Returns:
Most recent sample for cache miss count on disk

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 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

getAverageSearchTime

public long getAverageSearchTime()
Get the average search execution time for searches finishing within the last sample period

Specified by:
getAverageSearchTime in interface SampledCacheStatistics

getSearchesPerSecond

public long getSearchesPerSecond()
Get the number of searches that have finished execution in the last second

Specified by:
getSearchesPerSecond in interface SampledCacheStatistics

notifyCacheSearch

public void notifyCacheSearch(long executeTime)
Called when a search finishes execution

Specified by:
notifyCacheSearch in interface CacheUsageListener
Parameters:
executeTime - elapsed time in millis

getCacheXaCommitsMostRecentSample

public long getCacheXaCommitsMostRecentSample()
Get most recent value of XA commits

Specified by:
getCacheXaCommitsMostRecentSample in interface SampledCacheStatistics

notifyXaCommit

public void notifyXaCommit()
Called when the Cache's XAResource has been asked to commit

Specified by:
notifyXaCommit in interface CacheUsageListener

getCacheXaRollbacksMostRecentSample

public long getCacheXaRollbacksMostRecentSample()
Get most recent value of XA rollbacks

Specified by:
getCacheXaRollbacksMostRecentSample in interface SampledCacheStatistics

notifyXaRollback

public void notifyXaRollback()
Called when the Cache's XAResource has been asked to rollback

Specified by:
notifyXaRollback in interface CacheUsageListener

ehcache

true