Package net.sf.ehcache.event
Class RegisteredEventListeners
- java.lang.Object
-
- net.sf.ehcache.event.RegisteredEventListeners
-
public class RegisteredEventListeners extends java.lang.ObjectRegistered listeners for registering and unregistering CacheEventListeners and multicasting notifications to registrants.There is one of these per Cache.
- Version:
- $Id$
- Author:
- Greg Luck, Geert Bevin
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceRegisteredEventListeners.ElementCreationCallbackCallback interface for creating elements to pass to registered listeners.
-
Constructor Summary
Constructors Constructor Description RegisteredEventListeners(Cache cache)Constructs a new notification serviceRegisteredEventListeners(Ehcache cache, CacheStoreHelper helper)Construct a registered event listeners service
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddispose()Tell listeners to dispose themselves.java.util.Set<CacheEventListener>getCacheEventListeners()Gets a copy of the set of the listeners registered to this classbooleanhasCacheEventListeners()Returns whether or not at least one cache event listeners has been registered.booleanhasCacheReplicators()Determines whether any registered listeners are CacheReplicators.voidnotifyElementEvicted(Element element, boolean remoteEvent)Notifies all registered listeners, in no guaranteed order, that an element has been evicted from the cachevoidnotifyElementEvicted(RegisteredEventListeners.ElementCreationCallback callback, boolean remoteEvent)Notifies all registered listeners, in no guaranteed order, that an element has been evicted from the cachevoidnotifyElementExpiry(Element element, boolean remoteEvent)Notifies all registered listeners, in no guaranteed order, that an element has expiredvoidnotifyElementExpiry(RegisteredEventListeners.ElementCreationCallback callback, boolean remoteEvent)Notifies all registered listeners, in no guaranteed order, that an element has expiredvoidnotifyElementPut(Element element, boolean remoteEvent)Notifies all registered listeners, in no guaranteed order, that an element was put into the cachevoidnotifyElementPut(RegisteredEventListeners.ElementCreationCallback callback, boolean remoteEvent)Notifies all registered listeners, in no guaranteed order, that an element was put into the cachevoidnotifyElementPutOrdered(Element element)NotifiesInternalCacheEventListeners, when a put happensvoidnotifyElementRemoved(Element element, boolean remoteEvent)Notifies all registered listeners, in no guaranteed order, that an element was removedvoidnotifyElementRemoved(RegisteredEventListeners.ElementCreationCallback callback, boolean remoteEvent)Notifies all registered listeners, in no guaranteed order, that an element was removedvoidnotifyElementRemovedOrdered(Element element)NotifiesInternalCacheEventListeners, when a remove happensvoidnotifyElementUpdated(Element element, boolean remoteEvent)Notifies all registered listeners, in no guaranteed order, that an element in the cache was updatedvoidnotifyElementUpdated(RegisteredEventListeners.ElementCreationCallback callback, boolean remoteEvent)Notifies all registered listeners, in no guaranteed order, that an element in the cache was updatedvoidnotifyElementUpdatedOrdered(Element oldElement, Element newElement)NotifiesInternalCacheEventListeners, when an update happensvoidnotifyRemoveAll(boolean remoteEvent)Notifies all registered listeners, in no guaranteed order, that removeAll has been called and all elements clearedbooleanregisterListener(CacheEventListener cacheEventListener)Adds a listener to the notification service.booleanregisterListener(CacheEventListener cacheEventListener, NotificationScope scope)Adds a listener to the notification service.java.lang.StringtoString()Returns a string representation of the object.booleanunregisterListener(CacheEventListener cacheEventListener)Removes a listener from the notification service.
-
-
-
Constructor Detail
-
RegisteredEventListeners
public RegisteredEventListeners(Cache cache)
Constructs a new notification service- Parameters:
cache-
-
RegisteredEventListeners
public RegisteredEventListeners(Ehcache cache, CacheStoreHelper helper)
Construct a registered event listeners service
-
-
Method Detail
-
notifyElementUpdatedOrdered
public final void notifyElementUpdatedOrdered(Element oldElement, Element newElement)
NotifiesInternalCacheEventListeners, when an update happens- Parameters:
oldElement- the old elementnewElement- the new element
-
notifyElementRemovedOrdered
public final void notifyElementRemovedOrdered(Element element)
NotifiesInternalCacheEventListeners, when a remove happens- Parameters:
element- the element removes
-
notifyElementPutOrdered
public final void notifyElementPutOrdered(Element element)
NotifiesInternalCacheEventListeners, when a put happens- Parameters:
element- the element put
-
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)
-
notifyElementRemoved
public final void notifyElementRemoved(RegisteredEventListeners.ElementCreationCallback callback, boolean remoteEvent) throws CacheException
Notifies all registered listeners, in no guaranteed order, that an element was removed- Parameters:
callback-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)
-
notifyElementPut
public final void notifyElementPut(RegisteredEventListeners.ElementCreationCallback callback, boolean remoteEvent) throws CacheException
Notifies all registered listeners, in no guaranteed order, that an element was put into the cache- Parameters:
callback-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)
-
notifyElementUpdated
public final void notifyElementUpdated(RegisteredEventListeners.ElementCreationCallback callback, boolean remoteEvent)
Notifies all registered listeners, in no guaranteed order, that an element in the cache was updated- Parameters:
callback-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 onremoteEvent- whether the event came from a remote cache peer- See Also:
CacheEventListener.notifyElementExpired(net.sf.ehcache.Ehcache, net.sf.ehcache.Element)
-
notifyElementExpiry
public final void notifyElementExpiry(RegisteredEventListeners.ElementCreationCallback callback, boolean remoteEvent)
Notifies all registered listeners, in no guaranteed order, that an element has expired- Parameters:
callback-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 final 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 onremoteEvent- whether the event came from a remote cache peer- See Also:
CacheEventListener.notifyElementEvicted(net.sf.ehcache.Ehcache, net.sf.ehcache.Element)
-
notifyElementEvicted
public final void notifyElementEvicted(RegisteredEventListeners.ElementCreationCallback callback, boolean remoteEvent)
Notifies all registered listeners, in no guaranteed order, that an element has been evicted from the cache- Parameters:
callback-remoteEvent- whether the event came from a remote cache peer- See Also:
CacheEventListener.notifyElementEvicted(net.sf.ehcache.Ehcache, net.sf.ehcache.Element)
-
notifyRemoveAll
public final 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
-
registerListener
public final boolean registerListener(CacheEventListener cacheEventListener, NotificationScope scope)
Adds a listener to the notification service. No guarantee is made that listeners will be notified in the order they were added.If a cache is configured in a cluster, listeners in each node will get triggered by an event depending on the value of the
listenFor
parameter.- Parameters:
cacheEventListener- The listener to addscope- The notification scope- Returns:
- true if the listener is being added and was not already added
- Since:
- 2.0
-
unregisterListener
public final boolean unregisterListener(CacheEventListener cacheEventListener)
Removes a listener from the notification service.- Parameters:
cacheEventListener-- Returns:
- true if the listener was present
-
hasCacheReplicators
public final boolean hasCacheReplicators()
Determines whether any registered listeners are CacheReplicators.- Returns:
- whether any registered listeners are CacheReplicators.
-
getCacheEventListeners
public final java.util.Set<CacheEventListener> getCacheEventListeners()
Gets a copy of the set of the listeners registered to this class- Returns:
- a set 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, 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.
-
-