1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 /** 20 * @author Vitaly A. Provodin 21 */ 22 23 /** 24 * Created on 25.02.2005 25 */ 26 package org.apache.harmony.jpda.tests.jdwp.ThreadGroupReference; 27 28 import org.apache.harmony.jpda.tests.framework.DebuggeeSynchronizer; 29 import org.apache.harmony.jpda.tests.framework.LogWriter; 30 import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer; 31 import org.apache.harmony.jpda.tests.share.SyncDebuggee; 32 33 34 /** 35 * The class specifies debuggee for <code>org.apache.harmony.jpda.tests.jdwp.ThreadGroupReference.NameTest</code> 36 * and <code>org.apache.harmony.jpda.tests.jdwp.ThreadGroupReference.ParentTest</code>. 37 * This debuggee is started as follow: 38 * <ol> 39 * <li>the group <code>PARENT_GROUP</code> is created 40 * <li>the group <code>CHILD_GROUP</code> is created as a child of 41 * the <code>PARENT_GROUP</code> 42 * <li>the tested thread <code>TESTED_THREAD</code> is started so this 43 * thread belongs to the <code>CHILD_GROUP</code>. 44 * </ol> 45 */ 46 public class NameDebuggee extends SyncDebuggee { 47 48 public static final String PARENT_GROUP = "ParentGroup"; 49 public static final String CHILD_GROUP = "ChildGroup"; 50 public static final String TESTED_THREAD = "TestedThread"; 51 52 static Object waitForStart = new Object(); 53 static Object waitForFinish = new Object(); 54 run()55 public void run() { 56 ThreadGroup thrdGroupParent = new ThreadGroup(PARENT_GROUP); 57 ThreadGroup thrdGroupChild = new ThreadGroup(thrdGroupParent, CHILD_GROUP); 58 DebuggeeThread thrd = new DebuggeeThread(thrdGroupChild, TESTED_THREAD, 59 logWriter, synchronizer); 60 61 synchronized(waitForStart){ 62 thrd.start(); 63 try { 64 waitForStart.wait(); 65 } catch (InterruptedException e) { 66 67 } 68 } 69 70 synchronized(waitForFinish){ 71 logWriter.println("thread is finished"); 72 } 73 } 74 75 class DebuggeeThread extends Thread { 76 77 LogWriter logWriter; 78 DebuggeeSynchronizer synchronizer; 79 DebuggeeThread(ThreadGroup thrdGroup, String name, LogWriter logWriter, DebuggeeSynchronizer synchronizer)80 public DebuggeeThread(ThreadGroup thrdGroup, String name, 81 LogWriter logWriter, DebuggeeSynchronizer synchronizer) { 82 super(thrdGroup, name); 83 this.logWriter = logWriter; 84 this.synchronizer = synchronizer; 85 } 86 run()87 public void run() { 88 89 synchronized(NameDebuggee.waitForFinish){ 90 91 synchronized(NameDebuggee.waitForStart){ 92 93 NameDebuggee.waitForStart.notifyAll(); 94 95 logWriter.println(getName() + ": started"); 96 synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_READY); 97 98 logWriter.println(getName() + ": wait for SGNL_CONTINUE"); 99 synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); 100 logWriter.println(getName() + ": finished"); 101 } 102 } 103 } 104 } 105 main(String [] args)106 public static void main(String [] args) { 107 runDebuggee(NameDebuggee.class); 108 } 109 } 110