public final class EventDispatcher<K,V> extends Object
A CacheEntryListener is required to receive events in the order of the actions being
performed on the associated key. This implementation supports this through an actor-like model
by using a dispatch queue per listener. A listener is never executed in parallel on different
events, but may be executed sequentially on different threads. Batch processing of the dispatch
queue is not presently supported.
Some listeners may be configured as synchronous, meaning that the publishing thread
should wait until the listener has processed the event. The calling thread should publish within
an atomic block that mutates the entry, and complete the operation by calling
awaitSynchronous() or ignoreSynchronous().
| Constructor and Description |
|---|
EventDispatcher(Executor executor) |
| Modifier and Type | Method and Description |
|---|---|
void |
awaitSynchronous()
Blocks until all of the synchronous listeners have finished processing the events this thread
published.
|
void |
deregister(CacheEntryListenerConfiguration<K,V> configuration)
Deregisters a cache entry listener based on the supplied configuration.
|
void |
ignoreSynchronous()
Ignores and clears the queued futures to the synchronous listeners that are processing events
this thread published.
|
void |
publishCreated(Cache<K,V> cache,
K key,
V value)
Publishes a creation event for the entry to all of the interested listeners.
|
void |
publishExpired(Cache<K,V> cache,
K key,
V value)
Publishes a expire event for the entry to all of the interested listeners.
|
void |
publishExpiredQuietly(Cache<K,V> cache,
K key,
V value)
Publishes a expire event for the entry to all of the interested listeners.
|
void |
publishRemoved(Cache<K,V> cache,
K key,
V value)
Publishes a remove event for the entry to all of the interested listeners.
|
void |
publishRemovedQuietly(Cache<K,V> cache,
K key,
V value)
Publishes a remove event for the entry to all of the interested listeners.
|
void |
publishUpdated(Cache<K,V> cache,
K key,
V oldValue,
V newValue)
Publishes a update event for the entry to all of the interested listeners.
|
void |
register(CacheEntryListenerConfiguration<K,V> configuration)
Registers a cache entry listener based on the supplied configuration.
|
Set<Registration<K,V>> |
registrations()
Returns the cache entry listener registrations.
|
public EventDispatcher(Executor executor)
public Set<Registration<K,V>> registrations()
public void register(CacheEntryListenerConfiguration<K,V> configuration)
configuration - the listener's configuration.public void deregister(CacheEntryListenerConfiguration<K,V> configuration)
configuration - the listener's configuration.public void publishCreated(Cache<K,V> cache, K key, V value)
cache - the cache where the entry was createdkey - the entry's keyvalue - the entry's valuepublic void publishUpdated(Cache<K,V> cache, K key, V oldValue, V newValue)
cache - the cache where the entry was updatedkey - the entry's keyoldValue - the entry's old valuenewValue - the entry's new valuepublic void publishRemoved(Cache<K,V> cache, K key, V value)
cache - the cache where the entry was removedkey - the entry's keyvalue - the entry's valuepublic void publishRemovedQuietly(Cache<K,V> cache, K key, V value)
awaitSynchronous().cache - the cache where the entry was removedkey - the entry's keyvalue - the entry's valuepublic void publishExpired(Cache<K,V> cache, K key, V value)
cache - the cache where the entry expiredkey - the entry's keyvalue - the entry's valuepublic void publishExpiredQuietly(Cache<K,V> cache, K key, V value)
awaitSynchronous().cache - the cache where the entry expiredkey - the entry's keyvalue - the entry's valuepublic void awaitSynchronous()
public void ignoreSynchronous()