Home | History | Annotate | Download | only in ThreadGroupReference
      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 
     55     @Override
     56     public void run() {
     57         ThreadGroup thrdGroupParent = new ThreadGroup(PARENT_GROUP);
     58         ThreadGroup thrdGroupChild = new ThreadGroup(thrdGroupParent, CHILD_GROUP);
     59         DebuggeeThread thrd = new DebuggeeThread(thrdGroupChild, TESTED_THREAD,
     60                 logWriter, synchronizer);
     61 
     62         synchronized(waitForStart){
     63             thrd.start();
     64             try {
     65                 waitForStart.wait();
     66             } catch (InterruptedException e) {
     67 
     68             }
     69         }
     70 
     71         synchronized(waitForFinish){
     72             logWriter.println("thread is finished");
     73         }
     74     }
     75 
     76     static class DebuggeeThread extends Thread {
     77 
     78         LogWriter logWriter;
     79         DebuggeeSynchronizer synchronizer;
     80 
     81         public DebuggeeThread(ThreadGroup thrdGroup, String name,
     82                 LogWriter logWriter, DebuggeeSynchronizer synchronizer) {
     83             super(thrdGroup, name);
     84             this.logWriter = logWriter;
     85             this.synchronizer = synchronizer;
     86         }
     87 
     88         @Override
     89         public void run() {
     90 
     91             synchronized(NameDebuggee.waitForFinish){
     92 
     93                 synchronized(NameDebuggee.waitForStart){
     94 
     95                     NameDebuggee.waitForStart.notifyAll();
     96 
     97                     logWriter.println(getName() +  ": started");
     98                     synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_READY);
     99 
    100                     logWriter.println(getName() +  ": wait for SGNL_CONTINUE");
    101                     synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
    102                     logWriter.println(getName() +  ": finished");
    103                 }
    104             }
    105         }
    106     }
    107 
    108     public static void main(String [] args) {
    109         runDebuggee(NameDebuggee.class);
    110     }
    111 }
    112