00001 /* 00002 * AbstractEntryBundler.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_ENTRY_BUNDLER_HPP 00017 #define COH_ABSTRACT_ENTRY_BUNDLER_HPP 00018 00019 #include "coherence/lang.ns" 00020 00021 #include "coherence/net/cache/AbstractBundler.hpp" 00022 00023 #include "coherence/util/AtomicCounter.hpp" 00024 #include "coherence/util/Collections.hpp" 00025 #include "coherence/util/Map.hpp" 00026 #include "coherence/util/SafeHashMap.hpp" 00027 00028 COH_OPEN_NAMESPACE3(coherence,net,cache) 00029 00030 using coherence::util::AtomicCounter; 00031 using coherence::util::Collections; 00032 using coherence::util::Map; 00033 using coherence::util::SafeHashMap; 00034 00035 /** 00036 * An abstract entry-based bundler serves as a base for NamedCache::put() 00037 * operation bundling. 00038 * 00039 * @author gg 2007.01.28 00040 * @author lh 2012.05.06 00041 * @since Coherence 12.1.2 00042 */ 00043 class COH_EXPORT AbstractEntryBundler 00044 : public abstract_spec<AbstractEntryBundler, 00045 extends<AbstractBundler> > 00046 { 00047 // ----- handle definitions (needed for nested classes) ----------------- 00048 00049 public: 00050 typedef this_spec::Handle Handle; 00051 typedef this_spec::View View; 00052 typedef this_spec::Holder Holder; 00053 00054 // ----- constructors --------------------------------------------------- 00055 00056 protected: 00057 /** 00058 * @internal 00059 */ 00060 AbstractEntryBundler(); 00061 00062 private: 00063 /** 00064 * Blocked copy constructor. 00065 */ 00066 AbstractEntryBundler(const AbstractEntryBundler&); 00067 00068 // ----- bundling support ----------------------------------------------- 00069 00070 public: 00071 /** 00072 * Process the specified entry in a most optimal way according to the 00073 * bundle settings. 00074 * 00075 * @param vKey the entry key 00076 * @param ohValue the entry value 00077 */ 00078 virtual void process(Object::View vKey, Object::Holder ohValue); 00079 00080 /** 00081 * Process a colllection of entries in a most optimal way according to the 00082 * bundle settings. 00083 * 00084 * @param vMap the collection of entries to process 00085 */ 00086 virtual void processAll(Map::View vMap); 00087 00088 // ----- subclassing support -------------------------------------------- 00089 00090 protected: 00091 /** 00092 * The bundle operation to be performed against a collected map of entries 00093 * by the concrete AbstractEntryBundler implementations. If an exception 00094 * occurs during bundle operation, it will be repeated using singleton maps. 00095 * 00096 * @param vMapEntries a map to perform the bundled operation for 00097 */ 00098 virtual void bundle(Map::View vMapEntries) = 0; 00099 00100 // ----- AbstractBundler methods ---------------------------------------- 00101 00102 /** 00103 * {@inheritDoc} 00104 */ 00105 virtual AbstractBundler::Bundle::Handle instantiateBundle(); 00106 00107 // ----- inner class: Bundle -------------------------------------------- 00108 00109 /* 00110 * Bundle represents a unit of optimized execution. 00111 */ 00112 protected: 00113 class COH_EXPORT Bundle 00114 : public class_spec<Bundle, 00115 extends<AbstractBundler::Bundle> > 00116 { 00117 friend class factory<AbstractEntryBundler::Bundle>; 00118 00119 protected: 00120 /** 00121 * Default constructor. 00122 * 00123 * @param hBundler the AbstructBundler 00124 */ 00125 Bundle(AbstractBundler::Handle hBundler); 00126 00127 // ----- bundling support --------------------------------------- 00128 00129 public: 00130 /** 00131 * Add the specified entry to the Bundle. 00132 * 00133 * <b>Note:</b> a call to this method must be externally synchronized 00134 * for this Bundle object. 00135 * 00136 * @param vKey the entry key 00137 * @param ohValue the entry value 00138 * 00139 * @return true if this Bundle was empty prior to this call 00140 */ 00141 virtual bool add(Object::View vKey, Object::Holder ohValue); 00142 00143 /** 00144 * Add the specified collection of entries to the Bundle. 00145 * 00146 * <b>Note:</b> a call to this method must be externally synchronized 00147 * for this Bundle object. 00148 * 00149 * @param vMap the collection of entries 00150 * 00151 * @return true if this Bundle was empty prior to this call 00152 */ 00153 virtual bool addAll(Map::View vMap); 00154 00155 /** 00156 * Process the specified entry according to this Bundle state. 00157 * 00158 * @param fBurst true if this thread is supposed to perform an actual 00159 * bundled operation (burst); false otherwise 00160 * @param vKey the entry key 00161 * @param ohValue the entry value 00162 */ 00163 virtual void process(bool fBurst, Object::View vKey, Object::Holder ohValue); 00164 00165 /** 00166 * Process the specified collection of entries according to this Bundle 00167 * state. 00168 * 00169 * @param fBurst true if this thread is supposed to perform an actual 00170 * bundled operation (burst); false otherwise 00171 * @param vMap the collection of entries 00172 */ 00173 virtual void processAll(bool fBurst, Map::View vMap); 00174 00175 // ----- AbstractBundler::Bundle methods--------------------- 00176 00177 /** 00178 * {@inheritDoc} 00179 */ 00180 virtual int32_t getBundleSize() const; 00181 00182 /** 00183 * {@inheritDoc} 00184 */ 00185 using AbstractBundler::Bundle::ensureResults; 00186 00187 /** 00188 * {@inheritDoc} 00189 */ 00190 virtual void ensureResults(); 00191 00192 /** 00193 * {@inheritDoc} 00194 */ 00195 virtual bool releaseThread(); 00196 00197 // ----- data fileds -------------------------------------------- 00198 00199 private: 00200 /** 00201 * This bundle content. 00202 */ 00203 FinalHandle<Map> f_hMapEntries; 00204 }; 00205 }; 00206 00207 COH_CLOSE_NAMESPACE3 00208 00209 #endif // COH_ABSTRACT_ENTRY_BUNDLER_HPP