freemarker.template.cache
Class CacheEventAdapter

java.lang.Object
  extended by freemarker.template.cache.CacheEventAdapter

public class CacheEventAdapter
extends java.lang.Object

Adapter class responsible for firing cache events. Four different cache events are supported:

Version:
$Id: CacheEventAdapter.java 1153 2013-04-15 10:59:37Z run2000 $
Author:
Nicholas Cull
See Also:
CacheEvent, CacheListener

Field Summary
protected  GenericEventMulticaster<CacheListener> multicaster
          Holds any event listeners wanting to receive cache events.
protected  ListenerAdapter<CacheEvent,CacheListener> removedAdapter
          A ListenerAdapter for elementRemoved events.
protected  ListenerAdapter<CacheEvent,CacheListener> unavailableAdapter
          A ListenerAdapter for cacheUnavailable events.
protected  ListenerAdapter<CacheEvent,CacheListener> updatedAdapter
          A ListenerAdapter for elementUpdated events.
protected  ListenerAdapter<CacheEvent,CacheListener> updateFailedAdapter
          A ListenerAdapter for elementUpdateFailed events.
 
Constructor Summary
CacheEventAdapter()
          Creates new CacheEventAdapter.
 
Method Summary
 void addCacheListener(CacheListener listener)
          Registers a CacheListener for a Cache.
protected  void fireCacheEvent(Cache source, ListenerAdapter adapter, java.lang.String elementName, java.lang.Exception e)
          A convenience method for firing a CacheEvent.
protected  void fireCacheEvent(Cache source, ListenerAdapter adapter, java.lang.String elementName, long lastModified)
          A convenience method for firing a CacheEvent.
 void fireCacheUnavailable(Cache source, java.lang.Exception e)
          Fires a cacheUnavailable event to all registered listeners.
 void fireElementRemoved(Cache source, java.lang.String elementName)
          Fires an elementRemoved event to all registered listeners.
 void fireElementUpdated(Cache source, java.lang.String elementName, long lastModified)
          Fires an elementUpdated event to all registered listeners.
 void fireElementUpdateFailed(Cache source, java.lang.String elementName, java.lang.Exception e)
          Fires an elementUpdateFailed event to all registered listeners.
 CacheListener[] getCacheListeners()
          Retrieves all the listeners associated with this Cache.
 void removeCacheListener(CacheListener listener)
          Unregisters a CacheListener for a Cache.
 java.lang.String toString()
          Returns a string representation of the object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

multicaster

protected final GenericEventMulticaster<CacheListener> multicaster
Holds any event listeners wanting to receive cache events.


unavailableAdapter

protected ListenerAdapter<CacheEvent,CacheListener> unavailableAdapter
A ListenerAdapter for cacheUnavailable events.


updatedAdapter

protected ListenerAdapter<CacheEvent,CacheListener> updatedAdapter
A ListenerAdapter for elementUpdated events.


updateFailedAdapter

protected ListenerAdapter<CacheEvent,CacheListener> updateFailedAdapter
A ListenerAdapter for elementUpdateFailed events.


removedAdapter

protected ListenerAdapter<CacheEvent,CacheListener> removedAdapter
A ListenerAdapter for elementRemoved events.

Constructor Detail

CacheEventAdapter

public CacheEventAdapter()
Creates new CacheEventAdapter.

Method Detail

fireCacheUnavailable

public void fireCacheUnavailable(Cache source,
                                 java.lang.Exception e)
Fires a cacheUnavailable event to all registered listeners.

Parameters:
source - the source of the event
e - the Exception that caused the event to be fired

fireElementUpdated

public void fireElementUpdated(Cache source,
                               java.lang.String elementName,
                               long lastModified)
Fires an elementUpdated event to all registered listeners.

Parameters:
source - the source of the event
elementName - the cache element that was updated
lastModified - the last modification time of the cache element

fireElementUpdateFailed

public void fireElementUpdateFailed(Cache source,
                                    java.lang.String elementName,
                                    java.lang.Exception e)
Fires an elementUpdateFailed event to all registered listeners.

Parameters:
source - the source of the event
elementName - the cache element that failed to be updated
e - the Exception that caused the event to be fired

fireElementRemoved

public void fireElementRemoved(Cache source,
                               java.lang.String elementName)
Fires an elementRemoved event to all registered listeners.

Parameters:
source - the source of the event
elementName - the cache element that was updated

fireCacheEvent

protected void fireCacheEvent(Cache source,
                              ListenerAdapter adapter,
                              java.lang.String elementName,
                              java.lang.Exception e)
A convenience method for firing a CacheEvent.

Parameters:
source - the source of the event
adapter - a ListenerAdapter.
elementName - the name of the cache element in question, or null.
e - an Exception to be included with the event, or null.

fireCacheEvent

protected void fireCacheEvent(Cache source,
                              ListenerAdapter adapter,
                              java.lang.String elementName,
                              long lastModified)
A convenience method for firing a CacheEvent.

Parameters:
source - the source of the event
adapter - a ListenerAdapter.
elementName - the name of the cache element in question, or null.
lastModified - the time that the element was last modified

addCacheListener

public void addCacheListener(CacheListener listener)
Registers a CacheListener for a Cache.

Parameters:
listener - the CacheListener to be registered.

removeCacheListener

public void removeCacheListener(CacheListener listener)
Unregisters a CacheListener for a Cache.

Parameters:
listener - the CacheListener to be unregistered.

getCacheListeners

public CacheListener[] getCacheListeners()
Retrieves all the listeners associated with this Cache.

Returns:
an array of CacheListeners

toString

public java.lang.String toString()
Returns a string representation of the object.

Overrides:
toString in class java.lang.Object
Returns:
a String representation of the object