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 */
26package org.apache.harmony.jpda.tests.jdwp.ThreadReference;
27
28import org.apache.harmony.jpda.tests.framework.DebuggeeSynchronizer;
29import org.apache.harmony.jpda.tests.framework.LogWriter;
30import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
31import 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 */
38public 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    public void run() {
46        DebuggeeThread thrd = new DebuggeeThread(TESTED_THREAD,
47                logWriter, synchronizer);
48
49        synchronized(waitForStart){
50            thrd.start();
51            try {
52                waitForStart.wait();
53            } catch (InterruptedException e) {
54
55            }
56        }
57
58        synchronized(waitForFinish){
59            logWriter.println("thread is finished");
60        }
61    }
62
63    class DebuggeeThread extends Thread {
64
65        LogWriter logWriter;
66        DebuggeeSynchronizer synchronizer;
67
68        public DebuggeeThread(String name, LogWriter logWriter,
69                DebuggeeSynchronizer synchronizer) {
70            super(name);
71            this.logWriter = logWriter;
72            this.synchronizer = synchronizer;
73        }
74
75        public void run() {
76
77            synchronized(StatusDebuggee.waitForFinish){
78
79                synchronized(StatusDebuggee.waitForStart){
80
81                    StatusDebuggee.waitForStart.notifyAll();
82
83                    logWriter.println(getName() +  ": started");
84                    synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_READY);
85
86                    logWriter.println(getName() +  ": wait for SGNL_CONTINUE");
87                    synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
88                    logWriter.println(getName() +  ": finished");
89                }
90            }
91        }
92    }
93
94    public static void main(String [] args) {
95        runDebuggee(StatusDebuggee.class);
96    }
97}
98