ehcache

net.sf.ehcache.statistics
Class NullLiveCacheStatisticsData

java.lang.Object
  extended by net.sf.ehcache.statistics.NullLiveCacheStatisticsData
All Implemented Interfaces:
Cloneable, CacheEventListener, LiveCacheStatistics, LiveCacheStatisticsData

public class NullLiveCacheStatisticsData
extends Object
implements LiveCacheStatistics, LiveCacheStatisticsData

A no-op implementation which can be used both as a LiveCacheStatistics and LiveCacheStatisticsData

Since:
1.7
Author:
Abhishek Sanoujam

Constructor Summary
NullLiveCacheStatisticsData()
           
 
Method Summary
 void addGetTimeMillis(long millis)
          Adds time taken for a get operation in the cache
 void cacheHitInMemory()
          Called on a cache hit in the MemoryStore
 void cacheHitOffHeap()
          Called on a cache hit in the off-heap
 void cacheHitOnDisk()
          Called on a cache hit in the DiskStore
 void cacheMissExpired()
          Called when an element is found in the cache but already expired
 void cacheMissInMemory()
          Called on a cache miss in the MemoryStore
 void cacheMissNotFound()
          Called when an element is not found in the cache
 void cacheMissOffHeap()
          Called on a cache miss in the off-heap
 void cacheMissOnDisk()
          Called on a cache miss in the DiskStore
 void clearStatistics()
          Clears statistics of this cache
 Object clone()
          Creates a clone of this listener.
 void dispose()
          Give the listener a chance to cleanup and free resources when no longer needed
 float getAverageGetTimeMillis()
          Average time in milli seconds taken to get an element from the cache.
 long getCacheHitCount()
          The number of times a requested item was found in the cache.
 long getCacheMissCount()
          Number of times a requested element was not found in the cache.
 long getCacheMissCountExpired()
          
 String getCacheName()
          
 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 getInMemoryMissCount()
          Number of times a requested item was not found in the Memory Store.
 long getInMemorySize()
          Deprecated. see getLocalHeapSize()
 long getLocalDiskSize()
          Number of entries in the DiskStore
 long getLocalDiskSizeInBytes()
          Number of of bytes used by entries in the DiskStore
 long getLocalHeapSize()
          Number of entries in the MemoryStore
 long getLocalHeapSizeInBytes()
          Number of of bytes used by entries in the MemoryStore
 long getLocalOffHeapSize()
          Number of entries in the off-heap store
 long getLocalOffHeapSizeInBytes()
          Number of of bytes used by entries in the off-heap store
 long getMaxGetTimeMillis()
          Return maximum time taken for a get operation in the cache in milliseconds
 long getMinGetTimeMillis()
          Return minimum time taken for a get operation in the cache in milliseconds
 long getOffHeapHitCount()
          Number of times a requested item was found in the off-heap store.
 long getOffHeapMissCount()
          Number of times a requested item was not found in the off-heap store.
 long getOffHeapSize()
          Deprecated. see getLocalOffHeapSize()
 long getOnDiskHitCount()
          Number of times a requested item was found in the Disk Store.
 long getOnDiskMissCount()
          Number of times a requested item was not found in the Disk Store.
 long getOnDiskSize()
          Deprecated. see getLocalDiskSize()
 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.
 String getStatisticsAccuracyDescription()
          Accurately measuring statistics can be expensive.
 long getUpdateCount()
          Number of updates that as happened in the cache
 long getWriterQueueLength()
          Gets the size of the write-behind queue, if any.
 long getXaCommitCount()
          Return the Cache's XAResource commit calls count
 long getXaRollbackCount()
          Return the Cache's XAResource rollback calls count
 boolean isStatisticsEnabled()
          Returns true if statistics is enabled
 void notifyElementEvicted(Ehcache cache, Element element)
          Called immediately after an element is evicted from the cache.
 void notifyElementExpired(Ehcache cache, Element element)
          Called immediately after an element is found to be expired.
 void notifyElementPut(Ehcache cache, Element element)
          Called immediately after an element has been put into the cache.
 void notifyElementRemoved(Ehcache cache, Element element)
          Called immediately after an attempt to remove an element.
 void notifyElementUpdated(Ehcache cache, Element element)
          Called immediately after an element has been put into the cache and the element already existed in the cache.
 void notifyRemoveAll(Ehcache cache)
          Called during Ehcache.removeAll() to indicate that the all elements have been removed from the cache in a bulk operation.
 void registerCacheUsageListener(CacheUsageListener cacheUsageListener)
          Registers a CacheUsageListener which will be notified of the cache usage.
 void removeCacheUsageListener(CacheUsageListener cacheUsageListener)
          Remove an already registered CacheUsageListener, if any.
 void setStatisticsAccuracy(int statisticsAccuracy)
          Sets the statistics accuracy.
 void setStatisticsEnabled(boolean enableStatistics)
          Enabled/Disabled statistics
 void xaCommit()
          Called when the Cache's XAResource has been asked to commit
 void xaRollback()
          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

NullLiveCacheStatisticsData

public NullLiveCacheStatisticsData()
Method Detail

getCacheName

public String getCacheName()

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

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

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

getCacheMissCount

public long getCacheMissCount()
Number of times a requested element was not found in the cache.

Specified by:
getCacheMissCount in interface LiveCacheStatistics
Returns:
the number of times a requested element was not found in the cache

getInMemoryMissCount

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

Specified by:
getInMemoryMissCount in interface LiveCacheStatistics
Returns:
the number of times a requested item was not found in memory

getOffHeapMissCount

public long getOffHeapMissCount()
Number of times a requested item was not found in the off-heap store.

Specified by:
getOffHeapMissCount in interface LiveCacheStatistics
Returns:
the number of times a requested item was not found in off-heap

getOnDiskMissCount

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

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

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

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

getExpiredCount

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

Specified by:
getExpiredCount in interface LiveCacheStatistics
Returns:
Number of expired elements

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

getInMemorySize

@Deprecated
public long getInMemorySize()
Deprecated. see getLocalHeapSize()

Number of elements in the MemoryStore

Specified by:
getInMemorySize in interface LiveCacheStatistics
Returns:
the number of elements in memory

getOffHeapHitCount

public long getOffHeapHitCount()
Number of times a requested item was found in the off-heap store.

Specified by:
getOffHeapHitCount in interface LiveCacheStatistics
Returns:
the number of times a requested item was found in off-heap

getOffHeapSize

@Deprecated
public long getOffHeapSize()
Deprecated. see getLocalOffHeapSize()

Number of elements in the off-heap store

Specified by:
getOffHeapSize in interface LiveCacheStatistics
Returns:
the number of elements in off-heap

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.

getOnDiskSize

@Deprecated
public long getOnDiskSize()
Deprecated. see getLocalDiskSize()

Number of elements in the DiskStore

Specified by:
getOnDiskSize in interface LiveCacheStatistics
Returns:
number of elements on disk

getLocalHeapSize

public long getLocalHeapSize()
Number of entries in the MemoryStore

Specified by:
getLocalHeapSize in interface LiveCacheStatistics
Returns:
the number of elements in memory

getLocalOffHeapSize

public long getLocalOffHeapSize()
Number of entries in the off-heap store

Specified by:
getLocalOffHeapSize in interface LiveCacheStatistics
Returns:
the number of elements in off-heap

getLocalDiskSize

public long getLocalDiskSize()
Number of entries in the DiskStore

Specified by:
getLocalDiskSize in interface LiveCacheStatistics
Returns:
number of elements on disk

getLocalHeapSizeInBytes

public long getLocalHeapSizeInBytes()
Number of of bytes used by entries in the MemoryStore

Specified by:
getLocalHeapSizeInBytes in interface LiveCacheStatistics
Returns:
the number of of bytes used by elements in memory

getLocalOffHeapSizeInBytes

public long getLocalOffHeapSizeInBytes()
Number of of bytes used by entries in the off-heap store

Specified by:
getLocalOffHeapSizeInBytes in interface LiveCacheStatistics
Returns:
the number of of bytes used by elements in off-heap

getLocalDiskSizeInBytes

public long getLocalDiskSizeInBytes()
Number of of bytes used by entries in the DiskStore

Specified by:
getLocalDiskSizeInBytes in interface LiveCacheStatistics
Returns:
number of bytes used by elements on disk

getPutCount

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

Specified by:
getPutCount in interface LiveCacheStatistics
Returns:
Number of puts

getRemovedCount

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

Specified by:
getRemovedCount in interface LiveCacheStatistics
Returns:
Number of elements removed

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 current accuracy setting

getStatisticsAccuracy

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

Specified by:
getStatisticsAccuracy in interface LiveCacheStatistics
Returns:
one of Statistics.STATISTICS_ACCURACY_BEST_EFFORT, Statistics.STATISTICS_ACCURACY_GUARANTEED, Statistics.STATISTICS_ACCURACY_NONE

getStatisticsAccuracyDescription

public String getStatisticsAccuracyDescription()
Accurately measuring statistics can be expensive. Returns the current accuracy setting.

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

getUpdateCount

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

Specified by:
getUpdateCount in interface LiveCacheStatistics
Returns:
Number of updates

isStatisticsEnabled

public boolean isStatisticsEnabled()
Returns true if statistics is enabled

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

addGetTimeMillis

public void addGetTimeMillis(long millis)
Adds time taken for a get operation in the cache

Specified by:
addGetTimeMillis in interface LiveCacheStatisticsData

cacheHitInMemory

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

Specified by:
cacheHitInMemory in interface LiveCacheStatisticsData

cacheHitOffHeap

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

Specified by:
cacheHitOffHeap in interface LiveCacheStatisticsData

cacheHitOnDisk

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

Specified by:
cacheHitOnDisk in interface LiveCacheStatisticsData

cacheMissExpired

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

Specified by:
cacheMissExpired in interface LiveCacheStatisticsData

xaCommit

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

Specified by:
xaCommit in interface LiveCacheStatisticsData

xaRollback

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

Specified by:
xaRollback in interface LiveCacheStatisticsData

cacheMissNotFound

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

Specified by:
cacheMissNotFound in interface LiveCacheStatisticsData

cacheMissInMemory

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

Specified by:
cacheMissInMemory in interface LiveCacheStatisticsData

cacheMissOffHeap

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

Specified by:
cacheMissOffHeap in interface LiveCacheStatisticsData

cacheMissOnDisk

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

Specified by:
cacheMissOnDisk in interface LiveCacheStatisticsData

clearStatistics

public void clearStatistics()
Clears statistics of this cache

Specified by:
clearStatistics in interface LiveCacheStatistics
Specified by:
clearStatistics in interface LiveCacheStatisticsData

registerCacheUsageListener

public void registerCacheUsageListener(CacheUsageListener cacheUsageListener)
                                throws IllegalStateException
Registers a CacheUsageListener which will be notified of the cache usage. Implementations of CacheUsageListener should override the Object.equals(Object) and Object.hashCode() methods as it is used for equality check

Specified by:
registerCacheUsageListener in interface LiveCacheStatisticsData
Throws:
IllegalStateException

removeCacheUsageListener

public void removeCacheUsageListener(CacheUsageListener cacheUsageListener)
                              throws IllegalStateException
Remove an already registered CacheUsageListener, if any. Depends on the Object.equals(Object) method.

Specified by:
removeCacheUsageListener in interface LiveCacheStatisticsData
Throws:
IllegalStateException

setStatisticsAccuracy

public void setStatisticsAccuracy(int statisticsAccuracy)
Sets the statistics accuracy.

Specified by:
setStatisticsAccuracy in interface LiveCacheStatisticsData
Parameters:
statisticsAccuracy - one of Statistics#STATISTICS_ACCURACY_BEST_EFFORT, Statistics#STATISTICS_ACCURACY_GUARANTEED, Statistics#STATISTICS_ACCURACY_NONE

setStatisticsEnabled

public void setStatisticsEnabled(boolean enableStatistics)
Enabled/Disabled statistics

Specified by:
setStatisticsEnabled in interface LiveCacheStatisticsData

dispose

public void dispose()
Give the listener a chance to cleanup and free resources when no longer needed

Specified by:
dispose in interface CacheEventListener

notifyElementEvicted

public void notifyElementEvicted(Ehcache cache,
                                 Element element)
Called immediately after an element is evicted from the cache. Evicted in this sense means evicted from one store and not moved to another, so that it exists nowhere in the local cache.

In a sense the Element has been removed from the cache, but it is different, thus the separate notification.

Specified by:
notifyElementEvicted in interface CacheEventListener
Parameters:
cache - the cache emitting the notification
element - the element that has just been evicted

notifyElementExpired

public void notifyElementExpired(Ehcache cache,
                                 Element element)
Called immediately after an element is found to be expired. The Cache.remove(Object) method will block until this method returns.

As the Element has been expired, only what was the key of the element is known.

Elements are checked for expiry in ehcache at the following times:

If an element is found to be expired, it is deleted and this method is notified.

Specified by:
notifyElementExpired in interface CacheEventListener
Parameters:
cache - the cache emitting the notification
element - the element that has just expired

Deadlock Warning: expiry will often come from the DiskStore expiry thread. It holds a lock to the DiskStorea the time the notification is sent. If the implementation of this method calls into a synchronized Cache method and that subsequently calls into DiskStore a deadlock will result. Accordingly implementers of this method should not call back into Cache.


notifyElementPut

public void notifyElementPut(Ehcache cache,
                             Element element)
                      throws CacheException
Called immediately after an element has been put into the cache. The Cache.put(net.sf.ehcache.Element) method will block until this method returns.

Implementers may wish to have access to the Element's fields, including value, so the element is provided. Implementers should be careful not to modify the element. The effect of any modifications is undefined.

Specified by:
notifyElementPut in interface CacheEventListener
Parameters:
cache - the cache emitting the notification
element - the element which was just put into the cache.
Throws:
CacheException

notifyElementRemoved

public void notifyElementRemoved(Ehcache cache,
                                 Element element)
                          throws CacheException
Called immediately after an attempt to remove an element. The remove method will block until this method returns.

This notification is received regardless of whether the cache had an element matching the removal key or not. If an element was removed, the element is passed to this method, otherwise a synthetic element, with only the key set is passed in.

This notification is not called for the following special cases:

  1. removeAll was called. See CacheEventListener.notifyRemoveAll(net.sf.ehcache.Ehcache)
  2. An element was evicted from the cache. See CacheEventListener.notifyElementEvicted(net.sf.ehcache.Ehcache, net.sf.ehcache.Element)

Specified by:
notifyElementRemoved in interface CacheEventListener
Parameters:
cache - the cache emitting the notification
element - the element just deleted, or a synthetic element with just the key set if no element was removed.
Throws:
CacheException

notifyElementUpdated

public void notifyElementUpdated(Ehcache cache,
                                 Element element)
                          throws CacheException
Called immediately after an element has been put into the cache and the element already existed in the cache. This is thus an update.

The Cache.put(net.sf.ehcache.Element) method will block until this method returns.

Implementers may wish to have access to the Element's fields, including value, so the element is provided. Implementers should be careful not to modify the element. The effect of any modifications is undefined.

Specified by:
notifyElementUpdated in interface CacheEventListener
Parameters:
cache - the cache emitting the notification
element - the element which was just put into the cache.
Throws:
CacheException

notifyRemoveAll

public void notifyRemoveAll(Ehcache cache)
Called during Ehcache.removeAll() to indicate that the all elements have been removed from the cache in a bulk operation. The usual CacheEventListener.notifyElementRemoved(net.sf.ehcache.Ehcache, net.sf.ehcache.Element) is not called.

This notification exists because clearing a cache is a special case. It is often not practical to serially process notifications where potentially millions of elements have been bulk deleted.

Specified by:
notifyRemoveAll in interface CacheEventListener
Parameters:
cache - the cache emitting the notification

clone

public Object clone()
             throws CloneNotSupportedException
Creates a clone of this listener. This method will only be called by ehcache before a cache is initialized.

This may not be possible for listeners after they have been initialized. Implementations should throw CloneNotSupportedException if they do not support clone.

Specified by:
clone in interface CacheEventListener
Overrides:
clone in class Object
Returns:
a clone
Throws:
CloneNotSupportedException - if the listener could not be cloned.

getMaxGetTimeMillis

public long getMaxGetTimeMillis()
Return maximum time taken for a get operation in the cache in milliseconds

Specified by:
getMaxGetTimeMillis in interface LiveCacheStatistics
Returns:
maximum time taken for a get operation in the cache in milliseconds

getWriterQueueLength

public long getWriterQueueLength()
Gets the size of the write-behind queue, if any. The value is for all local buckets but returns 0, always!

Specified by:
getWriterQueueLength in interface LiveCacheStatistics
Returns:
Elements waiting to be processed by the write-behind writer. -1 if no write-behind

getXaCommitCount

public long getXaCommitCount()
Return the Cache's XAResource commit calls count

Specified by:
getXaCommitCount in interface LiveCacheStatistics
Returns:
the Cache's XAResource commit calls count

getXaRollbackCount

public long getXaRollbackCount()
Return the Cache's XAResource rollback calls count

Specified by:
getXaRollbackCount in interface LiveCacheStatistics
Returns:
the Cache's XAResource rollback calls count

getMinGetTimeMillis

public long getMinGetTimeMillis()
Return minimum time taken for a get operation in the cache in milliseconds

Specified by:
getMinGetTimeMillis in interface LiveCacheStatistics
Returns:
minimum time taken for a get operation in the cache in milliseconds

ehcache

Copyright © 2003-2012 Terracotta, Inc.. All Rights Reserved.