Class MapEvent<K,​V>

  • Type Parameters:
    K - the type of the Map entry key
    V - the type of the Map entry value
    All Implemented Interfaces:
    PortableObject, Serializable
    Direct Known Subclasses:
    CacheEvent

    public class MapEvent<K,​V>
    extends EventObject
    implements PortableObject
    An event which indicates that the content of a map has changed:
    • an entry has been added
    • an entry has been removed
    • an entry has been changed
    A MapEvent object is sent as an argument to the MapListener interface methods. Null values may be provided for the old and the new values.
    Author:
    gg 2002.02.11
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int ENTRY_DELETED
      This event indicates that an entry has been removed from the map.
      static int ENTRY_INSERTED
      This event indicates that an entry has been added to the map.
      static int ENTRY_UPDATED
      This event indicates that an entry has been updated in the map.
      protected K m_key
      A key.
      protected int m_nId
      The event's id.
      protected int m_nPartition
      The partition this MapEvent was emitted from.
      protected long m_nVersion
      The partition version of this MapEvent.
      protected V m_valueNew
      A new value.
      protected V m_valueOld
      A previous value.
    • Constructor Summary

      Constructors 
      Constructor Description
      MapEvent()
      Default constructor for serialization.
      MapEvent​(ObservableMap<K,​V> map, int nId, K key, V valueOld, V valueNew)
      Constructs a new MapEvent.
    • Field Detail

      • ENTRY_INSERTED

        public static final int ENTRY_INSERTED
        This event indicates that an entry has been added to the map.
        See Also:
        Constant Field Values
      • ENTRY_UPDATED

        public static final int ENTRY_UPDATED
        This event indicates that an entry has been updated in the map.
        See Also:
        Constant Field Values
      • ENTRY_DELETED

        public static final int ENTRY_DELETED
        This event indicates that an entry has been removed from the map.
        See Also:
        Constant Field Values
      • m_nId

        protected int m_nId
        The event's id.
      • m_key

        protected K m_key
        A key.
      • m_valueOld

        protected V m_valueOld
        A previous value. May be null if not known.
      • m_valueNew

        protected V m_valueNew
        A new value. May be null if not known.
      • m_nPartition

        protected int m_nPartition
        The partition this MapEvent was emitted from.
      • m_nVersion

        protected long m_nVersion
        The partition version of this MapEvent.
    • Constructor Detail

      • MapEvent

        public MapEvent()
        Default constructor for serialization.
      • MapEvent

        public MapEvent​(ObservableMap<K,​V> map,
                        int nId,
                        K key,
                        V valueOld,
                        V valueNew)
        Constructs a new MapEvent.
        Parameters:
        map - the ObservableMap object that fired the event
        nId - this event's id, one of ENTRY_INSERTED, ENTRY_UPDATED or ENTRY_DELETED
        key - the key into the map
        valueOld - the old value (for update and delete events)
        valueNew - the new value (for insert and update events)
    • Method Detail

      • getMap

        public ObservableMap getMap()
        Return an ObservableMap object on which this event has actually occurred.
        Returns:
        an ObservableMap object
      • getId

        public int getId()
        Return this event's id. The event id is one of the ENTRY_* enumerated constants.
        Returns:
        an id
      • getKey

        public K getKey()
        Return a key associated with this event.
        Returns:
        a key
      • getOldValue

        public V getOldValue()
        Return an old value associated with this event.

        The old value represents a value deleted from or updated in a map. It is always null for "insert" notifications.

        Returns:
        an old value
      • getNewValue

        public V getNewValue()
        Return a new value associated with this event.

        The new value represents a new value inserted into or updated in a map. It is always null for "delete" notifications.

        Returns:
        a new value
      • getOldEntry

        public Map.Entry<K,​V> getOldEntry()
        Return a Map Entry that represents the state of the Entry before the change occurred that generated this event.
        Returns:
        a Map Entry representing the pre-event state of the Entry
        Since:
        Coherence 3.6
      • getNewEntry

        public Map.Entry<K,​V> getNewEntry()
        Return a Map Entry that represents the state of the Entry after the change occurred that generated this event.
        Returns:
        a Map Entry representing the post-event state of the Entry
        Since:
        Coherence 3.6
      • getPartition

        public int getPartition()
        Return the partition this MapEvent represents or -1 if the event source is not partition aware.
        Returns:
        the partition this MapEvent represents or -1 if the event source is not partition aware
      • getVersion

        public long getVersion()
        Return the version that represents the change that caused this MapEvent. The meaning of this version, and therefore causality of versions, is defined by the event source.
        Returns:
        the version that represents the change that caused this MapEvent
      • isInsert

        public boolean isInsert()
        Determine whether this event is an insert event.
        Returns:
        true if this event is an insert event
      • isUpdate

        public boolean isUpdate()
        Determine whether this event is an update event.
        Returns:
        true if this event is an update event
      • isDelete

        public boolean isDelete()
        Determine whether this event is a delete event.
        Returns:
        true if this event is a delete event
      • with

        public MapEvent<K,​V> with​(int nPartition,
                                        long lVersion)
        Return a MapEvent that is enriched with the provided partition and version.
        Parameters:
        nPartition - the partition this MapEvent
        lVersion - the version that caused this change
        Returns:
        a MapEvent that is enriched with the provided partition and version
      • readExternal

        public void readExternal​(PofReader in)
                          throws IOException
        Description copied from interface: PortableObject
        Restore the contents of a user type instance by reading its state using the specified PofReader object.
        Specified by:
        readExternal in interface PortableObject
        Parameters:
        in - the PofReader from which to read the object's state
        Throws:
        IOException - if an I/O error occurs
      • writeExternal

        public void writeExternal​(PofWriter out)
                           throws IOException
        Description copied from interface: PortableObject
        Save the contents of a POF user type instance by writing its state using the specified PofWriter object.
        Specified by:
        writeExternal in interface PortableObject
        Parameters:
        out - the PofWriter to which to write the object's state
        Throws:
        IOException - if an I/O error occurs
      • toString

        public String toString()
        Return a String representation of this MapEvent object.
        Overrides:
        toString in class EventObject
        Returns:
        a String representation of this MapEvent object
      • dispatch

        public void dispatch​(Listeners listeners)
        Dispatch this event to the specified listeners collection.

        This call is equivalent to

           dispatch(listeners, true);
         
        Parameters:
        listeners - the listeners collection
        Throws:
        ClassCastException - if any of the targets is not an instance of MapListener interface
      • dispatch

        public void dispatch​(Listeners listeners,
                             boolean fStrict)
        Dispatch this event to the specified listeners collection.
        Parameters:
        listeners - the listeners collection
        fStrict - if true then any RuntimeException thrown by event handlers stops all further event processing and the exception is re-thrown; if false then all exceptions are logged and the process continues
        Throws:
        ClassCastException - if any of the targets is not an instance of MapListener interface
      • dispatch

        public void dispatch​(MapListener<? super K,​? super V> listener)
        Dispatch this event to the specified MapListener.
        Parameters:
        listener - the listener
      • shouldDispatch

        protected boolean shouldDispatch​(MapListener listener)
        Return true if the provided MapListener should receive this event.
        Parameters:
        listener - the MapListener to dispatch this event to
        Returns:
        true if the provided MapListener should receive the event
      • getDescription

        protected String getDescription()
        Get the event's description.
        Returns:
        this event's description
      • getDescription

        public static String getDescription​(int nId)
        Convert an event ID into a human-readable string.
        Parameters:
        nId - an event ID, one of the ENTRY_* enumerated values
        Returns:
        a corresponding human-readable string, for example "inserted"