ehcache

net.sf.ehcache.event
Interface CacheEventListener

All Known Subinterfaces:
CacheReplicator
All Known Implementing Classes:
RMIAsynchronousCacheReplicator, RMISynchronousCacheReplicator

public interface CacheEventListener

Allows implementers to register callback methods that will be executed when a cache event occurs. The events include:

  1. put Element
  2. update Element
  3. remove Element
  4. an Element expires, either because timeToLive or timeToIdle has been reached.

Callbacks to these methods are synchronous and unsynchronized. It is the responsibility of the implementer to safely handle the potential performance and thread safety issues depending on what their listener is doing.

Events are guaranteed to be notified in the order in which they occurred.

Cache also has putQuiet and removeQuiet methods which do not notify listeners.

Since:
1.2
Version:
$Id: CacheEventListener.java 28 2006-04-15 05:12:32Z gregluck $
Author:
Greg Luck
See Also:
CacheManagerEventListener

Method Summary
 void dispose()
          Give the replicator a chance to cleanup and free resources when no longer needed
 void notifyElementExpired(Cache cache, Element element)
          Called immediately after an element is found to be expired.
 void notifyElementPut(Cache cache, Element element)
          Called immediately after an element has been put into the cache.
 void notifyElementRemoved(Cache cache, Element element)
          Called immediately after an element has been removed.
 void notifyElementUpdated(Cache cache, Element element)
          Called immediately after an element has been put into the cache and the element already existed in the cache.
 

Method Detail

notifyElementRemoved

void notifyElementRemoved(Cache cache,
                          Element element)
                          throws CacheException
Called immediately after an element has been removed. The remove method will block until this method returns.

Ehcache does not chech for

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

Parameters:
cache - the cache emitting the notification
element - just deleted
Throws:
CacheException

notifyElementPut

void notifyElementPut(Cache 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.

Parameters:
cache - the cache emitting the notification
element - the element which was just put into the cache.
Throws:
CacheException

notifyElementUpdated

void notifyElementUpdated(Cache 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.

Parameters:
cache - the cache emitting the notification
element - the element which was just put into the cache.
Throws:
CacheException

notifyElementExpired

void notifyElementExpired(Cache 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.

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.


dispose

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


ehcache