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 Aleksander V. Budniy
021: * @version $Revision: $
022: */
023:
024: /**
025: * Created on 5.06.2006
026: */package org.apache.harmony.jpda.tests.jdwp.DebuggerOnDemand;
027:
028: import org.apache.harmony.jpda.tests.share.Debuggee;
029: import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
030:
031: /**
032: * This class provides simple debuggee class with deferred synch establishing.
033: *
034: * When debuggee throws exception, agent launches debugger, that connects to debuggee.
035: * Then debuggee establishes synch connection with debugger and invokes tested method.
036: */
037: public class OnthowDebuggerLaunchDebuggee extends Debuggee {
038:
039: public void onStart() {
040: super .onStart();
041:
042: logWriter.println("DEBUGGEE: started");
043:
044: // prepare for connection with debugger
045: logWriter
046: .println("DEBUGGEE: bind for synch connection with debugger");
047: synchronizer = createSynchronizer();
048: synchronizer.bindServer();
049:
050: // throw tested exception to launch debugger
051: try {
052: logWriter.println("DEBUGGEE: throw ExceptionForDebugger");
053: throw new ExceptionForDebugger();
054: } catch (ExceptionForDebugger e) {
055: logWriter.println("DEBUGGEE: cought ExceptionForDebugger: "
056: + e);
057: }
058:
059: // listen for connection with debugger
060: synchronizer.startServer();
061: logWriter
062: .println("DEBUGGEE: established synch connection with debugger");
063: }
064:
065: public void run() {
066: synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_READY);
067: synchronizer
068: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
069: testMethod();
070: }
071:
072: void testMethod() {
073: logWriter.println("DEBUGGEE: testMethod invoked");
074: }
075:
076: protected JPDADebuggeeSynchronizer createSynchronizer() {
077: return new JPDADebuggeeSynchronizer(logWriter, settings);
078: }
079:
080: public void onFinish() {
081: logWriter.println("DEBUGGEE: finished");
082:
083: if (synchronizer != null) {
084: synchronizer.stop();
085: logWriter
086: .println("DEBUGGEE: closed synch connection with debugger");
087: }
088: super .onFinish();
089: }
090:
091: public static void main(String[] args) {
092: runDebuggee(OnthowDebuggerLaunchDebuggee.class);
093: }
094:
095: protected JPDADebuggeeSynchronizer synchronizer;
096: }
097:
098: @SuppressWarnings("serial")
099: class ExceptionForDebugger extends Exception {
100: }
|