00001 /* 00002 * AbstractAggregator.hpp 00003 * 00004 * Copyright (c) 2000, 2014, 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_ABSTRACT_AGGREGATOR_HPP 00017 #define COH_ABSTRACT_AGGREGATOR_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/InvocableMap.hpp" 00025 #include "coherence/util/ValueExtractor.hpp" 00026 00027 COH_OPEN_NAMESPACE3(coherence,util,aggregator) 00028 00029 using coherence::io::pof::PofReader; 00030 using coherence::io::pof::PofWriter; 00031 using coherence::io::pof::PortableObject; 00032 00033 00034 /** 00035 * Abstract base class implementation of 00036 * coherence::util::InvocableMap::EntryAggregator that supports 00037 * parallel aggregation. 00038 * 00039 * @author djl 2008.05.09 00040 */ 00041 class COH_EXPORT AbstractAggregator 00042 : public abstract_spec<AbstractAggregator, 00043 extends<Object>, 00044 implements<PortableObject, InvocableMap::ParallelAwareAggregator> > 00045 { 00046 // ----- constructors --------------------------------------------------- 00047 00048 protected: 00049 /** 00050 * @internal 00051 */ 00052 AbstractAggregator(); 00053 00054 /** 00055 * @internal 00056 */ 00057 AbstractAggregator(ValueExtractor::View vExtractor); 00058 00059 /** 00060 * Construct an AbstractAggregator that will aggregate values 00061 * extracted from a set of InvocableMap::Entry objects. 00062 * 00063 * @param vsMethod the name of the method that could be invoked 00064 * via reflection and that returns values to 00065 * aggregate; this parameter can also be a 00066 * dot-delimited sequence of method names which 00067 * would result in an aggregator based 00068 * on the ChainedExtractor that is based on an 00069 * array of corresponding ReflectionExtractor 00070 * objects 00071 * 00072 * @since Coherence 12.1.2 00073 */ 00074 AbstractAggregator(String::View vsMethod); 00075 00076 private: 00077 /** 00078 * Blocked copy constructor. 00079 */ 00080 AbstractAggregator(const AbstractAggregator&); 00081 00082 00083 // ----- AbstractAggregator Interface ---------------------------------- 00084 00085 protected: 00086 /** 00087 * Initialize the aggregation result. 00088 * 00089 * @param fFinal true is passed if the aggregation process that is 00090 * being initialized must produce a final aggregation 00091 * result; this will only be false if a parallel 00092 * approach is being used and the initial (partial) 00093 * aggregation process is being initialized 00094 */ 00095 virtual void init(bool fFinal) = 0; 00096 00097 /** 00098 * Incorporate one aggregatable value into the result. 00099 * 00100 * If the <tt>fFinal</tt> parameter is true, the given object is a 00101 * partial result (returned by an individual parallel aggregator) that 00102 * should be incorporated into the final result; otherwise, the object 00103 * is a value extracted from an 00104 * coherence::util::InvocableMap::Entry. 00105 * 00106 * @param vO the value to incorporate into the aggregated result 00107 * @param fFinal true to indicate that the given object is a partial 00108 * result returned by a parallel aggregator 00109 */ 00110 virtual void process(Object::View vO, bool fFinal) = 0; 00111 00112 /** 00113 * Obtain the result of the aggregation. 00114 * 00115 * If the <tt>fFinal</tt> parameter is true, the returned object must 00116 * be the final result of the aggregation; otherwise, the returned 00117 * object will be treated as a partial result that should be 00118 * incorporated into the final result. 00119 * 00120 * @param fFinal true to indicate that the final result of the 00121 * aggregation process should be returned; this will 00122 * only be false if a parallel approach is being used 00123 * 00124 * @return the result of the aggregation process 00125 */ 00126 virtual Object::Holder finalizeResult(bool fFinal) = 0; 00127 00128 00129 // ----- InvocableMap::EntryAggregator interface ------------------------ 00130 00131 public: 00132 /** 00133 * {@inheritDoc} 00134 */ 00135 virtual Object::Holder aggregate(Set::View vSetEntries); 00136 00137 /** 00138 * {@inheritDoc} 00139 */ 00140 virtual InvocableMap::EntryAggregator::Handle 00141 getParallelAggregator(); 00142 00143 /** 00144 * {@inheritDoc} 00145 */ 00146 virtual Object::Holder aggregateResults( 00147 Collection::View vCollResults); 00148 00149 00150 // ----- PortableObject interface --------------------------------------- 00151 00152 public: 00153 /** 00154 * {@inheritDoc} 00155 */ 00156 virtual void readExternal(PofReader::Handle hIn); 00157 00158 /** 00159 * {@inheritDoc} 00160 */ 00161 virtual void writeExternal(PofWriter::Handle hOut) const; 00162 00163 00164 // ----- Object interface ----------------------------------------------- 00165 00166 public: 00167 /** 00168 * {@inheritDoc} 00169 */ 00170 virtual bool equals(Object::View v) const; 00171 00172 /** 00173 * {@inheritDoc} 00174 */ 00175 virtual size32_t hashCode() const; 00176 00177 /** 00178 * {@inheritDoc} 00179 */ 00180 virtual void toStream(std::ostream& out) const; 00181 00182 00183 // ----- data member accessors ------------------------------------------ 00184 00185 public: 00186 /** 00187 * Determine the ValueExtractor whose values this aggregator is 00188 * aggregating. 00189 * 00190 * @return the ValueExtractor used by this aggregator 00191 */ 00192 virtual ValueExtractor::View getValueExtractor() const; 00193 00194 00195 // ----- data members --------------------------------------------------- 00196 00197 protected: 00198 /** 00199 * Set to true if this aggregator realizes that it is going to be used 00200 * in parallel. 00201 */ 00202 bool m_fParallel; 00203 00204 /** 00205 * The ValueExtractor that obtains the value to aggregate from the 00206 * value that is stored in the Map. 00207 */ 00208 FinalView<ValueExtractor> f_vExtractor; 00209 }; 00210 00211 COH_CLOSE_NAMESPACE3 00212 00213 #endif // COH_ABSTRACT_AGGREGATOR_HPP