00001 /* 00002 * MapEventFilter.hpp 00003 * 00004 * Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. 00005 * 00006 * Oracle is a registered trademarks of Oracle Corporation and/or its 00007 * affiliates. 00008 * 00009 * This software is the confidential and proprietary information of Oracle 00010 * Corporation. You shall not disclose such confidential and proprietary 00011 * information and shall use it only in accordance with the terms of the 00012 * license agreement you entered into with Oracle. 00013 * 00014 * This notice may not be removed or altered. 00015 */ 00016 #ifndef COH_MAP_EVENT_FILTER_HPP 00017 #define COH_MAP_EVENT_FILTER_HPP 00018 00019 #include "coherence/lang.ns" 00020 00021 #include "coherence/io/pof/PofReader.hpp" 00022 #include "coherence/io/pof/PofWriter.hpp" 00023 #include "coherence/io/pof/PortableObject.hpp" 00024 #include "coherence/util/Describable.hpp" 00025 #include "coherence/util/Filter.hpp" 00026 00027 COH_OPEN_NAMESPACE3(coherence,util,filter) 00028 00029 using coherence::io::pof::PofReader; 00030 using coherence::io::pof::PofWriter; 00031 using coherence::io::pof::PortableObject; 00032 00033 00034 /** 00035 * Filter which evaluates the content of a MapEvent object according to the 00036 * specified criteria. This filter is intended to be used by various 00037 * ObservableMap listeners that are interested in particular subsets 00038 * of MapEvent notifications emitted by the map. 00039 * 00040 * Usage examples: 00041 * <ul> 00042 * <li>a filter that evaluates to true if an Employee object is inserted into 00043 * a cache with a value of Married property set to true. 00044 * <pre> 00045 * MapEventFilter::create(MapEventFilter.E_INSERT, 00046 * EqualsFilter::create(ReflectionExtractor::create("isMarried"), 00047 * Boolean::create(true)); 00048 * </pre> 00049 * <li>a filter that evaluates to true if any object is removed from a cache. 00050 * <pre> 00051 * MapEventFilter::create(MapEventFilter::E_DELETED); 00052 * </pre> 00053 * <li>a filter that evaluates to true if there is an update to an Employee 00054 * object where either an old or new value of LastName property equals to 00055 * "Smith" 00056 * <pre> 00057 * MapEventFilter::create(MapEventFilter::E_UPDATE, 00058 * EqualsFilter::create(ReflectionExtractor::create("LastName"), 00059 * String::create("Smith"))); 00060 * </pre> 00061 * <li>a filter that is used to keep a cached keySet result based on some map 00062 * filter up-to-date. 00063 * <pre> 00064 * Set::View setKeys = HashSet::create(); 00065 * Filter::View filterEvt = MapEventFilter::create(filterMap); 00066 * MapListener::Handle listener = MapListener::create(); 00067 * map.addMapListener(listener, filterEvt, true); 00068 * setKeys.addAll(map.keySet(filterMap)); 00069 * </pre> 00070 * </ul> 00071 * 00072 * see ValueChangeEventFilter 00073 * 00074 * @author djl 2008.05.19 00075 */ 00076 class COH_EXPORT MapEventFilter 00077 : public class_spec<MapEventFilter, 00078 extends<Describable>, 00079 implements<PortableObject, Filter> > 00080 { 00081 friend class factory<MapEventFilter>; 00082 00083 // ----- constructors --------------------------------------------------- 00084 00085 protected: 00086 /** 00087 * Default constructor (necessary for the PortableObject interface). 00088 */ 00089 MapEventFilter(); 00090 00091 /** 00092 * Construct a MapEventFilter that evaluates MapEvent objects that 00093 * would affect the results of a keySet filter issued by a previous 00094 * call to 00095 * coherence::util::QueryMap::keySet(coherence::util::Filter::View). 00096 * It is possible to easily implement <i>continuous query</i> 00097 * functionality. 00098 * 00099 * Using this constructor is equivalent to: 00100 * <tt> 00101 * MapEventFilter::create(e_keyset, vFilter); 00102 * </tt> 00103 * 00104 * @param vFilter the filter passed previously to a keySet() query 00105 * method 00106 */ 00107 MapEventFilter(Filter::View vFilter); 00108 00109 /** 00110 * Construct a MapEventFilter that evaluates MapEvent objects 00111 * based on the specified combination of event types. 00112 * 00113 * @param nMask combination of any of the e_* values 00114 * @param vFilter (optional) the filter used for evaluating event 00115 * values 00116 */ 00117 MapEventFilter(int32_t nMask, Filter::View vFilter = NULL); 00118 00119 private: 00120 /** 00121 * Blocked copy constructor. 00122 */ 00123 MapEventFilter(const MapEventFilter&); 00124 00125 00126 // ----- Filter interface ----------------------------------------------- 00127 00128 public: 00129 /** 00130 * {@inheritDoc} 00131 */ 00132 virtual bool evaluate(Object::View v) const; 00133 00134 00135 // ----- PortableObject interface --------------------------------------- 00136 00137 public: 00138 /** 00139 * {@inheritDoc} 00140 */ 00141 virtual void readExternal(PofReader::Handle hIn); 00142 00143 /** 00144 * {@inheritDoc} 00145 */ 00146 virtual void writeExternal(PofWriter::Handle hOut) const; 00147 00148 00149 // ----- Object interface ----------------------------------------------- 00150 00151 public: 00152 /** 00153 * {@inheritDoc} 00154 */ 00155 virtual bool equals(Object::View v) const; 00156 00157 /** 00158 * {@inheritDoc} 00159 */ 00160 virtual size32_t hashCode() const; 00161 00162 /** 00163 * {@inheritDoc} 00164 */ 00165 virtual TypedHandle<const String> toString() const; 00166 00167 00168 // ----- Describable interface ------------------------------------------ 00169 00170 public: 00171 /** 00172 * {@inheritDoc} 00173 */ 00174 virtual String::View getDescription() const; 00175 00176 00177 // ----- data member accessors ------------------------------------------ 00178 00179 public: 00180 /** 00181 * Obtain the event mask. The mask value is concatenation of any of 00182 * the E_* values. 00183 * 00184 * @return the event mask 00185 */ 00186 virtual int32_t getEventMask() const; 00187 00188 00189 /** 00190 * Obtain the Filter object used to evaluate the event value(s). 00191 * 00192 * @return the filter used to evaluate the event value(s) 00193 */ 00194 virtual Filter::View getFilter() const; 00195 00196 // ----- constants ------------------------------------------------------ 00197 00198 public: 00199 /** 00200 * This value indicates that MapEvent#entry_inserted 00201 * entry_inserted} events should be evaluated. The event will be fired 00202 * if there is no filter specified or the filter evaluates to true 00203 * for a new value. 00204 */ 00205 static const int32_t e_inserted = 0x0001; 00206 00207 /** 00208 * This value indicates that MapEvent#entry_updated entry_updated 00209 * events should be evaluated. The event will be fired if there is no 00210 * filter specified or the filter evaluates to true when applied to 00211 * either old or new value. 00212 */ 00213 static const int32_t e_updated = 0x0002; 00214 00215 /** 00216 * This value indicates that MapEvent#entry_deleted entry_deleted 00217 * events should be evaluated. The event will be fired if there is no 00218 * filter specified or the filter evaluates to true for an old value. 00219 */ 00220 static const int32_t e_deleted = 0x0004; 00221 00222 /** 00223 * This value indicates that MapEvent#entry_updated entry_updated 00224 * events should be evaluated, but only if filter evaluation is false 00225 * for the old value and true for the new value. This corresponds to 00226 * an item that was not in a keySet filter result changing such that 00227 * it would now be in that keySet filter result. 00228 */ 00229 static const int32_t e_updated_entered = 0x0008; 00230 00231 /** 00232 * This value indicates that MapEvent#entry_updated entry_updated 00233 * events should be evaluated, but only if filter evaluation is true 00234 * for the old value and false for the new value. This corresponds to 00235 * an item that was in a keySet filter result changing such that it 00236 * would no longer be in that keySet filter result. 00237 */ 00238 static const int32_t e_updated_left = 0x0010; 00239 00240 /** 00241 * This value indicates that MapEvent#entry_updated entry_updated 00242 * events should be evaluated, but only if filter evaluation is true 00243 * for both the old and the new value. This corresponds to an item 00244 * that was in a keySet filter result changing but not leaving the 00245 * keySet filter result. 00246 */ 00247 static const int32_t e_updated_within = 0x0020; 00248 00249 /** 00250 * This value indicates that all events should be evaluated. 00251 */ 00252 static const int32_t e_all = e_inserted | e_updated | 00253 e_deleted; 00254 00255 /** 00256 * This value indicates that all events that would affect the result 00257 * of a coherence::util::QueryMap::keySet(coherence::util::Filter) 00258 * query should be evaluated. 00259 */ 00260 static const int32_t e_keyset = e_inserted | e_deleted | 00261 e_updated_entered | 00262 e_updated_left; 00263 /** 00264 * Event id to event mask translation. 00265 * 00266 * @param iEvent the event index 00267 * 00268 * @return the translated event mask 00269 */ 00270 static int32_t getMask(size32_t iEvent); 00271 00272 00273 // ----- data members --------------------------------------------------- 00274 00275 protected: 00276 /** 00277 * The event mask. 00278 */ 00279 int32_t m_nMask; 00280 00281 /** 00282 * The event value(s) filter. 00283 */ 00284 FinalView<Filter> f_vFilter; 00285 }; 00286 00287 COH_CLOSE_NAMESPACE3 00288 00289 #endif // COH_MAP_EVENT_FILTER_HPP