Class EventDispatcher<K,V>
java.lang.Object
com.github.benmanes.caffeine.jcache.event.EventDispatcher<K,V>
A dispatcher that publishes cache events to listeners for asynchronous execution.
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()
.
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) final Map
<Registration<K, V>, CompletableFuture<Void>> (package private) final Executor
(package private) static final Logger
(package private) static final ThreadLocal
<List<CompletableFuture<Void>>> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Blocks until all of the synchronous listeners have finished processing the events this thread published.void
deregister
(javax.cache.configuration.CacheEntryListenerConfiguration<K, V> configuration) Deregisters a cache entry listener based on the supplied configuration.void
Ignores and clears the queued futures to the synchronous listeners that are processing events this thread published.private void
publish
(javax.cache.Cache<K, V> cache, javax.cache.event.EventType eventType, K key, boolean hasOldValue, @Nullable V oldValue, @Nullable V newValue, boolean quiet) Broadcasts the event to all of the interested listener's dispatch queues.void
publishCreated
(javax.cache.Cache<K, V> cache, K key, V value) Publishes a creation event for the entry to all of the interested listeners.void
publishExpired
(javax.cache.Cache<K, V> cache, K key, V value) Publishes a expire event for the entry to all of the interested listeners.void
publishExpiredQuietly
(javax.cache.Cache<K, V> cache, K key, V value) Publishes a expire event for the entry to all of the interested listeners.void
publishRemoved
(javax.cache.Cache<K, V> cache, K key, V value) Publishes a remove event for the entry to all of the interested listeners.void
publishRemovedQuietly
(javax.cache.Cache<K, V> cache, K key, V value) Publishes a remove event for the entry to all of the interested listeners.void
Publishes a update event for the entry to all of the interested listeners.void
Registers a cache entry listener based on the supplied configuration.Set
<Registration<K, V>> Returns the cache entry listener registrations.
-
Field Details
-
logger
-
pending
-
executor
-
dispatchQueues
-
-
Constructor Details
-
EventDispatcher
-
-
Method Details
-
registrations
Returns the cache entry listener registrations. -
register
Registers a cache entry listener based on the supplied configuration.- Parameters:
configuration
- the listener's configuration.
-
deregister
public void deregister(javax.cache.configuration.CacheEntryListenerConfiguration<K, V> configuration) Deregisters a cache entry listener based on the supplied configuration.- Parameters:
configuration
- the listener's configuration.
-
publishCreated
Publishes a creation event for the entry to all of the interested listeners.- Parameters:
cache
- the cache where the entry was createdkey
- the entry's keyvalue
- the entry's value
-
publishUpdated
Publishes a update event for the entry to all of the interested listeners.- Parameters:
cache
- the cache where the entry was updatedkey
- the entry's keyoldValue
- the entry's old valuenewValue
- the entry's new value
-
publishRemoved
Publishes a remove event for the entry to all of the interested listeners.- Parameters:
cache
- the cache where the entry was removedkey
- the entry's keyvalue
- the entry's value
-
publishRemovedQuietly
Publishes a remove event for the entry to all of the interested listeners. This method does not register the synchronous listener's future withawaitSynchronous()
.- Parameters:
cache
- the cache where the entry was removedkey
- the entry's keyvalue
- the entry's value
-
publishExpired
Publishes a expire event for the entry to all of the interested listeners.- Parameters:
cache
- the cache where the entry expiredkey
- the entry's keyvalue
- the entry's value
-
publishExpiredQuietly
Publishes a expire event for the entry to all of the interested listeners. This method does not register the synchronous listener's future withawaitSynchronous()
.- Parameters:
cache
- the cache where the entry expiredkey
- the entry's keyvalue
- the entry's value
-
awaitSynchronous
public void awaitSynchronous()Blocks until all of the synchronous listeners have finished processing the events this thread published. -
ignoreSynchronous
public void ignoreSynchronous()Ignores and clears the queued futures to the synchronous listeners that are processing events this thread published. -
publish
private void publish(javax.cache.Cache<K, V> cache, javax.cache.event.EventType eventType, K key, boolean hasOldValue, @Nullable V oldValue, @Nullable V newValue, boolean quiet) Broadcasts the event to all of the interested listener's dispatch queues.
-