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.4 $
022: */
023:
024: /**
025: * Created on 22.02.2005
026: */package org.apache.harmony.jpda.tests.jdwp.ThreadReference;
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.ThreadReference.InterruptTest</code>.
035: * This debuggee starts the tested thread <code>TESTED_THREAD</code> and blocks it
036: * in an invocation of the <code>wait()</code> method.
037: * If it receives an <code>InterruptedException</code>, it notifies debugger via
038: * the synchronization channel.
039: */
040: public class InterruptDebuggee extends SyncDebuggee {
041:
042: public static final String TESTED_THREAD = "TestedThread";
043:
044: static Object waitForStart = new Object();
045: static Object waitForInterrupt = new Object();
046: static Object waitForFinish = new Object();
047:
048: public void run() {
049: DebuggeeThread thrd = new DebuggeeThread(TESTED_THREAD,
050: logWriter, synchronizer);
051:
052: synchronized (waitForStart) {
053: thrd.start();
054: try {
055: waitForStart.wait();
056: } catch (InterruptedException e) {
057:
058: }
059: }
060:
061: synchronized (waitForFinish) {
062: logWriter.println("thread is finished");
063: }
064: }
065:
066: class DebuggeeThread extends Thread {
067:
068: LogWriter logWriter;
069: DebuggeeSynchronizer synchronizer;
070:
071: public DebuggeeThread(String name, LogWriter logWriter,
072: DebuggeeSynchronizer synchronizer) {
073: super (name);
074: this .logWriter = logWriter;
075: this .synchronizer = synchronizer;
076: }
077:
078: public void run() {
079:
080: synchronized (InterruptDebuggee.waitForFinish) {
081:
082: synchronized (InterruptDebuggee.waitForStart) {
083:
084: InterruptDebuggee.waitForStart.notifyAll();
085: }
086:
087: synchronized (InterruptDebuggee.waitForInterrupt) {
088:
089: logWriter.println(getName() + ": started");
090: synchronizer
091: .sendMessage(JPDADebuggeeSynchronizer.SGNL_READY);
092:
093: try {
094: InterruptDebuggee.waitForInterrupt.wait();
095: } catch (InterruptedException e) {
096: logWriter.println("Expected " + e);
097: synchronizer.sendMessage(e.toString());
098: }
099:
100: logWriter.println(getName()
101: + ": wait for SGNL_CONTINUE");
102: synchronizer
103: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
104: logWriter.println(getName() + ": finished");
105: }
106: }
107: }
108: }
109:
110: public static void main(String[] args) {
111: runDebuggee(InterruptDebuggee.class);
112: }
113: }
|