Home | History | Annotate | Download | only in ThreadReference
      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 22.02.2005
     25  */
     26 package org.apache.harmony.jpda.tests.jdwp.ThreadReference;
     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.ThreadReference.StatusTest</code>.
     36  * This debuggee starts the tested thread <code>TESTED_THREAD</code>.
     37  */
     38 public class StatusDebuggee extends SyncDebuggee {
     39 
     40     public static final String TESTED_THREAD = "TestedThread";
     41 
     42     static Object waitForStart = new Object();
     43     static Object waitForFinish = new Object();
     44 
     45     @Override
     46     public void run() {
     47         DebuggeeThread thrd = new DebuggeeThread(TESTED_THREAD,
     48                 logWriter, synchronizer);
     49 
     50         synchronized(waitForStart){
     51             thrd.start();
     52             try {
     53                 waitForStart.wait();
     54             } catch (InterruptedException e) {
     55 
     56             }
     57         }
     58 
     59         synchronized(waitForFinish){
     60             logWriter.println("thread is finished");
     61         }
     62     }
     63 
     64     static class DebuggeeThread extends Thread {
     65 
     66         LogWriter logWriter;
     67         DebuggeeSynchronizer synchronizer;
     68 
     69         public DebuggeeThread(String name, LogWriter logWriter,
     70                 DebuggeeSynchronizer synchronizer) {
     71             super(name);
     72             this.logWriter = logWriter;
     73             this.synchronizer = synchronizer;
     74         }
     75 
     76         @Override
     77         public void run() {
     78 
     79             synchronized(StatusDebuggee.waitForFinish){
     80 
     81                 synchronized(StatusDebuggee.waitForStart){
     82 
     83                     StatusDebuggee.waitForStart.notifyAll();
     84 
     85                     logWriter.println(getName() +  ": started");
     86                     synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_READY);
     87 
     88                     logWriter.println(getName() +  ": wait for SGNL_CONTINUE");
     89                     synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
     90                     logWriter.println(getName() +  ": finished");
     91                 }
     92             }
     93         }
     94     }
     95 
     96     public static void main(String [] args) {
     97         runDebuggee(StatusDebuggee.class);
     98     }
     99 }
    100