Merge branch 'master' of https://source.jalview.org/git/jalviewjs.git
[jalviewjs.git] / site / j2s / java / lang / ThreadGroup.js
1 Clazz.declarePackage ("java.lang");
2 Clazz.load (["java.lang.Thread"], "java.lang.ThreadGroup", ["java.lang.IllegalThreadStateException", "$.ThreadDeath", "java.util.Arrays"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.parent = null;
5 this.name = null;
6 this.maxPriority = 10;
7 this.destroyed = false;
8 this.daemon = false;
9 this.vmAllowSuspension = false;
10 this.nUnstartedThreads = 0;
11 this.nthreads = 0;
12 this.threads = null;
13 this.ngroups = 0;
14 this.groups = null;
15 this.html5Applet = null;
16 Clazz.instantialize (this, arguments);
17 }, java.lang, "ThreadGroup", null, java.lang.Thread.UncaughtExceptionHandler);
18 Clazz.makeConstructor (c$, 
19 function (name) {
20 this.construct (java.lang.Thread.currentThread ().getThreadGroup (), name);
21 }, "~S");
22 Clazz.makeConstructor (c$, 
23 function (parent, name) {
24 this.name = name;
25 this.parent = parent;
26 if (parent != null) {
27 this.maxPriority = parent.maxPriority;
28 this.daemon = parent.daemon;
29 this.vmAllowSuspension = parent.vmAllowSuspension;
30 parent.add (this);
31 }}, "java.lang.ThreadGroup,~S");
32 Clazz.defineMethod (c$, "getName", 
33 function () {
34 return this.name;
35 });
36 Clazz.defineMethod (c$, "getParent", 
37 function () {
38 if (this.parent != null) this.parent.checkAccess ();
39 return this.parent;
40 });
41 Clazz.defineMethod (c$, "getMaxPriority", 
42 function () {
43 return this.maxPriority;
44 });
45 Clazz.defineMethod (c$, "isDaemon", 
46 function () {
47 return this.daemon;
48 });
49 Clazz.defineMethod (c$, "isDestroyed", 
50 function () {
51 return this.destroyed;
52 });
53 Clazz.defineMethod (c$, "setDaemon", 
54 function (daemon) {
55 this.checkAccess ();
56 this.daemon = daemon;
57 }, "~B");
58 Clazz.defineMethod (c$, "setMaxPriority", 
59 function (pri) {
60 var ngroupsSnapshot;
61 var groupsSnapshot;
62 {
63 this.checkAccess ();
64 if (pri < 1 || pri > 10) {
65 return;
66 }this.maxPriority = (this.parent != null) ? Math.min (pri, this.parent.maxPriority) : pri;
67 ngroupsSnapshot = this.ngroups;
68 if (this.groups != null) {
69 groupsSnapshot = java.util.Arrays.copyOf (this.groups, ngroupsSnapshot);
70 } else {
71 groupsSnapshot = null;
72 }}for (var i = 0; i < ngroupsSnapshot; i++) {
73 groupsSnapshot[i].setMaxPriority (pri);
74 }
75 }, "~N");
76 Clazz.defineMethod (c$, "parentOf", 
77 function (g) {
78 for (; g != null; g = g.parent) {
79 if (g === this) {
80 return true;
81 }}
82 return false;
83 }, "java.lang.ThreadGroup");
84 Clazz.defineMethod (c$, "checkAccess", 
85 function () {
86 });
87 Clazz.defineMethod (c$, "activeCount", 
88 function () {
89 var result;
90 var ngroupsSnapshot;
91 var groupsSnapshot;
92 {
93 if (this.destroyed) {
94 return 0;
95 }result = this.nthreads;
96 ngroupsSnapshot = this.ngroups;
97 if (this.groups != null) {
98 groupsSnapshot = java.util.Arrays.copyOf (this.groups, ngroupsSnapshot);
99 } else {
100 groupsSnapshot = null;
101 }}for (var i = 0; i < ngroupsSnapshot; i++) {
102 result += groupsSnapshot[i].activeCount ();
103 }
104 return result;
105 });
106 Clazz.defineMethod (c$, "enumerate", 
107 function (list) {
108 this.checkAccess ();
109 return this.enumerate (list, 0, true);
110 }, "~A");
111 Clazz.defineMethod (c$, "enumerate", 
112 function (list, recurse) {
113 this.checkAccess ();
114 return this.enumerate (list, 0, recurse);
115 }, "~A,~B");
116 Clazz.defineMethod (c$, "enumerate", 
117  function (list, n, recurse) {
118 var ngroupsSnapshot = 0;
119 var groupsSnapshot = null;
120 {
121 if (this.destroyed) {
122 return 0;
123 }var nt = this.nthreads;
124 if (nt > list.length - n) {
125 nt = list.length - n;
126 }for (var i = 0; i < nt; i++) {
127 if (this.threads[i].isAlive ()) {
128 list[n++] = this.threads[i];
129 }}
130 if (recurse) {
131 ngroupsSnapshot = this.ngroups;
132 if (this.groups != null) {
133 groupsSnapshot = java.util.Arrays.copyOf (this.groups, ngroupsSnapshot);
134 } else {
135 groupsSnapshot = null;
136 }}}if (recurse) {
137 for (var i = 0; i < ngroupsSnapshot; i++) {
138 n = groupsSnapshot[i].enumerate (list, n, true);
139 }
140 }return n;
141 }, "~A,~N,~B");
142 Clazz.defineMethod (c$, "activeGroupCount", 
143 function () {
144 var ngroupsSnapshot;
145 var groupsSnapshot;
146 {
147 if (this.destroyed) {
148 return 0;
149 }ngroupsSnapshot = this.ngroups;
150 if (this.groups != null) {
151 groupsSnapshot = java.util.Arrays.copyOf (this.groups, ngroupsSnapshot);
152 } else {
153 groupsSnapshot = null;
154 }}var n = ngroupsSnapshot;
155 for (var i = 0; i < ngroupsSnapshot; i++) {
156 n += groupsSnapshot[i].activeGroupCount ();
157 }
158 return n;
159 });
160 Clazz.defineMethod (c$, "enumerate", 
161 function (list) {
162 this.checkAccess ();
163 return this.enumerate (list, 0, true);
164 }, "~A");
165 Clazz.defineMethod (c$, "enumerate", 
166 function (list, recurse) {
167 this.checkAccess ();
168 return this.enumerate (list, 0, recurse);
169 }, "~A,~B");
170 Clazz.defineMethod (c$, "enumerate", 
171  function (list, n, recurse) {
172 var ngroupsSnapshot = 0;
173 var groupsSnapshot = null;
174 {
175 if (this.destroyed) {
176 return 0;
177 }var ng = this.ngroups;
178 if (ng > list.length - n) {
179 ng = list.length - n;
180 }if (ng > 0) {
181 System.arraycopy (this.groups, 0, list, n, ng);
182 n += ng;
183 }if (recurse) {
184 ngroupsSnapshot = this.ngroups;
185 if (this.groups != null) {
186 groupsSnapshot = java.util.Arrays.copyOf (this.groups, ngroupsSnapshot);
187 } else {
188 groupsSnapshot = null;
189 }}}if (recurse) {
190 for (var i = 0; i < ngroupsSnapshot; i++) {
191 n = groupsSnapshot[i].enumerate (list, n, true);
192 }
193 }return n;
194 }, "~A,~N,~B");
195 Clazz.defineMethod (c$, "stop", 
196 function () {
197 if (this.stopOrSuspend (false)) java.lang.Thread.currentThread ().stop ();
198 });
199 Clazz.defineMethod (c$, "interrupt", 
200 function () {
201 var ngroupsSnapshot;
202 var groupsSnapshot;
203 {
204 this.checkAccess ();
205 for (var i = 0; i < this.nthreads; i++) {
206 this.threads[i].interrupt ();
207 }
208 ngroupsSnapshot = this.ngroups;
209 if (this.groups != null) {
210 groupsSnapshot = java.util.Arrays.copyOf (this.groups, ngroupsSnapshot);
211 } else {
212 groupsSnapshot = null;
213 }}for (var i = 0; i < ngroupsSnapshot; i++) {
214 groupsSnapshot[i].interrupt ();
215 }
216 });
217 Clazz.defineMethod (c$, "suspend", 
218 function () {
219 if (this.stopOrSuspend (true)) java.lang.Thread.currentThread ().suspend ();
220 });
221 Clazz.defineMethod (c$, "stopOrSuspend", 
222  function (suspend) {
223 var suicide = false;
224 var us = java.lang.Thread.currentThread ();
225 var ngroupsSnapshot;
226 var groupsSnapshot = null;
227 {
228 this.checkAccess ();
229 for (var i = 0; i < this.nthreads; i++) {
230 if (this.threads[i] === us) suicide = true;
231  else if (suspend) this.threads[i].suspend ();
232  else this.threads[i].stop ();
233 }
234 ngroupsSnapshot = this.ngroups;
235 if (this.groups != null) {
236 groupsSnapshot = java.util.Arrays.copyOf (this.groups, ngroupsSnapshot);
237 }}for (var i = 0; i < ngroupsSnapshot; i++) suicide = groupsSnapshot[i].stopOrSuspend (suspend) || suicide;
238
239 return suicide;
240 }, "~B");
241 Clazz.defineMethod (c$, "resume", 
242 function () {
243 var ngroupsSnapshot;
244 var groupsSnapshot;
245 {
246 this.checkAccess ();
247 for (var i = 0; i < this.nthreads; i++) {
248 this.threads[i].resume ();
249 }
250 ngroupsSnapshot = this.ngroups;
251 if (this.groups != null) {
252 groupsSnapshot = java.util.Arrays.copyOf (this.groups, ngroupsSnapshot);
253 } else {
254 groupsSnapshot = null;
255 }}for (var i = 0; i < ngroupsSnapshot; i++) {
256 groupsSnapshot[i].resume ();
257 }
258 });
259 Clazz.defineMethod (c$, "destroy", 
260 function () {
261 var ngroupsSnapshot;
262 var groupsSnapshot;
263 {
264 this.checkAccess ();
265 if (this.destroyed || (this.nthreads > 0)) {
266 throw  new IllegalThreadStateException ();
267 }ngroupsSnapshot = this.ngroups;
268 if (this.groups != null) {
269 groupsSnapshot = java.util.Arrays.copyOf (this.groups, ngroupsSnapshot);
270 } else {
271 groupsSnapshot = null;
272 }if (this.parent != null) {
273 this.destroyed = true;
274 this.ngroups = 0;
275 this.groups = null;
276 this.nthreads = 0;
277 this.threads = null;
278 }}for (var i = 0; i < ngroupsSnapshot; i += 1) {
279 groupsSnapshot[i].destroy ();
280 }
281 if (this.parent != null) {
282 this.parent.remove (this);
283 }});
284 Clazz.defineMethod (c$, "add", 
285  function (g) {
286 {
287 if (this.destroyed) {
288 throw  new IllegalThreadStateException ();
289 }if (this.groups == null) {
290 this.groups =  new Array (4);
291 } else if (this.ngroups == this.groups.length) {
292 this.groups = java.util.Arrays.copyOf (this.groups, this.ngroups * 2);
293 }this.groups[this.ngroups] = g;
294 this.ngroups++;
295 }}, "java.lang.ThreadGroup");
296 Clazz.defineMethod (c$, "remove", 
297  function (g) {
298 {
299 if (this.destroyed) {
300 return;
301 }for (var i = 0; i < this.ngroups; i++) {
302 if (this.groups[i] === g) {
303 this.ngroups -= 1;
304 System.arraycopy (this.groups, i + 1, this.groups, i, this.ngroups - i);
305 this.groups[this.ngroups] = null;
306 break;
307 }}
308 if (this.nthreads == 0) {
309 this.notifyAll ();
310 }if (this.daemon && (this.nthreads == 0) && (this.nUnstartedThreads == 0) && (this.ngroups == 0)) {
311 this.destroy ();
312 }}}, "java.lang.ThreadGroup");
313 Clazz.defineMethod (c$, "addUnstarted", 
314 function () {
315 {
316 if (this.destroyed) {
317 throw  new IllegalThreadStateException ();
318 }this.nUnstartedThreads++;
319 }});
320 Clazz.defineMethod (c$, "add", 
321 function (t) {
322 {
323 if (this.destroyed) {
324 throw  new IllegalThreadStateException ();
325 }if (this.threads == null) {
326 this.threads =  new Array (4);
327 } else if (this.nthreads == this.threads.length) {
328 this.threads = java.util.Arrays.copyOf (this.threads, this.nthreads * 2);
329 }this.threads[this.nthreads] = t;
330 this.nthreads++;
331 this.nUnstartedThreads--;
332 }}, "java.lang.Thread");
333 Clazz.defineMethod (c$, "remove", 
334 function (t) {
335 {
336 if (this.destroyed) {
337 return;
338 }for (var i = 0; i < this.nthreads; i++) {
339 if (this.threads[i] === t) {
340 System.arraycopy (this.threads, i + 1, this.threads, i, --this.nthreads - i);
341 this.threads[this.nthreads] = null;
342 break;
343 }}
344 if (this.nthreads == 0) {
345 this.notifyAll ();
346 }if (this.daemon && (this.nthreads == 0) && (this.nUnstartedThreads == 0) && (this.ngroups == 0)) {
347 this.destroy ();
348 }}}, "java.lang.Thread");
349 Clazz.defineMethod (c$, "uncaughtException", 
350 function (t, e) {
351 if (this.parent != null) {
352 this.parent.uncaughtException (t, e);
353 } else {
354 var ueh = java.lang.Thread.getDefaultUncaughtExceptionHandler ();
355 if (ueh != null) {
356 ueh.uncaughtException (t, e);
357 } else if (!(Clazz.instanceOf (e, ThreadDeath))) {
358 System.err.print ("Exception in thread \"" + t.getName () + "\" ");
359 e.printStackTrace (System.err);
360 }}}, "java.lang.Thread,Throwable");
361 Clazz.overrideMethod (c$, "toString", 
362 function () {
363 return this.getClass ().getName () + "[name=" + this.getName () + ",maxpri=" + this.maxPriority + ",html5Applet=" + this.html5Applet + "]";
364 });
365 });