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 19.02.2005
026: */package org.apache.harmony.jpda.tests.jdwp.VirtualMachine;
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.VirtualMachine.AllThreadsTest</code>.
035: * This debuggee starts the tested thread <code>TESTED_THREAD</code> and for
036: * different goals of tests, the debuggee sends the <code>SGNL_READY</code>
037: * signal to and waits for the <code>SGNL_CONTINUE</code> signal from debugger
038: * in two places:
039: * <ul>
040: * <li>right away when the tested thread has been started
041: * <li>when the tested thread has been finished
042: * </ul>
043: */
044: public class AllThreadsDebuggee extends SyncDebuggee {
045:
046: static Object waitTimeObject = new Object();
047:
048: static void waitMlsecsTime(long mlsecsTime) {
049: synchronized (waitTimeObject) {
050: try {
051: waitTimeObject.wait(mlsecsTime);
052: } catch (Throwable throwable) {
053: // ignore
054: }
055: }
056: }
057:
058: public static final String TESTED_THREAD = "TestedThread";
059:
060: static Object waitForStart = new Object();
061:
062: public void run() {
063: DebuggeeThread thrd = new DebuggeeThread(TESTED_THREAD,
064: logWriter, synchronizer);
065:
066: synchronized (waitForStart) {
067: thrd.start();
068: try {
069: waitForStart.wait();
070: } catch (InterruptedException e) {
071:
072: }
073: }
074:
075: logWriter.println("Wait for thread to finish...");
076: while (thrd.isAlive()) {
077: waitMlsecsTime(1000);
078: }
079: logWriter.println("thread finished");
080: logWriter.println("send SGNL_READY");
081: synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_READY);
082:
083: synchronizer
084: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
085: }
086:
087: class DebuggeeThread extends Thread {
088:
089: LogWriter logWriter;
090: DebuggeeSynchronizer synchronizer;
091:
092: public DebuggeeThread(String name, LogWriter logWriter,
093: DebuggeeSynchronizer synchronizer) {
094: super (name);
095: this .logWriter = logWriter;
096: this .synchronizer = synchronizer;
097: }
098:
099: public void run() {
100:
101: logWriter.println(getName() + ": started...");
102: synchronized (AllThreadsDebuggee.waitForStart) {
103:
104: AllThreadsDebuggee.waitForStart.notifyAll();
105: }
106:
107: synchronizer
108: .sendMessage(JPDADebuggeeSynchronizer.SGNL_READY);
109: logWriter.println(getName() + ": wait for SGNL_CONTINUE");
110: synchronizer
111: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
112: logWriter.println(getName() + ": is finishing...");
113: }
114: }
115:
116: public static void main(String[] args) {
117: runDebuggee(AllThreadsDebuggee.class);
118: }
119: }
|