Oracle Fusion Middleware C++ API Reference for Oracle Coherence
12c (12.1.2)

E26041-01

coherence/net/partition/PartitionSet.hpp

00001 /*
00002 * PartitionSet.hpp
00003 *
00004 * Copyright (c) 2000, 2013, 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_PARTITION_SET_HPP
00017 #define COH_PARTITION_SET_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 
00025 COH_OPEN_NAMESPACE3(coherence,net,partition)
00026 
00027 using coherence::io::pof::PofReader;
00028 using coherence::io::pof::PofWriter;
00029 using coherence::io::pof::PortableObject;
00030 
00031 
00032 /**
00033 * PartitionSet is a light-weight data structure that represents a set of
00034 * partitions that are used in parallel processing. This set quite often
00035 * accompanies a result of partial parallel execution and is used to determine
00036 * whether or not the entire set of partitions was successfully processed.
00037 * 
00038 * Note that all PartitionSet operations that take another set as an argument
00039 * assume that both sets have the same partition count.
00040 *
00041 * @since Coherence 3.7.1 
00042 * @author tb  2011.08.12
00043 */
00044 class COH_EXPORT PartitionSet
00045     : public class_spec<PartitionSet,
00046         extends<Object>,
00047         implements<PortableObject> >
00048     {
00049     friend class factory<PartitionSet>;
00050 
00051     // ----- Format definition ----------------------------------------------
00052 
00053     public:
00054         /**
00055         * Serialization format indicator.
00056         */
00057         typedef enum
00058             {
00059             /**
00060             * Indicates that no partitions are marked; MARKED_NONE requires 
00061             * no additional data.
00062             */
00063             marked_none = 0,
00064 
00065             /**
00066             * Indicates that a small number of partitions are marked; 
00067             * followed by stream of packed integers indicating gaps between 
00068             * each marked partition, terminated with a -1.
00069             */
00070             marked_few = 1,
00071             
00072             /**
00073             * Indicates that a large number of partitions are marked; 
00074             * followed by a sequence of 64-bit values sufficient to represent 
00075             * the cardinality of the PartitionSet.
00076             */
00077             marked_many = 2,
00078             
00079             /**
00080             * Indicates that all partitions are marked; MARKED_ALL requires 
00081             * no additional data.
00082             */
00083             marked_all = 3
00084             } Format;
00085 
00086 
00087     // ----- Constructors ---------------------------------------------------
00088 
00089     public:
00090         /**
00091         * Default constructor.
00092         */
00093         PartitionSet();
00094 
00095 
00096     // ----- pseudo Set operations ------------------------------------------
00097 
00098     public:
00099         /**
00100         * Add the specified partition to the set.
00101         *
00102         * @param nPartition  the partition to add
00103         *
00104         * @return true if the specified partition was actually added as a 
00105         *         result of this call; false otherwise
00106         */
00107         virtual bool add(int32_t nPartition);
00108 
00109        /**
00110         * Add the specified PartitionSet to this set.
00111         *
00112         * @param vPartitions  the PartitionSet to add
00113         *
00114         * @return true if all of the partitions were actually added as a 
00115         *         result of this call; false otherwise
00116         */
00117         virtual bool add(PartitionSet::View vPartitions);
00118 
00119         /**
00120         * Fill the set to contain all the partitions.
00121         */
00122         virtual void fill();
00123         
00124         /**
00125         * Return an index of the first marked partition that is greater than 
00126         * or equal to the specified partition. If no such partition exists 
00127         * then -1 is returned.
00128         * 
00129         * This method could be used to iterate over all marked partitions:
00130         * <pre>
00131         * for (int i = ps.next(0); i >= 0; i = ps->next(i+1))
00132         *     {
00133         *     // process partition
00134         *     }
00135         * </pre>
00136         *
00137         * @param nPartition  the partition to start checking from (inclusive)
00138         *
00139         * @return the next marked partition, or -1 if no next marked partition
00140         *         exists in the set
00141         *
00142         * @throws IndexOutOfBoundsException if the specified partition is
00143         *         invalid
00144         */
00145         virtual int32_t next(int32_t nPartition) const;
00146      
00147  
00148     // ----- helpers --------------------------------------------------------
00149 
00150     protected:
00151         /**
00152         * Determine the number of trailing zero bits in the passed long value.
00153         *
00154         * @param l  a long value
00155         *
00156         * @return the number of trailing zero bits in the value, from 0
00157         *         (indicating that the least significant bit is set) to 64
00158         *         (indicating that no bits are set)
00159         */
00160         static int32_t getTrailingZeroCount(int64_t l);
00161 
00162 
00163     // ----- Object interface -----------------------------------------------
00164 
00165     public:
00166         /**
00167         * {@inheritDoc}
00168         */
00169         virtual void toStream(std::ostream& out) const;
00170         
00171         
00172     // ----- PortableObject interface ---------------------------------------
00173 
00174     public:
00175         /**
00176         * {@inheritDoc}
00177         */
00178         virtual void readExternal(PofReader::Handle hIn);
00179 
00180         /**
00181         * {@inheritDoc}
00182         */
00183         virtual void writeExternal(PofWriter::Handle hOut) const;
00184 
00185 
00186     // ----- data members ---------------------------------------------------
00187 
00188     protected:
00189         /**
00190         * Total partition count.
00191         */
00192         int32_t m_cPartitions;
00193 
00194         /**
00195         * A bit array representing the partitions, stored as an array of longs.
00196         */
00197         FinalHandle< Array<int64_t> > f_halBits;
00198     
00199         /**
00200         * A mask for the last long that indicates what bits get used.
00201         */
00202         int64_t m_lTailMask;
00203     
00204         /**
00205         * A cached count of marked partitions; -1 indicates that the value must
00206         * be recalculated.
00207         */
00208         int32_t m_cMarked;
00209     };
00210 
00211 COH_CLOSE_NAMESPACE3
00212 
00213 #endif // COH_PARTITION_SET_HPP
Copyright © 2000, 2013, Oracle and/or its affiliates. All rights reserved.