KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > debugger > jpda > models > JPDAThreadGroupImpl


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.debugger.jpda.models;
21
22 import com.sun.jdi.ThreadGroupReference;
23 import com.sun.jdi.ThreadReference;
24 import java.util.Iterator JavaDoc;
25
26 import java.util.List JavaDoc;
27
28 import org.netbeans.api.debugger.jpda.JPDAThread;
29 import org.netbeans.api.debugger.jpda.JPDAThreadGroup;
30 import org.netbeans.modules.debugger.jpda.JPDADebuggerImpl;
31 import org.netbeans.spi.viewmodel.UnknownTypeException;
32
33
34 /**
35  * The implementation of JPDAThreadGroup.
36  */

37 public class JPDAThreadGroupImpl implements JPDAThreadGroup {
38
39     private ThreadGroupReference tgr;
40     private JPDADebuggerImpl debugger;
41     
42     public JPDAThreadGroupImpl (ThreadGroupReference tgr, JPDADebuggerImpl debugger) {
43         this.tgr = tgr;
44         this.debugger = debugger;
45     }
46
47     /**
48     * Returns parent thread group.
49     *
50     * @return parent thread group.
51     */

52     public JPDAThreadGroup getParentThreadGroup () {
53         ThreadGroupReference ptgr = tgr.parent ();
54         if (ptgr == null) return null;
55         return debugger.getThreadGroup(ptgr);
56     }
57     
58     public JPDAThread[] getThreads () {
59         List JavaDoc l = tgr.threads ();
60         int i, k = l.size ();
61         JPDAThread[] ts = new JPDAThread [k];
62         for (i = 0; i < k; i++)
63             ts [i] = debugger.getThread((ThreadReference) l.get (i));
64         return ts;
65     }
66     
67     public JPDAThreadGroup[] getThreadGroups () {
68         List JavaDoc l = tgr.threadGroups ();
69         int i, k = l.size ();
70         JPDAThreadGroup[] ts = new JPDAThreadGroup [k];
71         for (i = 0; i < k; i++)
72             ts [i] = debugger.getThreadGroup((ThreadGroupReference) l.get (i));
73         return ts;
74     }
75     
76     public String JavaDoc getName () {
77         return tgr.name ();
78     }
79     
80     // XXX Add some synchronization so that the threads can not be resumed at any time
81
public void resume () {
82         List JavaDoc threads = tgr.threads();
83         for (Iterator JavaDoc it = threads.iterator(); it.hasNext(); ) {
84             JPDAThreadImpl thread = (JPDAThreadImpl) debugger.getThread((ThreadReference) it.next());
85             thread.notifyToBeResumed();
86         }
87         tgr.resume ();
88     }
89     
90     // XXX Add some synchronization
91
public void suspend () {
92         tgr.suspend ();
93         List JavaDoc threads = tgr.threads();
94         for (Iterator JavaDoc it = threads.iterator(); it.hasNext(); ) {
95             JPDAThreadImpl thread = (JPDAThreadImpl) debugger.getThread((ThreadReference) it.next());
96             thread.notifySuspended();
97         }
98     }
99     
100 }
101
Popular Tags