KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > aspectj > debugger > gui > AJThreadGroupNode


1 /* -*- Mode: JDE; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2  *
3  * This file is part of the debugger and core tools for the AspectJ(tm)
4  * programming language; see http://aspectj.org
5  *
6  * The contents of this file are subject to the Mozilla Public License
7  * Version 1.1 (the "License"); you may not use this file except in
8  * compliance with the License. You may obtain a copy of the License at
9  * either http://www.mozilla.org/MPL/ or http://aspectj.org/MPL/.
10  *
11  * Software distributed under the License is distributed on an "AS IS" basis,
12  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13  * for the specific language governing rights and limitations under the
14  * License.
15  *
16  * The Original Code is AspectJ.
17  *
18  * The Initial Developer of the Original Code is Xerox Corporation. Portions
19  * created by Xerox Corporation are Copyright (C) 1999-2002 Xerox Corporation.
20  * All Rights Reserved.
21  */

22
23 package org.aspectj.debugger.gui;
24
25 import org.aspectj.debugger.base.*;
26
27 import java.util.*;
28 import javax.swing.tree.*;
29 import com.sun.jdi.ThreadReference;
30 import com.sun.jdi.ThreadGroupReference;
31
32 /**
33  * An AJTreeNode with a ThreadGroupReference used object. This node can
34  * contain other AJThreadGroupNode instances or AJThreadNode
35  * instances. Access is provided to the underlying ThreadGropuReference, so
36  * it is not adviced to access the actual reference directly.
37  */

38 public class AJThreadGroupNode extends AJTreeNode {
39
40     /**
41      * The underlying ThreadGroupReference.
42      */

43     ThreadGroupReference threadGroup = null;
44
45     /**
46      * Sets the ThreadGroupReference.
47      *
48      * @param threadGroup the underlying ThreadGroupReference.
49      */

50     public AJThreadGroupNode(ThreadGroupReference threadGroup, DefaultTreeModel model) {
51         super(AJIcons.THREADGROUP_ICON, model);
52         this.threadGroup = threadGroup;
53         this.setUserObject(threadGroup);
54     }
55
56     // ------------------------------------------------------------------------
57
// Interface to the underlying ThreadGroupReference
58
// ------------------------------------------------------------------------
59

60     /**
61      * Returns the name of this thread group.
62      *
63      * @return the string containing the thread group name.
64      */

65     public String JavaDoc name() {
66         return threadGroup.name();
67     }
68
69     /**
70      * Returns the parent of this thread group.
71      *
72      * @return a ThreadGroupReference mirroring the parent of
73      * this thread group in the target VM, or null if this
74      * is a top-level thread group.
75      */

76     public ThreadGroupReference parent() {
77         return threadGroup.parent();
78     }
79
80     /**
81      * Resumes all threads in this thread group. Each thread in
82      * this group and in all of its subgroups will be resumed as
83      * described in ThreadReference.resume().
84      */

85     public void resume() {
86         threadGroup.resume();
87     }
88
89     /**
90      * Suspends all threads in this thread group. Each thread in this
91      * group and in all of its subgroups will be suspended as described
92      * in ThreadReference.suspend(). This is not guaranteed to be an atomic
93      * operation; if the target VM is not interrupted at the time this method
94      * is called, it is possible that new threads will be created between
95      * the time that threads are enumerated and all of them have been
96      * suspended.
97      */

98     public void suspend() {
99         threadGroup.suspend();
100     }
101
102     /**
103      * Returns a List containing each ThreadGroupReference in this thread
104      * group. Only the thread groups in this immediate thread group (and
105      * not its subgroups) are returned.
106      *
107      * @return a List of ThreadGroupReference objects mirroring the threads
108      * from this thread group in the target VM.
109      */

110     public List threadGroups() {
111         return threadGroup.threadGroups();
112     }
113
114     /**
115      * Returns a List containing each ThreadReference in this thread group.
116      * Only the threads in this immediate thread group (and not its
117      * subgroups) are returned.
118      *
119      * @return a List of ThreadReference objects mirroring the threads
120      * from this thread group in the target VM.
121      */

122     public List threads() {
123         return threadGroup.threads();
124     }
125
126     // ------------------------------------------------------------------------
127
// Misc. methods
128
// ------------------------------------------------------------------------
129

130     /**
131      * Returns the underlying ThreadReference.
132      *
133      * @return The underlying ThreadReference.
134      */

135     public ThreadGroupReference getThreadGroup() {
136         return threadGroup;
137     }
138
139     /**
140      * Overrides isThreadGroup of AJTreeNode because this <b>is</b> a
141      * thread group.
142      *
143      * @return true.
144      */

145     public boolean isThreadGroup() {
146         return true;
147     }
148
149     public String JavaDoc toString() {
150         return threadGroup.name() + " (" + threadGroup.uniqueID() + ")";
151     }
152
153     public boolean isOKToExpand() {
154         return true;
155     }
156 }
157
Popular Tags