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

F79659-03

coherence/util/transformer/ExtractorEventTransformer.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_EXTRACTOR_EVENT_TRANSFORMER_HPP
00008 #define COH_EXTRACTOR_EVENT_TRANSFORMER_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/MapEvent.hpp"
00016 #include "coherence/util/MapEventTransformer.hpp"
00017 #include "coherence/util/ValueExtractor.hpp"
00018 
00019 COH_OPEN_NAMESPACE3(coherence,util,transformer)
00020 
00021 using coherence::io::pof::PofReader;
00022 using coherence::io::pof::PofWriter;
00023 using coherence::io::pof::PortableObject;
00024 
00025 
00026 /**
00027 * ExtractorEventTransformer is a special purpose MapEventTransformer
00028 * implementation that transforms emitted events, extracting one or more
00029 * properties from either the OldValue or the NewValue. This transformation
00030 * will generally result in the change of the values' data type.
00031 * <p/>
00032 * Example: the following code will register a listener to receive events only
00033 * if the value of the AccountBalance property changes. The transformed
00034 * event's NewValue will be a List containing the LastTransactionTime and
00035 * AccountBalance properties. The OldValue will always be null.
00036 * <pre>
00037 *    Filter::View vFilter =
00038 *       ValueChangeEventFilter::create("getAccountBalance");
00039 *    ValueExtractor::View vExtractor =
00040 *       MultiExtractor::create(MultiExtractor::createExtractors(
00041 *           "getLastTransactionTime,getAccountBalance"));
00042 *    MapEventTransformer::Handle hTransformer =
00043 *       ExtractorEventTransformer::create(NULL, vExtractor);
00044 *
00045 *    cache->addMapListener(listener,
00046 *       MapEventTransformerFilter::create(vFilter, hTransformer), false);
00047 * </pre>
00048 *
00049 * @author djl  2008.06.17
00050 */
00051 class COH_EXPORT ExtractorEventTransformer
00052     : public class_spec<ExtractorEventTransformer,
00053         extends<Object>,
00054         implements<PortableObject, MapEventTransformer> >
00055     {
00056     friend class factory<ExtractorEventTransformer>;
00057 
00058     // ----- constructors ---------------------------------------------------
00059 
00060     protected:
00061         /**
00062         * Default constructor (necessary for the PortableObject interface).
00063         */
00064         ExtractorEventTransformer();
00065 
00066         /**
00067         * Construct a ExtractorEventTransformer that transforms MapEvent
00068         * values based on the specified extractor.
00069         *
00070         * Note: The specified extractor will be applied to both old and new
00071         * values.
00072         *
00073         * @param vExtractor  ValueExtractor to extract MapEvent values
00074         */
00075         ExtractorEventTransformer(ValueExtractor::View vExtractor);
00076 
00077         /**
00078         * Construct a ExtractorEventTransformer that transforms MapEvent
00079         * values based on the specified extractors. Passing null indicates
00080         * that the corresponding values should be skipped completely.
00081         *
00082         * @param vExtractorOld  extractor to extract the OldValue property(s)
00083         * @param vExtractorNew  extractor to extract the NewValue property(s)
00084         */
00085         ExtractorEventTransformer(ValueExtractor::View vExtractorOld,
00086                 ValueExtractor::View vExtractorNew);
00087 
00088 
00089     // ----- MapEventTransformer interface ----------------------------------
00090 
00091     public:
00092         /**
00093         * {@inheritDoc}
00094         */
00095         virtual MapEvent::Handle transform(MapEvent::Handle hEvent) const;
00096 
00097 
00098    // ----- PortableObject interface ---------------------------------------
00099 
00100     public:
00101         /**
00102         * {@inheritDoc}
00103         */
00104         virtual void readExternal(PofReader::Handle hIn);
00105 
00106         /**
00107         * {@inheritDoc}
00108         */
00109         virtual void writeExternal(PofWriter::Handle hOut) const;
00110 
00111 
00112     // ----- Object interface -----------------------------------------------
00113 
00114     public:
00115         /**
00116         * {@inheritDoc}
00117         */
00118         virtual bool equals(Object::View v) const;
00119 
00120         /**
00121         * {@inheritDoc}
00122         */
00123         virtual size32_t hashCode() const;
00124 
00125         /**
00126         * {@inheritDoc}
00127         */
00128         virtual TypedHandle<const String> toString() const;
00129 
00130 
00131     // ----- data member accessors ------------------------------------------
00132 
00133     public:
00134         /**
00135         * Return a ValueExtractor used to transfrom the event's OldValue.
00136         *
00137         * @return an extractor from the OldValue
00138         */
00139         virtual ValueExtractor::View getOldValueExtractor() const;
00140 
00141         /**
00142         * Return a ValueExtractor used to transfrom the event's NewValue.
00143         *
00144         * @return an extractor from the NewValue
00145         */
00146         virtual ValueExtractor::View getNewValueExtractor() const;
00147 
00148 
00149     // ----- data members ---------------------------------------------------
00150 
00151     private:
00152         /**
00153         * The OldValueExtractor.
00154         */
00155         FinalView<ValueExtractor> f_vExtractorOld;
00156 
00157         /**
00158         * The NewValueExtractor.
00159         */
00160         FinalView<ValueExtractor> f_vExtractorNew;
00161     };
00162 
00163 COH_CLOSE_NAMESPACE3
00164 
00165 #endif // COH_EXTRACTOR_EVENT_TRANSFORMER_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.