Top Description Fields Constructors Methods
net.sf.ehcache.event

public Class TerracottaCacheEventReplication

extends Object
implements CacheEventListener
Class Inheritance
All Implemented Interfaces
net.sf.ehcache.event.CacheEventListener, java.lang.Cloneable
Imports
java.util.concurrent.ConcurrentHashMap, .ConcurrentMap, net.sf.ehcache.CacheException, .Ehcache, .Element

Creates a wrapper for sending out cache events through the Terracotta cluster
Author
Geert Bevin
Version
$Id: TerracottaCacheEventReplication.java 5594 2012-05-07 16:04:31Z cdennis $

Field Summary

Modifier and TypeField and Description
private final ConcurrentMap<Ehcache, CacheEventListener>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public TerracottaCacheEventReplication
clone()

Overrides java.lang.Object.clone.

Implements net.sf.ehcache.event.CacheEventListener.clone.

Creates a clone of this listener.
private CacheEventListener
public void
dispose()

Implements net.sf.ehcache.event.CacheEventListener.dispose.

Give the listener a chance to cleanup and free resources when no longer needed
public void
notifyElementEvicted(Ehcache
the cache emitting the notification
cache
,
Element
the element that has just been evicted
element
)

Implements net.sf.ehcache.event.CacheEventListener.notifyElementEvicted.

Called immediately after an element is evicted from the cache.
public void
notifyElementExpired(Ehcache
the cache emitting the notification
cache
,
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.

element
)

Implements net.sf.ehcache.event.CacheEventListener.notifyElementExpired.

Called immediately after an element is found to be expired.
public void
notifyElementPut(Ehcache
the cache emitting the notification
cache
,
Element
the element which was just put into the cache.
element
)

Implements net.sf.ehcache.event.CacheEventListener.notifyElementPut.

Called immediately after an element has been put into the cache.
public void
notifyElementRemoved(Ehcache
the cache emitting the notification
cache
,
Element
the element just deleted, or a synthetic element with just the key set if no element was removed.
element
)

Implements net.sf.ehcache.event.CacheEventListener.notifyElementRemoved.

Called immediately after an attempt to remove an element.
public void
notifyElementUpdated(Ehcache
the cache emitting the notification
cache
,
Element
the element which was just put into the cache.
element
)

Implements net.sf.ehcache.event.CacheEventListener.notifyElementUpdated.

Called immediately after an element has been put into the cache and the element already existed in the cache.
public void
notifyRemoveAll(Ehcache
the cache emitting the notification
cache
)

Implements net.sf.ehcache.event.CacheEventListener.notifyRemoveAll.

Called during net.sf.ehcache.Ehcache#removeAll() to indicate that the all elements have been removed from the cache in a bulk operation.
Inherited from java.lang.Object:
equalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

replicatorsback to summary
private final ConcurrentMap<Ehcache, CacheEventListener> replicators

Constructor Detail

TerracottaCacheEventReplicationback to summary
public TerracottaCacheEventReplication()

Method Detail

cloneback to summary
public TerracottaCacheEventReplication clone() throws CloneNotSupportedException

Overrides java.lang.Object.clone.

Implements net.sf.ehcache.event.CacheEventListener.clone.

Doc from net.sf.ehcache.event.CacheEventListener.clone.

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.

Returns:TerracottaCacheEventReplication

a clone

Annotations
@Override
Exceptions
CloneNotSupportedException:
if the listener could not be cloned.
createCacheEventReplicatorback to summary
private CacheEventListener createCacheEventReplicator(Ehcache cache)
disposeback to summary
public void dispose()

Implements net.sf.ehcache.event.CacheEventListener.dispose.

Doc from net.sf.ehcache.event.CacheEventListener.dispose.

Give the listener a chance to cleanup and free resources when no longer needed

notifyElementEvictedback to summary
public void notifyElementEvicted(Ehcache cache, Element element)

Implements net.sf.ehcache.event.CacheEventListener.notifyElementEvicted.

Doc from net.sf.ehcache.event.CacheEventListener.notifyElementEvicted.

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.

Parameters
cache:Ehcache

the cache emitting the notification

element:Element

the element that has just been evicted

notifyElementExpiredback to summary
public void notifyElementExpired(Ehcache cache, Element element)

Implements net.sf.ehcache.event.CacheEventListener.notifyElementExpired.

Doc from net.sf.ehcache.event.CacheEventListener.notifyElementExpired.

Called immediately after an element is found to be expired. The net.sf.ehcache.Cache#remove(Object) method will block until this method returns.

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

the cache emitting the notification

element: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.

notifyElementPutback to summary
public void notifyElementPut(Ehcache cache, Element element) throws CacheException

Implements net.sf.ehcache.event.CacheEventListener.notifyElementPut.

Doc from net.sf.ehcache.event.CacheEventListener.notifyElementPut.

Called immediately after an element has been put into the cache. The net.sf.ehcache.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:Ehcache

the cache emitting the notification

element:Element

the element which was just put into the cache.

notifyElementRemovedback to summary
public void notifyElementRemoved(Ehcache cache, Element element) throws CacheException

Implements net.sf.ehcache.event.CacheEventListener.notifyElementRemoved.

Doc from net.sf.ehcache.event.CacheEventListener.notifyElementRemoved.

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 notifyRemoveAll(net.sf.ehcache.Ehcache)
  2. An element was evicted from the cache. See notifyElementEvicted(net.sf.ehcache.Ehcache, net.sf.ehcache.Element)
Parameters
cache:Ehcache

the cache emitting the notification

element:Element

the element just deleted, or a synthetic element with just the key set if no element was removed.

notifyElementUpdatedback to summary
public void notifyElementUpdated(Ehcache cache, Element element) throws CacheException

Implements net.sf.ehcache.event.CacheEventListener.notifyElementUpdated.

Doc from net.sf.ehcache.event.CacheEventListener.notifyElementUpdated.

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 net.sf.ehcache.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:Ehcache

the cache emitting the notification

element:Element

the element which was just put into the cache.

notifyRemoveAllback to summary
public void notifyRemoveAll(Ehcache cache)

Implements net.sf.ehcache.event.CacheEventListener.notifyRemoveAll.

Doc from net.sf.ehcache.event.CacheEventListener.notifyRemoveAll.

Called during net.sf.ehcache.Ehcache#removeAll() to indicate that the all elements have been removed from the cache in a bulk operation. The usual 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.

Parameters
cache:Ehcache

the cache emitting the notification