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

F79659-03

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