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 TypeMethodDescriptionvoidBlocks until all of the synchronous listeners have finished processing the events this thread published.voidderegister(javax.cache.configuration.CacheEntryListenerConfiguration<K, V> configuration) Deregisters a cache entry listener based on the supplied configuration.voidIgnores and clears the queued futures to the synchronous listeners that are processing events this thread published.private voidpublish(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.voidpublishCreated(javax.cache.Cache<K, V> cache, K key, V value) Publishes a creation event for the entry to all of the interested listeners.voidpublishExpired(javax.cache.Cache<K, V> cache, K key, V value) Publishes a expire event for the entry to all of the interested listeners.voidpublishExpiredQuietly(javax.cache.Cache<K, V> cache, K key, V value) Publishes a expire event for the entry to all of the interested listeners.voidpublishRemoved(javax.cache.Cache<K, V> cache, K key, V value) Publishes a remove event for the entry to all of the interested listeners.voidpublishRemovedQuietly(javax.cache.Cache<K, V> cache, K key, V value) Publishes a remove event for the entry to all of the interested listeners.voidPublishes a update event for the entry to all of the interested listeners.voidRegisters 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
-
deregister
-
publishCreated
-
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
-
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
-
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
-