00001 /* 00002 * AbstractAggregator.hpp 00003 * 00004 * Copyright (c) 2000, 2011, 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 // ----- AbstractAggregator Interface ---------------------------------- 00061 00062 protected: 00063 /** 00064 * Initialize the aggregation result. 00065 * 00066 * @param fFinal true is passed if the aggregation process that is 00067 * being initialized must produce a final aggregation 00068 * result; this will only be false if a parallel 00069 * approach is being used and the initial (partial) 00070 * aggregation process is being initialized 00071 */ 00072 virtual void init(bool fFinal) = 0; 00073 00074 /** 00075 * Incorporate one aggregatable value into the result. 00076 * 00077 * If the <tt>fFinal</tt> parameter is true, the given object is a 00078 * partial result (returned by an individual parallel aggregator) that 00079 * should be incorporated into the final result; otherwise, the object 00080 * is a value extracted from an 00081 * coherence::util::InvocableMap::Entry. 00082 * 00083 * @param vO the value to incorporate into the aggregated result 00084 * @param fFinal true to indicate that the given object is a partial 00085 * result returned by a parallel aggregator 00086 */ 00087 virtual void process(Object::View vO, bool fFinal) = 0; 00088 00089 /** 00090 * Obtain the result of the aggregation. 00091 * 00092 * If the <tt>fFinal</tt> parameter is true, the returned object must 00093 * be the final result of the aggregation; otherwise, the returned 00094 * object will be treated as a partial result that should be 00095 * incorporated into the final result. 00096 * 00097 * @param fFinal true to indicate that the final result of the 00098 * aggregation process should be returned; this will 00099 * only be false if a parallel approach is being used 00100 * 00101 * @return the result of the aggregation process 00102 */ 00103 virtual Object::Holder finalizeResult(bool fFinal) = 0; 00104 00105 00106 // ----- InvocableMap::EntryAggregator interface ------------------------ 00107 00108 public: 00109 /** 00110 * {@inheritDoc} 00111 */ 00112 virtual Object::Holder aggregate(Set::View vSetEntries); 00113 00114 /** 00115 * {@inheritDoc} 00116 */ 00117 virtual InvocableMap::EntryAggregator::Handle 00118 getParallelAggregator(); 00119 00120 /** 00121 * {@inheritDoc} 00122 */ 00123 virtual Object::Holder aggregateResults( 00124 Collection::View vCollResults); 00125 00126 00127 // ----- PortableObject interface --------------------------------------- 00128 00129 public: 00130 /** 00131 * {@inheritDoc} 00132 */ 00133 virtual void readExternal(PofReader::Handle hIn); 00134 00135 /** 00136 * {@inheritDoc} 00137 */ 00138 virtual void writeExternal(PofWriter::Handle hOut) const; 00139 00140 00141 // ----- Object interface ----------------------------------------------- 00142 00143 public: 00144 /** 00145 * {@inheritDoc} 00146 */ 00147 virtual bool equals(Object::View v) const; 00148 00149 /** 00150 * {@inheritDoc} 00151 */ 00152 virtual size32_t hashCode() const; 00153 00154 /** 00155 * {@inheritDoc} 00156 */ 00157 virtual void toStream(std::ostream& out) const; 00158 00159 00160 // ----- data member accessors ------------------------------------------ 00161 00162 public: 00163 /** 00164 * Determine the ValueExtractor whose values this aggregator is 00165 * aggregating. 00166 * 00167 * @return the ValueExtractor used by this aggregator 00168 */ 00169 virtual ValueExtractor::View getValueExtractor() const; 00170 00171 00172 // ----- data members --------------------------------------------------- 00173 00174 protected: 00175 /** 00176 * Set to true if this aggregator realizes that it is going to be used 00177 * in parallel. 00178 */ 00179 bool m_fParallel; 00180 00181 /** 00182 * The ValueExtractor that obtains the value to aggregate from the 00183 * value that is stored in the Map. 00184 */ 00185 MemberView<ValueExtractor> m_vExtractor; 00186 }; 00187 00188 COH_CLOSE_NAMESPACE3 00189 00190 #endif // COH_ABSTRACT_AGGREGATOR_HPP