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 by using a dispatch queue for
each listener and key pair, and provides the following characteristics:
- A listener may be executed in parallel for events with different keys
- A listener is executed sequentially for events with the same key. This creates a dependency relationship between events and waiting dependents do not consume threads.
- A listener receives a single event per invocation; batch processing is not supported
- Multiple listeners may be executed in parallel for the same event
- Listeners process events at their own rate and do not explicitly block each other
- Listeners share a pool of threads for event processing. A slow listener may limit the throughput if all threads are busy handling distinct events, causing the execution of other listeners to be delayed until the executor is able to process the work.
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidBlocks until all of the synchronous listeners have finished processing the events this thread published.voidderegister(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.voidPublishes a creation event for the entry to the interested listeners.voidPublishes an expiration event for the entry to the interested listeners.voidPublishes an expiration event for the entry to the interested listeners.voidPublishes a removal event for the entry to the interested listeners.voidPublishes a removal event for the entry to the interested listeners.voidPublishes an update event for the entry to the interested listeners.voidregister(CacheEntryListenerConfiguration<K, V> configuration) Registers a cache entry listener based on the supplied configuration.Set<Registration<K, V>> Returns the cache entry listener registrations.
-
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
Deregisters a cache entry listener based on the supplied configuration.- Parameters:
configuration- the listener's configuration.
-
publishCreated
-
publishUpdated
-
publishRemoved
-
publishRemovedQuietly
Publishes a removal event for the entry to 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 an expiration event for the entry to 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.
-