ehcache

net.sf.ehcache.event
Class CacheManagerEventListenerRegistry

java.lang.Object
  extended by 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: CacheManagerEventListenerRegistry.java 519 2007-07-27 07:11:45Z gregluck $
Author:
Greg Luck

Constructor Summary
CacheManagerEventListenerRegistry()
          Construct a new registry
 
Method Summary
 void dispose()
          Tell listeners to dispose themselves.
 java.util.Set getRegisteredListeners()
          Gets a Set of the listeners registered to this class
 Status getStatus()
          Returns the listener status.
 boolean hasRegisteredListeners()
          Returns whether or not at least one cache manager event listeners has been registered.
 void init()
          Initialises the listeners, ready to receive events.
 void notifyCacheAdded(java.lang.String cacheName)
          Called immediately after a cache has been added and activated.
 void notifyCacheRemoved(java.lang.String cacheName)
          Called immediately after a cache has been disposed and removed.
 boolean registerListener(CacheManagerEventListener cacheManagerEventListener)
          Adds a listener to the notification service.
 java.lang.String toString()
          Returns a string representation of the object.
 boolean unregisterListener(CacheManagerEventListener cacheManagerEventListener)
          Removes a listener from the notification service.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CacheManagerEventListenerRegistry

public CacheManagerEventListenerRegistry()
Construct a new registry

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:
init in interface CacheManagerEventListener

getStatus

public Status getStatus()
Returns the listener status.

Specified by:
getStatus in interface CacheManagerEventListener
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:
dispose in interface CacheManagerEventListener

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_UNINITIALISED to Status.STATUS_ALIVE. Care should be taken on processing that notification because:

The calling method will block until this method returns.

Specified by:
notifyCacheAdded in interface CacheManagerEventListener
Parameters:
cacheName - the name of the Cache the 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 CacheEventListener status changed will also be triggered. Any attempt from that notification to access CacheManager will also result in a deadlock.

Specified by:
notifyCacheRemoved in interface CacheManagerEventListener
Parameters:
cacheName - the name of the Cache the operation relates to

toString

public java.lang.String toString()
Returns a string representation of the object. In general, the toString method 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:
toString in class java.lang.Object
Returns:
a string representation of the object.

ehcache