C++ Client API Reference for Oracle Coherence
14c (14.1.2.0.0)

F79659-03

coherence/util/filter/MapEventFilter.hpp

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