001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.debugger.jpda.models;
043:
044: import com.sun.jdi.ThreadGroupReference;
045: import com.sun.jdi.ThreadReference;
046: import java.util.Iterator;
047:
048: import java.util.List;
049:
050: import org.netbeans.api.debugger.jpda.JPDAThread;
051: import org.netbeans.api.debugger.jpda.JPDAThreadGroup;
052: import org.netbeans.modules.debugger.jpda.JPDADebuggerImpl;
053: import org.netbeans.spi.viewmodel.UnknownTypeException;
054:
055: /**
056: * The implementation of JPDAThreadGroup.
057: */
058: public class JPDAThreadGroupImpl implements JPDAThreadGroup {
059:
060: private ThreadGroupReference tgr;
061: private JPDADebuggerImpl debugger;
062:
063: public JPDAThreadGroupImpl(ThreadGroupReference tgr,
064: JPDADebuggerImpl debugger) {
065: this .tgr = tgr;
066: this .debugger = debugger;
067: }
068:
069: /**
070: * Returns parent thread group.
071: *
072: * @return parent thread group.
073: */
074: public JPDAThreadGroup getParentThreadGroup() {
075: ThreadGroupReference ptgr = tgr.parent();
076: if (ptgr == null)
077: return null;
078: return debugger.getThreadGroup(ptgr);
079: }
080:
081: public JPDAThread[] getThreads() {
082: List l = tgr.threads();
083: int i, k = l.size();
084: JPDAThread[] ts = new JPDAThread[k];
085: for (i = 0; i < k; i++)
086: ts[i] = debugger.getThread((ThreadReference) l.get(i));
087: return ts;
088: }
089:
090: public JPDAThreadGroup[] getThreadGroups() {
091: List l = tgr.threadGroups();
092: int i, k = l.size();
093: JPDAThreadGroup[] ts = new JPDAThreadGroup[k];
094: for (i = 0; i < k; i++)
095: ts[i] = debugger.getThreadGroup((ThreadGroupReference) l
096: .get(i));
097: return ts;
098: }
099:
100: public String getName() {
101: return tgr.name();
102: }
103:
104: // XXX Add some synchronization so that the threads can not be resumed at any time
105: public void resume() {
106: List threads = tgr.threads();
107: for (Iterator it = threads.iterator(); it.hasNext();) {
108: JPDAThreadImpl thread = (JPDAThreadImpl) debugger
109: .getThread((ThreadReference) it.next());
110: thread.notifyToBeResumed();
111: }
112: tgr.resume();
113: }
114:
115: // XXX Add some synchronization
116: public void suspend() {
117: tgr.suspend();
118: List threads = tgr.threads();
119: for (Iterator it = threads.iterator(); it.hasNext();) {
120: JPDAThreadImpl thread = (JPDAThreadImpl) debugger
121: .getThread((ThreadReference) it.next());
122: thread.notifySuspended();
123: }
124: }
125:
126: }
|