Class CacheManagerEventListenerRegistry
- java.lang.Object
-
- net.sf.ehcache.event.CacheManagerEventListenerRegistry
-
- All Implemented Interfaces:
CacheManagerEventListener
public class CacheManagerEventListenerRegistry extends java.lang.Object implements CacheManagerEventListener
Registered listeners for registering and unregistering CacheManagerEventListeners and sending notifications to registrants.There is one of these per CacheManager. It is a composite listener.
- Since:
- 1.3
- Version:
- $Id$
- Author:
- Greg Luck
-
-
Constructor Summary
Constructors Constructor Description CacheManagerEventListenerRegistry()Construct a new registry
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddispose()Tell listeners to dispose themselves.java.util.SetgetRegisteredListeners()Gets a Set of the listeners registered to this classStatusgetStatus()Returns the listener status.booleanhasRegisteredListeners()Returns whether or not at least one cache manager event listeners has been registered.voidinit()Initialises the listeners, ready to receive events.voidnotifyCacheAdded(java.lang.String cacheName)Called immediately after a cache has been added and activated.voidnotifyCacheRemoved(java.lang.String cacheName)Called immediately after a cache has been disposed and removed.booleanregisterListener(CacheManagerEventListener cacheManagerEventListener)Adds a listener to the notification service.java.lang.StringtoString()Returns a string representation of the object.booleanunregisterListener(CacheManagerEventListener cacheManagerEventListener)Removes a listener from the notification service.
-
-
-
Method Detail
-
registerListener
public final boolean registerListener(CacheManagerEventListener cacheManagerEventListener)
Adds a listener to the notification service. No guarantee is made that listeners will be notified in the order they were added.- Parameters:
cacheManagerEventListener- the listener to add. Can be null, in which case nothing happens- Returns:
- true if the listener is being added and was not already added
-
unregisterListener
public final boolean unregisterListener(CacheManagerEventListener cacheManagerEventListener)
Removes a listener from the notification service.- Parameters:
cacheManagerEventListener- the listener to remove- Returns:
- true if the listener was present
-
hasRegisteredListeners
public boolean hasRegisteredListeners()
Returns whether or not at least one cache manager event listeners has been registered.- Returns:
- true if a one or more listeners have registered, otherwise false
-
getRegisteredListeners
public java.util.Set getRegisteredListeners()
Gets a Set of the listeners registered to this class- Returns:
- a set of type
CacheManagerEventListener
-
init
public void init()
Initialises the listeners, ready to receive events.- Specified by:
initin interfaceCacheManagerEventListener
-
getStatus
public Status getStatus()
Returns the listener status.- Specified by:
getStatusin interfaceCacheManagerEventListener- Returns:
- the status at the point in time the method is called
-
dispose
public void dispose()
Tell listeners to dispose themselves. Because this method is only ever called from a synchronized cache method, it does not itself need to be synchronized.- Specified by:
disposein interfaceCacheManagerEventListener
-
notifyCacheAdded
public void notifyCacheAdded(java.lang.String cacheName)
Called immediately after a cache has been added and activated.Note that the CacheManager calls this method from a synchronized method. Any attempt to call a synchronized method on CacheManager from this method will cause a deadlock.
Note that activation will also cause a CacheEventListener status change notification from
Status.STATUS_UNINITIALISEDtoStatus.STATUS_ALIVE. Care should be taken on processing that notification because:- the cache will not yet be accessible from the CacheManager.
- the addCaches methods which cause this notification are synchronized on the
CacheManager. An attempt to call
CacheManager.getEhcache(String)will cause a deadlock.
- Specified by:
notifyCacheAddedin interfaceCacheManagerEventListener- Parameters:
cacheName- the name of theCachethe operation relates to- See Also:
CacheEventListener
-
notifyCacheRemoved
public void notifyCacheRemoved(java.lang.String cacheName)
Called immediately after a cache has been disposed and removed. The calling method will block until this method returns.Note that the CacheManager calls this method from a synchronized method. Any attempt to call a synchronized method on CacheManager from this method will cause a deadlock.
Note that a
CacheEventListenerstatus changed will also be triggered. Any attempt from that notification to access CacheManager will also result in a deadlock.- Specified by:
notifyCacheRemovedin interfaceCacheManagerEventListener- Parameters:
cacheName- the name of theCachethe operation relates to
-
toString
public java.lang.String toString()
Returns a string representation of the object. In general, thetoStringmethod returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read.- Overrides:
toStringin classjava.lang.Object- Returns:
- a string representation of the object.
-
-