ehcache

net.sf.ehcache.event
Class RegisteredEventListeners

java.lang.Object
  extended by net.sf.ehcache.event.RegisteredEventListeners

public class RegisteredEventListeners
extends java.lang.Object

Registered listeners for registering and unregistering CacheEventListeners and multicasting notifications to registrants.

There is one of these per Cache.

This class also has counters to accumulate the numbers of each type of event for statistics purposes.

Version:
$Id: RegisteredEventListeners.java 558 2007-10-29 07:14:38Z gregluck $
Author:
Greg Luck

Constructor Summary
RegisteredEventListeners(Ehcache cache)
          Constructs a new notification service
 
Method Summary
 void clearCounters()
          Clears all event counters
 void dispose()
          Tell listeners to dispose themselves.
 java.util.Set getCacheEventListeners()
          Gets a list of the listeners registered to this class
 long getElementsEvictedCounter()
          Gets the number of events, irrespective of whether there are any registered listeners.
 long getElementsExpiredCounter()
          Gets the number of events, irrespective of whether there are any registered listeners.
 long getElementsPutCounter()
          Gets the number of events, irrespective of whether there are any registered listeners.
 long getElementsRemoveAllCounter()
          Gets the number of events, irrespective of whether there are any registered listeners.
 long getElementsRemovedCounter()
          Gets the number of events, irrespective of whether there are any registered listeners.
 long getElementsUpdatedCounter()
          Gets the number of events, irrespective of whether there are any registered listeners.
 boolean hasCacheEventListeners()
          Returns whether or not at least one cache event listeners has been registered.
 void notifyElementEvicted(Element element, boolean remoteEvent)
          Notifies all registered listeners, in no guaranteed order, that an element has been evicted from the cache
 void notifyElementExpiry(Element element, boolean remoteEvent)
          Notifies all registered listeners, in no guaranteed order, that an element has expired
 void notifyElementPut(Element element, boolean remoteEvent)
          Notifies all registered listeners, in no guaranteed order, that an element was put into the cache
 void notifyElementRemoved(Element element, boolean remoteEvent)
          Notifies all registered listeners, in no guaranteed order, that an element was removed
 void notifyElementUpdated(Element element, boolean remoteEvent)
          Notifies all registered listeners, in no guaranteed order, that an element in the cache was updated
 void notifyRemoveAll(boolean remoteEvent)
          Notifies all registered listeners, in no guaranteed order, that removeAll has been called and all elements cleared
 boolean registerListener(CacheEventListener cacheEventListener)
          Adds a listener to the notification service.
 java.lang.String toString()
          Returns a string representation of the object.
 boolean unregisterListener(CacheEventListener cacheEventListener)
          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

RegisteredEventListeners

public RegisteredEventListeners(Ehcache cache)
Constructs a new notification service

Parameters:
cache -
Method Detail

notifyElementRemoved

public final void notifyElementRemoved(Element element,
                                       boolean remoteEvent)
                                throws CacheException
Notifies all registered listeners, in no guaranteed order, that an element was removed

Parameters:
element -
remoteEvent - whether the event came from a remote cache peer
Throws:
CacheException
See Also:
CacheEventListener.notifyElementRemoved(net.sf.ehcache.Ehcache, net.sf.ehcache.Element)

notifyElementPut

public final void notifyElementPut(Element element,
                                   boolean remoteEvent)
                            throws CacheException
Notifies all registered listeners, in no guaranteed order, that an element was put into the cache

Parameters:
element -
remoteEvent - whether the event came from a remote cache peer
Throws:
CacheException
See Also:
CacheEventListener.notifyElementPut(net.sf.ehcache.Ehcache,net.sf.ehcache.Element)

notifyElementUpdated

public final void notifyElementUpdated(Element element,
                                       boolean remoteEvent)
Notifies all registered listeners, in no guaranteed order, that an element in the cache was updated

Parameters:
element -
remoteEvent - whether the event came from a remote cache peer
See Also:
CacheEventListener.notifyElementPut(net.sf.ehcache.Ehcache,net.sf.ehcache.Element)

notifyElementExpiry

public final void notifyElementExpiry(Element element,
                                      boolean remoteEvent)
Notifies all registered listeners, in no guaranteed order, that an element has expired

Parameters:
element - the Element to perform the notification on
remoteEvent - whether the event came from a remote cache peer
See Also:
CacheEventListener.notifyElementExpired(net.sf.ehcache.Ehcache, net.sf.ehcache.Element)

hasCacheEventListeners

public final boolean hasCacheEventListeners()
Returns whether or not at least one cache event listeners has been registered.

Returns:
true if a one or more listeners have registered, otherwise false

notifyElementEvicted

public void notifyElementEvicted(Element element,
                                 boolean remoteEvent)
Notifies all registered listeners, in no guaranteed order, that an element has been evicted from the cache

Parameters:
element - the Element to perform the notification on
remoteEvent - whether the event came from a remote cache peer
See Also:
CacheEventListener.notifyElementEvicted(net.sf.ehcache.Ehcache, net.sf.ehcache.Element)

notifyRemoveAll

public void notifyRemoveAll(boolean remoteEvent)
Notifies all registered listeners, in no guaranteed order, that removeAll has been called and all elements cleared

Parameters:
remoteEvent - whether the event came from a remote cache peer
See Also:
CacheEventListener.notifyElementEvicted(net.sf.ehcache.Ehcache, net.sf.ehcache.Element)

registerListener

public final boolean registerListener(CacheEventListener cacheEventListener)
Adds a listener to the notification service. No guarantee is made that listeners will be notified in the order they were added.

Parameters:
cacheEventListener -
Returns:
true if the listener is being added and was not already added

unregisterListener

public final boolean unregisterListener(CacheEventListener cacheEventListener)
Removes a listener from the notification service.

Parameters:
cacheEventListener -
Returns:
true if the listener was present

getCacheEventListeners

public final java.util.Set getCacheEventListeners()
Gets a list of the listeners registered to this class

Returns:
a list of type CacheEventListener

dispose

public final 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.


toString

public final 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.

clearCounters

public void clearCounters()
Clears all event counters


getElementsRemovedCounter

public long getElementsRemovedCounter()
Gets the number of events, irrespective of whether there are any registered listeners.

Returns:
the number of events since cache creation or last clearing of counters

getElementsPutCounter

public long getElementsPutCounter()
Gets the number of events, irrespective of whether there are any registered listeners.

Returns:
the number of events since cache creation or last clearing of counters

getElementsUpdatedCounter

public long getElementsUpdatedCounter()
Gets the number of events, irrespective of whether there are any registered listeners.

Returns:
the number of events since cache creation or last clearing of counters

getElementsExpiredCounter

public long getElementsExpiredCounter()
Gets the number of events, irrespective of whether there are any registered listeners.

Returns:
the number of events since cache creation or last clearing of counters

getElementsEvictedCounter

public long getElementsEvictedCounter()
Gets the number of events, irrespective of whether there are any registered listeners.

Returns:
the number of events since cache creation or last clearing of counters

getElementsRemoveAllCounter

public long getElementsRemoveAllCounter()
Gets the number of events, irrespective of whether there are any registered listeners.

Returns:
the number of events since cache creation or last clearing of counters

ehcache