Class MapEvent<K,V>

java.lang.Object
java.util.EventObject
com.tangosol.util.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:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    This event indicates that an entry has been removed from the map.
    static final int
    This event indicates that an entry has been added to the map.
    static final int
    This event indicates that an entry has been updated in the map.
    protected K
    A key.
    protected int
    The event's id.
    protected int
    The partition this MapEvent was emitted from.
    protected long
    The partition version of this MapEvent.
    protected V
    A new value.
    protected V
    A previous value.

    Fields inherited from class java.util.EventObject

    source
  • Constructor Summary

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

    Modifier and Type
    Method
    Description
    void
    dispatch(Listeners listeners)
    Dispatch this event to the specified listeners collection.
    void
    dispatch(Listeners listeners, boolean fStrict)
    Dispatch this event to the specified listeners collection.
    void
    dispatch(MapListener<? super K,? super V> listener)
    Dispatch this event to the specified MapListener.
    protected String
    Get the event's description.
    static String
    getDescription(int nId)
    Convert an event ID into a human-readable string.
    int
    Return this event's id.
    Return a key associated with this event.
    Return an ObservableMap object on which this event has actually occurred.
    Return a Map Entry that represents the state of the Entry after the change occurred that generated this event.
    Return a new value associated with this event.
    Return a Map Entry that represents the state of the Entry before the change occurred that generated this event.
    Return an old value associated with this event.
    int
    Return the partition this MapEvent represents or -1 if the event source is not partition aware.
    long
    Return the version that represents the change that caused this MapEvent.
    boolean
    Determine whether this event is a delete event.
    boolean
    Determine whether this event is an insert event.
    boolean
    Determine whether this event is an update event.
    void
    Restore the contents of a user type instance by reading its state using the specified PofReader object.
    protected boolean
    Return true if the provided MapListener should receive this event.
    Return a String representation of this MapEvent object.
    with(int nPartition, long lVersion)
    Return a MapEvent that is enriched with the provided partition and version.
    void
    Save the contents of a POF user type instance by writing its state using the specified PofWriter object.

    Methods inherited from class java.util.EventObject

    getSource

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • ENTRY_INSERTED

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

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

      public static final int ENTRY_DELETED
      This event indicates that an entry has been removed from the map.
      See Also:
    • 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 Details

    • 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 Details

    • 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"