Oracle Coherence for C++ API
Release 3.6.0.0

E15728-01

coherence/util/filter/FilterTrigger.hpp

00001 /*
00002 * FilterTrigger.hpp
00003 *
00004 * Copyright (c) 2000, 2010, 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_FILTER_TRIGGER_HPP
00017 #define COH_FILTER_TRIGGER_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/Filter.hpp"
00025 #include "coherence/util/MapTrigger.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 * A generic Filter-based MapTrigger implementation. If an evaluation of the
00036 * coherence::util::MapTrigger::Entry object representing a pending
00037 * change fails (returns false), then one of the following actions is taken:
00038 * <ul>
00039 *   <li> ACTION_ROLLBACK - an IllegalArgumentException is thrown by the
00040 *        trigger to reject the operation that would result in this change
00041 *        (default);
00042 *   <li> ACTION_IGNORE - the change is ignored and the Entry's value is reset
00043 *        to the original value returned by the
00044 *        coherence::util::MapTrigger::Entry#getOriginalValue() method;
00045 *   <li> ACTION_REMOVE - the entry is removed from the underlying backing map
00046 *        using the coherence::util::InvocableMap::Entry#remove(boolean) call.
00047 * </ul>
00048 *
00049 * Note: This trigger never prevent entries from being removed.
00050 *
00051 * @author djl  2008.05.22
00052 */
00053 class COH_EXPORT FilterTrigger
00054     : public class_spec<FilterTrigger,
00055         extends<Object>,
00056         implements<PortableObject, MapTrigger> >
00057     {
00058     friend class factory<FilterTrigger>;
00059 
00060     // ----- constructors ---------------------------------------------------
00061 
00062     protected:
00063         /**
00064         * Default constructor (necessary for the PortableObject interface).
00065         */
00066         FilterTrigger();
00067 
00068         /**
00069         * Construct a FilterTrigger based on the specified Filter object and
00070         * the action constant.
00071         *
00072         * @param vFilter  the underlying Filter
00073         * @param nAction  one of the ACTION_* constants
00074         */
00075         FilterTrigger(Filter::View vFilter, int32_t nAction);
00076 
00077 
00078     // ----- MapTrigger interface -------------------------------------------
00079 
00080     public:
00081         /**
00082         * {@inheritDoc}
00083         */
00084         virtual void process(MapTrigger::Entry::Handle vEntry);
00085 
00086 
00087    // ----- PortableObject interface ---------------------------------------
00088 
00089      public:
00090         /**
00091         * {@inheritDoc}
00092         */
00093         virtual void readExternal(PofReader::Handle hIn);
00094 
00095         /**
00096         * {@inheritDoc}
00097         */
00098         virtual void writeExternal(PofWriter::Handle hOut) const;
00099 
00100 
00101     // ----- Object interface -----------------------------------------------
00102 
00103     public:
00104         /**
00105         * {@inheritDoc}
00106         */
00107         virtual bool equals(Object::View v) const;
00108 
00109         /**
00110         * {@inheritDoc}
00111         */
00112         virtual size32_t hashCode() const;
00113 
00114         /**
00115         * {@inheritDoc}
00116         */
00117         virtual void toStream(std::ostream& out) const;
00118 
00119 
00120     // ----- data member accessors ------------------------------------------
00121 
00122     public:
00123         /**
00124         * Obtain the underlying Filter.
00125         *
00126         * @return the underlying Filter object
00127         */
00128         virtual Filter::View getFilter() const;
00129 
00130         /**
00131         * Obtain the action code for this FilterTrigger.
00132         *
00133         * @return one of the ACTION_* constants
00134         */
00135         virtual int32_t getAction() const;
00136 
00137 
00138     // ----- constants ------------------------------------------------------
00139 
00140     public:
00141         /**
00142         * Evaluation failure results in an IllegalArgumentException thrown
00143         * by the trigger.
00144         */
00145         static const int32_t ACTION_ROLLBACK = 0;
00146 
00147         /**
00148         * Evaluation failure results in restoring the original Entry's value.
00149         */
00150         static const int32_t ACTION_IGNORE = 1;
00151 
00152         /**
00153         * Evaluation failure results in a removal of the entry.
00154         */
00155         static const int32_t ACTION_REMOVE = 2;
00156 
00157 
00158     // ----- data members ---------------------------------------------------
00159 
00160     protected:
00161         /**
00162         * The underlying filter.
00163         */
00164         MemberView<Filter> m_vFilter;
00165 
00166         /**
00167         * The action code.
00168         */
00169         int32_t m_nAction;
00170     };
00171 
00172 COH_CLOSE_NAMESPACE3
00173 
00174 #endif // COH_FILTER_TRIGGER_HPP
Copyright © 2000, 2010, Oracle and/or its affiliates. All rights reserved.