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

E80355-01

coherence/lang/ThreadGroup.hpp

00001 /*
00002 * ThreadGroup.hpp
00003 *
00004 * Copyright (c) 2000, 2017, 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_THREAD_GROUP_HPP
00017 #define COH_THREAD_GROUP_HPP
00018 
00019 #include "coherence/lang/compatibility.hpp"
00020 
00021 #include "coherence/lang/FinalHandle.hpp"
00022 #include "coherence/lang/FinalView.hpp"
00023 #include "coherence/lang/ObjectArray.hpp"
00024 #include "coherence/lang/String.hpp"
00025 #include "coherence/lang/TypedHandle.hpp"
00026 
00027 
00028 
00029 COH_OPEN_NAMESPACE2(coherence,lang)
00030 
00031 // ----- forward declarations -----------------------------------------------
00032 
00033 class Thread;
00034 
00035 
00036 /**
00037 * ThreadGroup represents a set of threads.
00038 *
00039 * @author mf 2009.11.17
00040 *
00041 * @since Coherence 3.6
00042 */
00043 class COH_EXPORT ThreadGroup
00044     : public class_spec<ThreadGroup>
00045     {
00046     friend class factory<ThreadGroup>;
00047 
00048     // ----- constructors ---------------------------------------------------
00049 
00050     protected:
00051         /**
00052         * Create a new ThreadGroup.
00053         *
00054         * @param vsName   the name for the group
00055         * @param hParent  the parent thread group, or NULL for current group
00056         */
00057         ThreadGroup(String::View vsName, ThreadGroup::Handle hParent = NULL);
00058 
00059 
00060     // ----- ThreadGroup interface ------------------------------------------
00061 
00062     public:
00063         /**
00064         * Return the name of the group.
00065         *
00066         * @return the group name
00067         */
00068         virtual String::View getName() const;
00069 
00070         /**
00071         * Return this groups parent group.
00072         *
00073         * @return the parent group
00074         */
00075         virtual ThreadGroup::View getParent() const;
00076 
00077         /**
00078         * Destroy this group and all of its subgroups. The groups must be
00079         * empty.
00080         */
00081         virtual void destroy();
00082 
00083         /**
00084         * Returns true if the group has been destroyed.
00085         *
00086         * @return true if the group has been destroyed.
00087         */
00088         virtual bool isDestroyed() const;
00089 
00090         /**
00091         * Return an estimate as to the number of threads in the group
00092         *
00093         * @param fRecurse  if the count should include sub-groups
00094         *
00095         * @return an estimate as to the number of threads in the group
00096         */
00097         virtual size32_t activeCount(bool fRecurse = true) const;
00098 
00099         /**
00100         * Return an estimate as to the number of thread groups in the group
00101         *
00102         * @param fRecurse  if the count should include sub-groups
00103         *
00104         * @return an estimate as to the number of thread groups in the group
00105         */
00106         virtual size32_t activeGroupCount(bool fRecurse = true) const;
00107 
00108         /**
00109         * Copy into the specified array the active threads represented by this
00110         * group.
00111         *
00112         * @param hao       the destination array
00113         * @param fRecurse  if sub-groups should be enumerated
00114         */
00115         virtual size32_t enumerateThreads(
00116                 ObjectArray::Handle hao, bool fRecurse = true);
00117 
00118         /**
00119         * Copy into the specified array the active threads represented by this
00120         * group.
00121         *
00122         * @param hao       the destination array
00123         * @param fRecurse  if sub-groups should be enumerated
00124         */
00125         virtual size32_t enumerateThreads(
00126                 ObjectArray::Handle hao, bool fRecurse = true) const;
00127 
00128         /**
00129         * Copy into the specified array the active thread groups represented
00130         * by this group.
00131         *
00132         * @param hao       the destination array
00133         * @param fRecurse  if sub-groups should be enumerated
00134         */
00135         virtual size32_t enumerateGroups(
00136                 ObjectArray::Handle hao, bool fRecurse = true);
00137 
00138         /**
00139         * Copy into the specified array the active thread groups represented
00140         * by this group.
00141         *
00142         * @param hao       the destination array
00143         * @param fRecurse  if sub-groups should be enumerated
00144         */
00145         virtual size32_t enumerateGroups(
00146                 ObjectArray::Handle hao, bool fRecurse = true) const;
00147 
00148         /**
00149         * Interrupt the threads represented by this group.
00150         *
00151         * @param fRecurse  if sub-groups should be enumerated
00152         */
00153         virtual void interrupt(bool fRecurse = true);
00154 
00155         /**
00156         * Join the threads represented by this group.
00157         *
00158         * @param cMillis   the total join timeout, or zero for infinite
00159         * @param fRecurse  if sub-groups should be enumerated
00160         *
00161         * @return the number of threads which failed to join within the timeout
00162         */
00163         virtual size32_t join(int64_t cMillis = 0, bool fRecurse = true) const;
00164 
00165     protected:
00166         /**
00167         * Add a thread to this group.
00168         *
00169         * @param hThread  the thread to add
00170         */
00171         virtual void add(TypedHandle<Thread> hThread);
00172 
00173         /**
00174         * Remove a thread from this group.
00175         *
00176         * @param hThread  the thread to remove
00177          */
00178         virtual void remove(TypedHandle<Thread> hThread);
00179 
00180         /**
00181         * Add a thread group to this group.
00182         *
00183         * @param hGroup  the group to add
00184         */
00185         virtual void addGroup(ThreadGroup::Handle hGroup);
00186 
00187         /**
00188         * Remove a thread group from this group.
00189         *
00190         * @param hGroup  the group to remove
00191         */
00192         virtual void removeGroup(ThreadGroup::Handle hGroup);
00193 
00194 
00195     // ----- Object interface -----------------------------------------------
00196 
00197     public:
00198         /**
00199         * {@inheritDoc}
00200         */
00201         virtual TypedHandle<const String> toString() const;
00202 
00203 
00204     // ----- data members ---------------------------------------------------
00205 
00206     protected:
00207         /**
00208         * The group name.
00209         */
00210         FinalView<String> f_vsName;
00211 
00212         /**
00213         * The parent group.
00214         */
00215         MemberHandle<ThreadGroup> m_hGroupParent;
00216 
00217         /**
00218         * True if the group has been destroyed.
00219         */
00220         bool m_fDestroyed;
00221 
00222         /**
00223         * The group's threads.
00224         */
00225         FinalHandle<Object> f_hSetThreads;
00226 
00227         /**
00228         * The group's child groups.
00229         */
00230         FinalHandle<Object> f_hSetGroups;
00231 
00232 
00233     // ----- friends --------------------------------------------------------
00234 
00235     friend class Thread;
00236     };
00237 
00238 COH_CLOSE_NAMESPACE2
00239 
00240 #endif // COH_THREAD_GROUP_HPP
Copyright © 2000, 2017, Oracle and/or its affiliates. All rights reserved.