00001 /* 00002 * Copyright (c) 2000, 2020, Oracle and/or its affiliates. 00003 * 00004 * Licensed under the Universal Permissive License v 1.0 as shown at 00005 * http://oss.oracle.com/licenses/upl. 00006 */ 00007 #ifndef COH_MAP_EVENT_HPP 00008 #define COH_MAP_EVENT_HPP 00009 00010 #include "coherence/lang.ns" 00011 00012 #include "coherence/util/EventObject.hpp" 00013 #include "coherence/util/Listeners.hpp" 00014 00015 COH_OPEN_NAMESPACE2(coherence,util) 00016 00017 class MapListener; 00018 class ObservableMap; 00019 00020 /** 00021 * An event which indicates that the content of a map has changed: 00022 * <ul> 00023 * <li>an entry has been added</li> 00024 * <li>an entry has been removed</li> 00025 * <li>an entry has been changed</li> 00026 * </ul> 00027 * A MapEvent object is sent as an argument to the MapListener interface 00028 * methods. NULL values may be provided for the old and the new values. 00029 * 00030 * @author js 2008.06.03 00031 */ 00032 class COH_EXPORT MapEvent 00033 : public class_spec<MapEvent, 00034 extends<EventObject> > 00035 { 00036 friend class factory<MapEvent>; 00037 00038 // ----- constructors --------------------------------------------------- 00039 00040 protected: 00041 /** 00042 * Create a MapEvent. 00043 * 00044 * @param hMap the map on which the Event initially occurred 00045 * @param nId the events id (entry_inserted | entry_updated | 00046 * entry_deleted) 00047 * @param vKey the key into the map 00048 * @param vValueOld the old value (for update and delete events) 00049 * @param vValueNew the new value (for insert and update events) 00050 */ 00051 MapEvent(TypedHandle<ObservableMap> hMap, int32_t nId, Object::View vKey, 00052 Object::View vValueOld, Object::View vValueNew); 00053 00054 private: 00055 /** 00056 * Blocked copy constructor. 00057 */ 00058 MapEvent(const MapEvent&); 00059 00060 00061 // ----- MapEvent interface --------------------------------------------- 00062 00063 public: 00064 /** 00065 * Return an ObservableMap object on which this event has actually 00066 * occured. 00067 * 00068 * @return an ObservableMap object 00069 */ 00070 virtual TypedHandle<ObservableMap> getMap() const; 00071 00072 /** 00073 * Return this event's id. The event id is one of the entry_* 00074 * enumerated constants. 00075 * 00076 * @return an id 00077 */ 00078 virtual int32_t getId() const; 00079 00080 /** 00081 * Return a key associated with this event. 00082 * 00083 * @return a key 00084 */ 00085 virtual Object::View getKey() const; 00086 00087 /** 00088 * Return an old value associated with this event. 00089 * <p> 00090 * The old value represents a value deleted from or updated in a map. 00091 * It is always NULL for "insert" notifications. 00092 * 00093 * @return an old value 00094 */ 00095 virtual Object::View getOldValue() const; 00096 00097 /** 00098 * Return a new value associated with this event. 00099 * <p> 00100 * The new value represents a new value inserted into or updated in 00101 * a map. It is always NULL for "delete" notifications. 00102 * 00103 * @return a new value 00104 */ 00105 virtual Object::View getNewValue() const; 00106 00107 00108 // ----- Object interface ----------------------------------------------- 00109 00110 public: 00111 /** 00112 * {@inheritDoc} 00113 */ 00114 virtual TypedHandle<const String> toString() const; 00115 00116 00117 // ----- helper methods ------------------------------------------------- 00118 00119 public: 00120 /** 00121 * Dispatch this event to the specified listeners collection. 00122 * <p> 00123 * This call is equivalent to 00124 * <pre> 00125 * dispatch(listeners, true); 00126 * </pre> 00127 * 00128 * @param vListeners the listeners collection 00129 * 00130 * @throws ClassCastException if any of the targets is not 00131 * an instance of MapListener interface 00132 */ 00133 virtual void dispatch(Listeners::View vListeners) const; 00134 00135 /** 00136 * Dispatch this event to the specified listeners collection. 00137 * 00138 * @param vListeners the listeners collection 00139 * @param fStrict if true then any RuntimeException thrown by event 00140 * handlers stops all further event processing and 00141 * the exception is re-thrown; if false then all 00142 * exceptions are logged and the process continues 00143 * 00144 * @throws ClassCastException if any of the targets is not 00145 * an instance of MapListener interface 00146 */ 00147 virtual void dispatch(Listeners::View vListeners, 00148 bool fStrict) const; 00149 00150 /** 00151 * Dispatch this event to the specified MapListener. 00152 * 00153 * @param hListener the listener 00154 */ 00155 virtual void dispatch(TypedHandle<MapListener> hListener) const; 00156 00157 /** 00158 * Convert an event ID into a human-readable string. 00159 * 00160 * @param nId an event ID, one of the entry_* enumerated values 00161 * 00162 * @return a corresponding human-readable string, for example 00163 * "inserted" 00164 */ 00165 static String::View getDescription(int32_t nId); 00166 00167 using Describable::getDescription; 00168 00169 protected: 00170 /** 00171 * Return true if the provided MapListener should receive this 00172 * event. 00173 * 00174 * @param vListener the MapListener to dispatch this event to 00175 * 00176 * @return true if the provided MapListener should receive the event 00177 * @since 12.2.1.3.2 00178 */ 00179 virtual bool shouldDispatch(TypedHandle<const MapListener> vListener) const; 00180 00181 // ----- Describable interface ------------------------------------------ 00182 00183 public: 00184 /** 00185 * {@inheritDoc} 00186 */ 00187 virtual String::View getDescription() const; 00188 00189 00190 // ----- constants ------------------------------------------------------ 00191 00192 public: 00193 /** 00194 * This event indicates that an entry has been added to the map. 00195 */ 00196 static const int32_t entry_inserted = 1; 00197 00198 /** 00199 * This event indicates that an entry has been updated in the map. 00200 */ 00201 static const int32_t entry_updated = 2; 00202 00203 /** 00204 * This event indicates that an entry has been removed from the map. 00205 */ 00206 static const int32_t entry_deleted = 3; 00207 00208 00209 // ----- data members --------------------------------------------------- 00210 00211 protected: 00212 /** 00213 * The event's id. 00214 */ 00215 int32_t m_nId; 00216 00217 /** 00218 * A key. This is mutable because subclasses may lazily initialize 00219 * this value from an accessor. 00220 */ 00221 mutable MemberView<Object> m_voKey; 00222 00223 /** 00224 * A previous value. May be NULL if not known. This is mutable 00225 * because subclasses may lazily initialize this value from an 00226 * accessor. 00227 */ 00228 mutable MemberView<Object> m_voValueOld; 00229 00230 /** 00231 * A new value. May be NULL if not known. This is mutable because 00232 * subclasses may lazily initialize this value from an accessor. 00233 */ 00234 mutable MemberView<Object> m_voValueNew; 00235 }; 00236 00237 COH_CLOSE_NAMESPACE2 00238 00239 #endif // COH_MAP_EVENT_HPP 00240