Interface Listeners.WriteListeners<K,​V>

  • All Known Subinterfaces:
    Listeners.ReadWriteListeners<K,​V>
    Enclosing class:
    Listeners

    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
    • Method Detail

      • onWrite

        java.lang.AutoCloseable onWrite​(java.util.function.Consumer<EntryView.ReadEntryView<K,​V>> f)
        Add a write event listener by passing in a Consumer 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, hence EntryView.ReadEntryView.find() will return an empty Optional instance, and EntryView.ReadEntryView.get() will throw NoSuchElementException.

        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

        java.lang.AutoCloseable add​(Listeners.WriteListeners.WriteListener<K,​V> l)
        Add a write-only listener, and return an AutoCloseable 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