org.ehcache.events
Class CacheEventDispatcherImpl<K,V>

java.lang.Object
  extended by org.ehcache.events.CacheEventDispatcherImpl<K,V>
All Implemented Interfaces:
CacheEventDispatcher<K,V>

public class CacheEventDispatcherImpl<K,V>
extends java.lang.Object
implements CacheEventDispatcher<K,V>

Per-cache component that manages cache event listener registrations, and provides event delivery based on desired firing mode and ordering, for specified event types.

Note on event ordering guarantees:
onEvent(CacheEvent) is assumed to be called within a key-based lock scope. If that is not the case, this facility has no means of maintaining event ordering consistent with source of such events. That is - listeners registered to receive events in the order they occurred in underlying store may be invoked in an order inconsistent with actual ordering of corresponding operations on said store.

Conversely, sending events to this service inside lock scope, when there are no registered listeners interested in ordered event delivery is harmless, i.e. event delivery to unordered listeners will still occur.


Constructor Summary
CacheEventDispatcherImpl(java.util.concurrent.ExecutorService orderedDelivery, java.util.concurrent.ExecutorService unorderedDelivery, Store<K,V> store)
           
 
Method Summary
 void deregisterCacheEventListener(CacheEventListener<? super K,? super V> listener)
          Allows for deregistering of a previously registered CacheEventListener instance
 boolean hasListeners()
           
 void onEvent(CacheEvent<K,V> event)
           
 void registerCacheEventListener(CacheEventListener<? super K,? super V> listener, EventOrdering ordering, EventFiring firing, java.util.EnumSet<EventType> forEventTypes)
          Allows for registering CacheEventListener on the cache
 void releaseAllListeners()
           
 void setStoreListenerSource(Cache<K,V> source)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CacheEventDispatcherImpl

public CacheEventDispatcherImpl(java.util.concurrent.ExecutorService orderedDelivery,
                                java.util.concurrent.ExecutorService unorderedDelivery,
                                Store<K,V> store)
Method Detail

registerCacheEventListener

public void registerCacheEventListener(CacheEventListener<? super K,? super V> listener,
                                       EventOrdering ordering,
                                       EventFiring firing,
                                       java.util.EnumSet<EventType> forEventTypes)
Allows for registering CacheEventListener on the cache

Specified by:
registerCacheEventListener in interface CacheEventDispatcher<K,V>
Parameters:
listener - the listener instance to register
ordering - the EventOrdering to invoke this listener
firing - the EventFiring to invoke this listener
forEventTypes - the EventType to notify this listener of
Throws:
java.lang.IllegalStateException - if the listener is already registered

deregisterCacheEventListener

public void deregisterCacheEventListener(CacheEventListener<? super K,? super V> listener)
Allows for deregistering of a previously registered CacheEventListener instance

Specified by:
deregisterCacheEventListener in interface CacheEventDispatcher<K,V>
Parameters:
listener - the listener to deregister
Throws:
java.lang.IllegalStateException - if the listener isn't already registered

releaseAllListeners

public void releaseAllListeners()
Specified by:
releaseAllListeners in interface CacheEventDispatcher<K,V>

setStoreListenerSource

public void setStoreListenerSource(Cache<K,V> source)
Specified by:
setStoreListenerSource in interface CacheEventDispatcher<K,V>

onEvent

public void onEvent(CacheEvent<K,V> event)
Specified by:
onEvent in interface CacheEventDispatcher<K,V>

hasListeners

public boolean hasListeners()
Specified by:
hasListeners in interface CacheEventDispatcher<K,V>
Returns:
true if at least one cache event listener is registered