ehcache

net.sf.ehcache.statistics
Class LiveCacheStatisticsWrapper

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

public class LiveCacheStatisticsWrapper
extends Object
implements LiveCacheStatistics, LiveCacheStatisticsData

An implementation of LiveCacheStatistics and also implements LiveCacheStatisticsData. Uses separate delegates depending on whether statistics is enabled or not.

To collect statistics element put/update/remove/expired data, instances of this class must be registered as a CacheEventListener to a Cache

Since:
1.7
Author:
Abhishek Sanoujam

Constructor Summary
LiveCacheStatisticsWrapper(Ehcache cache)
          Constructor accepting the backing cache.
 
Method Summary
 void addGetTimeMillis(long millis)
          Adds time taken for a get operation in the cache
 void addGetTimeNanos(long nanos)
          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 milliseconds taken to get an element from the cache.
 long getAverageGetTimeNanos()
          Average time in nanoseconds taken to get an element from the cache.
 long getCacheHitCount()
          The number of times a requested item was found in the cache.
 int getCacheHitRatio()
          The ratio of hits to accesses (hits + misses).
 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()
          Returns the usage of local disks in bytes
 long getLocalHeapSize()
          Number of entries in the MemoryStore
 long getLocalHeapSizeInBytes()
          Returns the usage of local heap in bytes
 long getLocalOffHeapSize()
          Number of entries in the off-heap store
 long getLocalOffHeapSizeInBytes()
          Returns the usage of local off heap in bytes
 long getMaxGetTimeMillis()
          Deprecated.  
 long getMaxGetTimeNanos()
          Return maximum time taken for a get operation in the cache in milliseconds
 long getMinGetTimeMillis()
          Deprecated.  
 long getMinGetTimeNanos()
          Return minimum time taken for a get operation in the cache in nanoseconds
 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 getXaRecoveredCount()
          Return the Cache's XAResource recovered XIDs 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 xaRecovered(int count)
          Called when the Cache's XAResource has recovered one or more XID
 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

LiveCacheStatisticsWrapper

public LiveCacheStatisticsWrapper(Ehcache cache)
Constructor accepting the backing cache.

Parameters:
cache -
Method Detail

setStatisticsEnabled

public void setStatisticsEnabled(boolean enableStatistics)
Enabled/Disabled statistics

Specified by:
setStatisticsEnabled in interface LiveCacheStatisticsData
See Also:
LiveCacheStatisticsData.setStatisticsEnabled(boolean)

isStatisticsEnabled

public boolean isStatisticsEnabled()
Returns true if statistics is enabled

Specified by:
isStatisticsEnabled in interface LiveCacheStatistics
Returns:
true if statistics is enabled
See Also:
LiveCacheStatistics.isStatisticsEnabled()

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
See Also:
LiveCacheStatisticsData.registerCacheUsageListener(net.sf.ehcache.statistics.CacheUsageListener)

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
See Also:
LiveCacheStatisticsData.removeCacheUsageListener(net.sf.ehcache.statistics.CacheUsageListener)

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
See Also:
LiveCacheStatisticsData.setStatisticsAccuracy(int)

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
See Also:
LiveCacheStatistics.getStatisticsAccuracy()

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".
See Also:
LiveCacheStatistics.getStatisticsAccuracyDescription()

getCacheName

public String getCacheName()

Specified by:
getCacheName in interface LiveCacheStatistics
Returns:
the name of the Ehcache
See Also:
LiveCacheStatistics.getCacheName()

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
See Also:
LiveCacheStatistics.getSize()

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
See Also:
LiveCacheStatistics.getInMemorySize()

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
See Also:
LiveCacheStatistics.getOffHeapSize()

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
See Also:
LiveCacheStatistics.getOnDiskSize()

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()
Returns the usage of local heap in bytes

Specified by:
getLocalHeapSizeInBytes in interface LiveCacheStatistics
Returns:
memory usage in bytes

getLocalOffHeapSizeInBytes

public long getLocalOffHeapSizeInBytes()
Returns the usage of local off heap in bytes

Specified by:
getLocalOffHeapSizeInBytes in interface LiveCacheStatistics
Returns:
memory usage in bytes

getLocalDiskSizeInBytes

public long getLocalDiskSizeInBytes()
Returns the usage of local disks in bytes

Specified by:
getLocalDiskSizeInBytes in interface LiveCacheStatistics
Returns:
memory usage in bytes

getAverageGetTimeMillis

public float getAverageGetTimeMillis()
Average time in milliseconds 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()

getAverageGetTimeNanos

public long getAverageGetTimeNanos()
Average time in nanoseconds taken to get an element from the cache.

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

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()
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
See Also:
LiveCacheStatistics.getCacheMissCount()

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
See Also:
LiveCacheStatistics.getInMemoryMissCount()

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
See Also:
LiveCacheStatistics.getOffHeapMissCount()

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.
See Also:
LiveCacheStatistics.getOnDiskMissCount()

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

getCacheHitRatio

public int getCacheHitRatio()
The ratio of hits to accesses (hits + misses).

Specified by:
getCacheHitRatio in interface LiveCacheStatistics
Returns:
the ratio of hits to (hits + misses) (0 - 100)
See Also:
LiveCacheStatistics.getCacheHitRatio()

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

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
See Also:
LiveCacheStatistics.getOffHeapHitCount()

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

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

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

addGetTimeMillis

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

Specified by:
addGetTimeMillis in interface LiveCacheStatisticsData
See Also:
LiveCacheStatisticsData.addGetTimeMillis(long)

addGetTimeNanos

public void addGetTimeNanos(long nanos)
Adds time taken for a get operation in the cache

Specified by:
addGetTimeNanos in interface LiveCacheStatisticsData
See Also:
LiveCacheStatisticsData.addGetTimeNanos(long)

getMaxGetTimeMillis

@Deprecated
public long getMaxGetTimeMillis()
Deprecated. 

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
See Also:
LiveCacheStatistics.getMaxGetTimeMillis()

getMinGetTimeMillis

@Deprecated
public long getMinGetTimeMillis()
Deprecated. 

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
See Also:
LiveCacheStatistics.getMinGetTimeMillis()

getMaxGetTimeNanos

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

Specified by:
getMaxGetTimeNanos in interface LiveCacheStatistics
Returns:
maximum time taken for a get operation in the cache in milliseconds
See Also:
LiveCacheStatistics.getMaxGetTimeNanos()

getMinGetTimeNanos

public long getMinGetTimeNanos()
Return minimum time taken for a get operation in the cache in nanoseconds

Specified by:
getMinGetTimeNanos in interface LiveCacheStatistics
Returns:
minimum time taken for a get operation in the cache in nanoseconds
See Also:
LiveCacheStatistics.getMinGetTimeNanos()

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
See Also:
LiveCacheStatistics.getXaCommitCount()

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
See Also:
LiveCacheStatistics.getXaRollbackCount()

getXaRecoveredCount

public long getXaRecoveredCount()
Return the Cache's XAResource recovered XIDs count

Specified by:
getXaRecoveredCount in interface LiveCacheStatistics
Returns:
the Cache's XAResource recovered XIDs count
See Also:
LiveCacheStatistics.getXaRecoveredCount()

getWriterQueueLength

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

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

cacheHitInMemory

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

Specified by:
cacheHitInMemory in interface LiveCacheStatisticsData
See Also:
LiveCacheStatisticsData.cacheHitInMemory()

cacheHitOffHeap

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

Specified by:
cacheHitOffHeap in interface LiveCacheStatisticsData
See Also:
LiveCacheStatisticsData.cacheHitOffHeap()

cacheHitOnDisk

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

Specified by:
cacheHitOnDisk in interface LiveCacheStatisticsData
See Also:
LiveCacheStatisticsData.cacheHitOnDisk()

cacheMissExpired

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

Specified by:
cacheMissExpired in interface LiveCacheStatisticsData
See Also:
LiveCacheStatisticsData.cacheMissExpired()

xaCommit

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

Specified by:
xaCommit in interface LiveCacheStatisticsData
See Also:
LiveCacheStatisticsData.xaCommit()

xaRollback

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

Specified by:
xaRollback in interface LiveCacheStatisticsData
See Also:
LiveCacheStatisticsData.xaRollback()

xaRecovered

public void xaRecovered(int count)
Called when the Cache's XAResource has recovered one or more XID

Specified by:
xaRecovered in interface LiveCacheStatisticsData
See Also:
LiveCacheStatisticsData.xaRecovered(int)

cacheMissNotFound

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

Specified by:
cacheMissNotFound in interface LiveCacheStatisticsData
See Also:
LiveCacheStatisticsData.cacheMissNotFound()

cacheMissInMemory

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

Specified by:
cacheMissInMemory in interface LiveCacheStatisticsData
See Also:
LiveCacheStatisticsData.cacheMissNotFound()

cacheMissOffHeap

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

Specified by:
cacheMissOffHeap in interface LiveCacheStatisticsData
See Also:
LiveCacheStatisticsData.cacheMissNotFound()

cacheMissOnDisk

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

Specified by:
cacheMissOnDisk in interface LiveCacheStatisticsData
See Also:
LiveCacheStatisticsData.cacheMissNotFound()

clearStatistics

public void clearStatistics()
Clears statistics of this cache

Specified by:
clearStatistics in interface LiveCacheStatistics
Specified by:
clearStatistics in interface LiveCacheStatisticsData
See Also:
LiveCacheStatisticsData.clearStatistics()

dispose

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

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

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
See Also:
CacheEventListener.notifyElementEvicted(net.sf.ehcache.Ehcache, net.sf.ehcache.Element)

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.

See Also:
CacheEventListener.notifyElementExpired(net.sf.ehcache.Ehcache, net.sf.ehcache.Element)

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
See Also:
CacheEventListener.notifyElementPut(net.sf.ehcache.Ehcache, net.sf.ehcache.Element)

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
See Also:
CacheEventListener.notifyElementRemoved(net.sf.ehcache.Ehcache, net.sf.ehcache.Element)

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
See Also:
CacheEventListener.notifyElementUpdated(net.sf.ehcache.Ehcache, net.sf.ehcache.Element)

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
See Also:
CacheEventListener.notifyRemoveAll(net.sf.ehcache.Ehcache)

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.
See Also:
Object.clone()

ehcache

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