001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: *
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */
018:
019: /**
020: * @author Vitaly A. Provodin
021: * @version $Revision: 1.3 $
022: */
023:
024: /**
025: * Created on 25.02.2005
026: */package org.apache.harmony.jpda.tests.jdwp.ThreadGroupReference;
027:
028: import org.apache.harmony.jpda.tests.framework.DebuggeeSynchronizer;
029: import org.apache.harmony.jpda.tests.framework.LogWriter;
030: import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
031: import org.apache.harmony.jpda.tests.share.SyncDebuggee;
032:
033: /**
034: * The class specifies debuggee for <code>org.apache.harmony.jpda.tests.jdwp.ThreadGroupReference.ChildrenTest</code>.
035: * This debuggee is started as follow:
036: * <ol>
037: * <li>the group <code>PARENT_GROUP</code> is created
038: * <li>the group <code>CHILD_GROUP</code> is created as a child of
039: * the <code>PARENT_GROUP</code>
040: * <li>the tested thread <code>TESTED_THREAD</code> is started so this
041: * thread belongs to the <code>PARENT_GROUP</code>.
042: * </ol>
043: */
044: public class ChildrenDebuggee extends SyncDebuggee {
045:
046: public static final String PARENT_GROUP = "ParentGroup";
047: public static final String CHILD_GROUP = "ChildGroup";
048: public static final String TESTED_THREAD = "TestedThread";
049:
050: static Object waitForStart = new Object();
051: static Object waitForFinish = new Object();
052:
053: public void run() {
054: ThreadGroup thrdGroupParent = new ThreadGroup(PARENT_GROUP);
055: ThreadGroup thrdGroupChild = new ThreadGroup(thrdGroupParent,
056: CHILD_GROUP);
057: DebuggeeThread thrd = new DebuggeeThread(thrdGroupParent,
058: TESTED_THREAD, logWriter, synchronizer);
059:
060: synchronized (waitForStart) {
061: thrd.start();
062: try {
063: waitForStart.wait();
064: } catch (InterruptedException e) {
065:
066: }
067: }
068:
069: synchronized (waitForFinish) {
070: logWriter.println("thread is finished");
071: }
072:
073: logWriter.println("DUMP{" + thrdGroupChild + "}");
074: }
075:
076: class DebuggeeThread extends Thread {
077:
078: LogWriter logWriter;
079: DebuggeeSynchronizer synchronizer;
080:
081: public DebuggeeThread(ThreadGroup thrdGroup, String name,
082: LogWriter logWriter, DebuggeeSynchronizer synchronizer) {
083: super (thrdGroup, name);
084: this .logWriter = logWriter;
085: this .synchronizer = synchronizer;
086: }
087:
088: public void run() {
089:
090: synchronized (ChildrenDebuggee.waitForFinish) {
091:
092: synchronized (ChildrenDebuggee.waitForStart) {
093:
094: ChildrenDebuggee.waitForStart.notifyAll();
095:
096: logWriter.println(getName() + ": started");
097: synchronizer
098: .sendMessage(JPDADebuggeeSynchronizer.SGNL_READY);
099:
100: logWriter.println(getName()
101: + ": wait for SGNL_CONTINUE");
102: synchronizer
103: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
104: logWriter.println(getName() + ": finished");
105: }
106: }
107: }
108: }
109:
110: public static void main(String[] args) {
111: runDebuggee(ChildrenDebuggee.class);
112: }
113: }
|