Interface Listeners.WriteListeners<K,V>
-
- All Known Subinterfaces:
Listeners.ReadWriteListeners<K,V>
- Enclosing class:
- Listeners
@Experimental public static interface Listeners.WriteListeners<K,V>
Write listeners enable user to register listeners for any cache entry write events that happen in either a read-write or write-only functional map.Listeners for write events cannot distinguish between cache entry created and cache entry modify/update events because they don't have access to the previous value. All they know is that a new non-null entry has been written.
However, write event listeners can distinguish between entry removals and cache entry create/modify-update events because they can query what the new entry's value via
EntryView.ReadEntryView.find()
.- Since:
- 8.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
Listeners.WriteListeners.WriteListener<K,V>
Write-only listener.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description AutoCloseable
add(Listeners.WriteListeners.WriteListener<K,V> l)
Add a write-only listener, and return anAutoCloseable
instance that can be used to remove the listener registration.AutoCloseable
onWrite(Consumer<EntryView.ReadEntryView<K,V>> f)
Add a write event listener by passing in aConsumer
to be called each time a cache entry is created, modified/updated or removed.
-
-
-
Method Detail
-
onWrite
AutoCloseable onWrite(Consumer<EntryView.ReadEntryView<K,V>> f)
Add a write event listener by passing in aConsumer
to be called each time a cache entry is created, modified/updated or removed.For created or modified/updated events, the
EntryView.ReadEntryView
passed in will represent the newly stored entry, hence implementations will not be available to differentiate between created events vs modified/updated events.For removed events,
EntryView.ReadEntryView
passed in will represent an empty entry view, henceEntryView.ReadEntryView.find()
will return an emptyOptional
instance, andEntryView.ReadEntryView.get()
will throwNoSuchElementException
.- Parameters:
f
- operation to be called each time a cache entry is written- Returns:
- an
AutoCloseable
instance that can be used to unregister the listener
-
add
AutoCloseable add(Listeners.WriteListeners.WriteListener<K,V> l)
Add a write-only listener, and return anAutoCloseable
instance that can be used to remove the listener registration.- Parameters:
l
- the write-only functional map event listener- Returns:
- an
AutoCloseable
instance that can be used to unregister the listener
-
-