KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > debugger > jpda > breakpoints > ThreadBreakpointImpl


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.debugger.jpda.breakpoints;
21
22
23 import com.sun.jdi.ThreadReference;
24 import com.sun.jdi.VMDisconnectedException;
25 import com.sun.jdi.VirtualMachine;
26 import com.sun.jdi.event.Event;
27 import com.sun.jdi.event.ThreadDeathEvent;
28 import com.sun.jdi.event.ThreadStartEvent;
29 import com.sun.jdi.request.ThreadDeathRequest;
30 import com.sun.jdi.request.ThreadStartRequest;
31
32 import org.netbeans.api.debugger.Session;
33 import org.netbeans.api.debugger.jpda.ThreadBreakpoint;
34 import org.netbeans.modules.debugger.jpda.JPDADebuggerImpl;
35
36 import org.netbeans.modules.debugger.jpda.util.Executor;
37
38
39 /**
40 * Implementation of breakpoint on method.
41 *
42 * @author Jan Jancura
43 */

44 public class ThreadBreakpointImpl extends BreakpointImpl implements Executor {
45
46     // variables ...............................................................
47

48     private ThreadBreakpoint breakpoint;
49
50
51     // init ....................................................................
52

53     public ThreadBreakpointImpl (ThreadBreakpoint presenter, JPDADebuggerImpl debugger, Session session) {
54         super (presenter, null, debugger, session);
55         breakpoint = presenter;
56         set ();
57     }
58             
59        
60     // Event impl ..............................................................
61

62     protected void setRequests () {
63         try {
64             if ( (breakpoint.getBreakpointType () &
65                   breakpoint.TYPE_THREAD_STARTED ) != 0
66             ) {
67                 ThreadStartRequest tsr = getEventRequestManager ().
68                     createThreadStartRequest ();
69                 addEventRequest (tsr);
70             }
71             if ( (breakpoint.getBreakpointType () &
72                   breakpoint.TYPE_THREAD_DEATH) != 0
73             ) {
74                 VirtualMachine vm = getVirtualMachine();
75                 if (vm != null) {
76                     ThreadDeathRequest tdr = vm.eventRequestManager().
77                         createThreadDeathRequest();
78                     addEventRequest (tdr);
79                 }
80             }
81         } catch (VMDisconnectedException e) {
82         }
83     }
84
85     public boolean exec (Event event) {
86         ThreadReference thread = null;
87         if (event instanceof ThreadStartEvent)
88             thread = ((ThreadStartEvent) event).thread ();
89         else
90         if (event instanceof ThreadDeathEvent)
91             thread = ((ThreadDeathEvent) event).thread ();
92
93         return perform (
94             null,
95             thread,
96             null,
97             thread
98         );
99     }
100 }
101
Popular Tags