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