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.2 $
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.NameTest</code>
035: * and <code>org.apache.harmony.jpda.tests.jdwp.ThreadGroupReference.ParentTest</code>.
036: * This debuggee is started as follow:
037: * <ol>
038: * <li>the group <code>PARENT_GROUP</code> is created
039: * <li>the group <code>CHILD_GROUP</code> is created as a child of
040: * the <code>PARENT_GROUP</code>
041: * <li>the tested thread <code>TESTED_THREAD</code> is started so this
042: * thread belongs to the <code>CHILD_GROUP</code>.
043: * </ol>
044: */
045: public class NameDebuggee extends SyncDebuggee {
046:
047: public static final String PARENT_GROUP = "ParentGroup";
048: public static final String CHILD_GROUP = "ChildGroup";
049: public static final String TESTED_THREAD = "TestedThread";
050:
051: static Object waitForStart = new Object();
052: static Object waitForFinish = new Object();
053:
054: public void run() {
055: ThreadGroup thrdGroupParent = new ThreadGroup(PARENT_GROUP);
056: ThreadGroup thrdGroupChild = new ThreadGroup(thrdGroupParent,
057: CHILD_GROUP);
058: DebuggeeThread thrd = new DebuggeeThread(thrdGroupChild,
059: TESTED_THREAD, logWriter, synchronizer);
060:
061: synchronized (waitForStart) {
062: thrd.start();
063: try {
064: waitForStart.wait();
065: } catch (InterruptedException e) {
066:
067: }
068: }
069:
070: synchronized (waitForFinish) {
071: logWriter.println("thread is finished");
072: }
073: }
074:
075: class DebuggeeThread extends Thread {
076:
077: LogWriter logWriter;
078: DebuggeeSynchronizer synchronizer;
079:
080: public DebuggeeThread(ThreadGroup thrdGroup, String name,
081: LogWriter logWriter, DebuggeeSynchronizer synchronizer) {
082: super (thrdGroup, name);
083: this .logWriter = logWriter;
084: this .synchronizer = synchronizer;
085: }
086:
087: public void run() {
088:
089: synchronized (NameDebuggee.waitForFinish) {
090:
091: synchronized (NameDebuggee.waitForStart) {
092:
093: NameDebuggee.waitForStart.notifyAll();
094:
095: logWriter.println(getName() + ": started");
096: synchronizer
097: .sendMessage(JPDADebuggeeSynchronizer.SGNL_READY);
098:
099: logWriter.println(getName()
100: + ": wait for SGNL_CONTINUE");
101: synchronizer
102: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
103: logWriter.println(getName() + ": finished");
104: }
105: }
106: }
107: }
108:
109: public static void main(String[] args) {
110: runDebuggee(NameDebuggee.class);
111: }
112: }
|