ehcache

net.sf.ehcache.management.sampled
Class SampledCache

java.lang.Object
  extended by net.sf.ehcache.management.sampled.SampledCache
All Implemented Interfaces:
SampledCacheMBean, LiveCacheStatistics, SampledCacheStatistics

public class SampledCache
extends java.lang.Object
implements SampledCacheMBean

An implementation of SampledCacheMBean

Since:
1.7
Author:
Abhishek Sanoujam

Constructor Summary
SampledCache(Ehcache cache)
          Constructor accepting the backing Ehcache
 
Method Summary
 void clearStatistics()
          Clear both sampled and cumulative statistics
 void disableSampledStatistics()
          Disables statistics collection
 void disableStatistics()
          Disables statistics collection.
 void dispose()
          Method used to dispose this statistics
 void enableSampledStatistics()
          Enables statistics collection.
 void enableStatistics()
          Enables statistics collection
 void flush()
          Flushes all cache items from memory to the disk store, and from the DiskStore to disk.
 float getAverageGetTimeMillis()
          Average time in milli seconds taken to get an element from the cache.
 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 getCacheHitCount()
          The number of times a requested item was found in the cache.
 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 getCacheMissCount()
          
 long getCacheMissCountExpired()
          
 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
 java.lang.String getCacheName()
          
 long getConfigDiskExpiryThreadIntervalSeconds()
          Configuration property accessor
 int getConfigMaxElementsInMemory()
          Configuration property accessor
 int getConfigMaxElementsOnDisk()
          Configuration property accessor
 java.lang.String getConfigMemoryStoreEvictionPolicy()
          Configuration property accessor
 long getConfigTimeToIdleSeconds()
          Configuration property accessor
 long getConfigTimeToLiveSeconds()
          Configuration property accessor
 long getEvictedCount()
          Number of elements evicted from the cache
 long getExpiredCount()
          Number of elements expired since creation or last clear
 long getInMemoryHitCount()
          Number of times a requested item was found in the Memory Store.
 long getInMemorySize()
          Number of elements in the MemoryStore
 long getOnDiskHitCount()
          Number of times a requested item was found in the Disk Store.
 long getOnDiskSize()
          Number of elements in the DiskStore
 long getPutCount()
          Number of puts that has happened in the cache
 long getRemovedCount()
          Number of elements removed since creation or last clear
 long getSize()
          Size of the cache based on current accuracy settings.
 int getStatisticsAccuracy()
          Accurately measuring statistics can be expensive.
 java.lang.String getStatisticsAccuracyDescription()
          Accurately measuring statistics can be expensive.
 java.lang.String getStatus()
          Gets the status attribute of the Cache.
 long getUpdateCount()
          Number of updates that as happened in the cache
 boolean isConfigDiskPersistent()
          Configuration property accessor
 boolean isConfigEternal()
          Configuration property accessor
 boolean isConfigOverflowToDisk()
          Configuration property accessor
 boolean isSampledStatisticsEnabled()
          Returns true if statistics collection is enabled for cache, otherwise false
 boolean isStatisticsEnabled()
          Returns true if statistics is enabled
 boolean isTerracottaClustered()
          Is the cache configured with Terracotta clustering?
 void removeAll()
          Removes all cached items.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SampledCache

public SampledCache(Ehcache cache)
Constructor accepting the backing Ehcache

Parameters:
cache -
Method Detail

flush

public void flush()
Flushes all cache items from memory to the disk store, and from the DiskStore to disk.

Specified by:
flush in interface SampledCacheMBean

getCacheName

public java.lang.String getCacheName()

Specified by:
getCacheName in interface LiveCacheStatistics
Returns:
the name of the Ehcache

getStatus

public java.lang.String getStatus()
Gets the status attribute of the Cache.

Specified by:
getStatus in interface SampledCacheMBean
Returns:
The status value from the Status enum class

removeAll

public void removeAll()
Removes all cached items.

Specified by:
removeAll in interface SampledCacheMBean

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

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

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

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

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

getStatisticsAccuracy

public int getStatisticsAccuracy()
Accurately measuring statistics can be expensive. Returns the current accuracy setting.

Specified by:
getStatisticsAccuracy in interface LiveCacheStatistics
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()
Accurately measuring statistics can be expensive. Returns the current accuracy setting.

Specified by:
getStatisticsAccuracyDescription in interface LiveCacheStatistics
Specified by:
getStatisticsAccuracyDescription in interface SampledCacheStatistics
Returns:
a human readable description of the accuracy setting. One of "None", "Best Effort" or "Guaranteed".

clearStatistics

public void clearStatistics()
Clear both sampled and cumulative statistics

Specified by:
clearStatistics in interface SampledCacheMBean

isStatisticsEnabled

public boolean isStatisticsEnabled()
Returns true if statistics is enabled

Specified by:
isStatisticsEnabled in interface LiveCacheStatistics
Returns:
true if statistics is enabled

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

isTerracottaClustered

public boolean isTerracottaClustered()
Is the cache configured with Terracotta clustering?

Specified by:
isTerracottaClustered in interface SampledCacheMBean
Returns:
true if clustered with terracotta

enableStatistics

public void enableStatistics()
Enables statistics collection

Specified by:
enableStatistics in interface SampledCacheMBean
See Also:
SampledCacheMBean.enableStatistics()

disableStatistics

public void disableStatistics()
Disables statistics collection. Also disables sampled statistics if it is enabled.

Specified by:
disableStatistics in interface SampledCacheMBean
See Also:
SampledCacheMBean.disableStatistics()

enableSampledStatistics

public void enableSampledStatistics()
Enables statistics collection. As it requires that normal statistics collection to be enabled, it enables it if its not already

Specified by:
enableSampledStatistics in interface SampledCacheMBean
See Also:
SampledCacheMBean.enableSampledStatistics()

disableSampledStatistics

public void disableSampledStatistics()
Disables statistics collection

Specified by:
disableSampledStatistics in interface SampledCacheMBean
See Also:
()

getAverageGetTimeMillis

public float getAverageGetTimeMillis()
Average time in milli seconds taken to get an element from the cache.

Specified by:
getAverageGetTimeMillis in interface LiveCacheStatistics
Returns:
Average time taken for a get operation in milliseconds
See Also:
LiveCacheStatistics.getAverageGetTimeMillis()

getCacheHitCount

public long getCacheHitCount()
The number of times a requested item was found in the cache.

Specified by:
getCacheHitCount in interface LiveCacheStatistics
Returns:
the number of times a requested item was found in the cache
See Also:
LiveCacheStatistics.getCacheHitCount()

getCacheMissCount

public long getCacheMissCount()

Specified by:
getCacheMissCount in interface LiveCacheStatistics
Returns:
the number of times a requested element was not found in the cache
See Also:
LiveCacheStatistics.getCacheMissCount()

getCacheMissCountExpired

public long getCacheMissCountExpired()

Specified by:
getCacheMissCountExpired in interface LiveCacheStatistics
Returns:
the number of times a requested element was not found in the cache and the reason being the element already expired
See Also:
LiveCacheStatistics.getCacheMissCountExpired()

getConfigDiskExpiryThreadIntervalSeconds

public long getConfigDiskExpiryThreadIntervalSeconds()
Configuration property accessor

Specified by:
getConfigDiskExpiryThreadIntervalSeconds in interface SampledCacheMBean
Returns:
Value for disk expiry thread interval in seconds specified in config
See Also:
SampledCacheMBean.getConfigDiskExpiryThreadIntervalSeconds()

getConfigMaxElementsInMemory

public int getConfigMaxElementsInMemory()
Configuration property accessor

Specified by:
getConfigMaxElementsInMemory in interface SampledCacheMBean
Returns:
Max elements in memory config setting value
See Also:
SampledCacheMBean.getConfigMaxElementsInMemory()

getConfigMaxElementsOnDisk

public int getConfigMaxElementsOnDisk()
Configuration property accessor

Specified by:
getConfigMaxElementsOnDisk in interface SampledCacheMBean
Returns:
Max elements on disk config setting value
See Also:
SampledCacheMBean.getConfigMaxElementsOnDisk()

getConfigMemoryStoreEvictionPolicy

public java.lang.String getConfigMemoryStoreEvictionPolicy()
Configuration property accessor

Specified by:
getConfigMemoryStoreEvictionPolicy in interface SampledCacheMBean
Returns:
a String representation of the policy
See Also:
SampledCacheMBean.getConfigMemoryStoreEvictionPolicy()

getConfigTimeToIdleSeconds

public long getConfigTimeToIdleSeconds()
Configuration property accessor

Specified by:
getConfigTimeToIdleSeconds in interface SampledCacheMBean
Returns:
TTI in config
See Also:
SampledCacheMBean.getConfigTimeToIdleSeconds()

getConfigTimeToLiveSeconds

public long getConfigTimeToLiveSeconds()
Configuration property accessor

Specified by:
getConfigTimeToLiveSeconds in interface SampledCacheMBean
Returns:
TTL in config
See Also:
SampledCacheMBean.getConfigTimeToLiveSeconds()

getEvictedCount

public long getEvictedCount()
Number of elements evicted from the cache

Specified by:
getEvictedCount in interface LiveCacheStatistics
Returns:
Number of elements evicted from the cache
See Also:
LiveCacheStatistics.getEvictedCount()

getExpiredCount

public long getExpiredCount()
Number of elements expired since creation or last clear

Specified by:
getExpiredCount in interface LiveCacheStatistics
Returns:
Number of expired elements
See Also:
LiveCacheStatistics.getExpiredCount()

getInMemoryHitCount

public long getInMemoryHitCount()
Number of times a requested item was found in the Memory Store.

Specified by:
getInMemoryHitCount in interface LiveCacheStatistics
Returns:
the number of times a requested item was found in memory
See Also:
LiveCacheStatistics.getInMemoryHitCount()

getInMemorySize

public long getInMemorySize()
Number of elements in the MemoryStore

Specified by:
getInMemorySize in interface LiveCacheStatistics
Returns:
the number of elements in memory
See Also:
LiveCacheStatistics.getInMemorySize()

getOnDiskHitCount

public long getOnDiskHitCount()
Number of times a requested item was found in the Disk Store.

Specified by:
getOnDiskHitCount in interface LiveCacheStatistics
Returns:
the number of times a requested item was found on Disk, or 0 if there is no disk storage configured.
See Also:
LiveCacheStatistics.getOnDiskHitCount()

getOnDiskSize

public long getOnDiskSize()
Number of elements in the DiskStore

Specified by:
getOnDiskSize in interface LiveCacheStatistics
Returns:
number of elements on disk
See Also:
LiveCacheStatistics.getOnDiskSize()

getPutCount

public long getPutCount()
Number of puts that has happened in the cache

Specified by:
getPutCount in interface LiveCacheStatistics
Returns:
Number of puts
See Also:
LiveCacheStatistics.getPutCount()

getRemovedCount

public long getRemovedCount()
Number of elements removed since creation or last clear

Specified by:
getRemovedCount in interface LiveCacheStatistics
Returns:
Number of elements removed
See Also:
LiveCacheStatistics.getRemovedCount()

getSize

public long getSize()
Size of the cache based on current accuracy settings.

Specified by:
getSize in interface LiveCacheStatistics
Returns:
The size of the cache based on currect accuracy setting
See Also:
LiveCacheStatistics.getSize()

getUpdateCount

public long getUpdateCount()
Number of updates that as happened in the cache

Specified by:
getUpdateCount in interface LiveCacheStatistics
Returns:
Number of updates
See Also:
LiveCacheStatistics.getUpdateCount()

isConfigDiskPersistent

public boolean isConfigDiskPersistent()
Configuration property accessor

Specified by:
isConfigDiskPersistent in interface SampledCacheMBean
Returns:
true if configured with disk persistence
See Also:
SampledCacheMBean.isConfigDiskPersistent()

isConfigEternal

public boolean isConfigEternal()
Configuration property accessor

Specified by:
isConfigEternal in interface SampledCacheMBean
Returns:
true if set to eternal in config
See Also:
SampledCacheMBean.isConfigEternal()

isConfigOverflowToDisk

public boolean isConfigOverflowToDisk()
Configuration property accessor

Specified by:
isConfigOverflowToDisk in interface SampledCacheMBean
Returns:
true if overflow to disk specified in config
See Also:
SampledCacheMBean.isConfigOverflowToDisk()

dispose

public void dispose()
Method used to dispose this statistics

Specified by:
dispose in interface SampledCacheStatistics
See Also:
SampledCacheStatistics.dispose()

ehcache

true