KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > rice > cs > drjava > model > debug > DebugEventNotifier


1 /*BEGIN_COPYRIGHT_BLOCK
2  *
3  * This file is part of DrJava. Download the current version of this project from http://www.drjava.org/
4  * or http://sourceforge.net/projects/drjava/
5  *
6  * DrJava Open Source License
7  *
8  * Copyright (C) 2001-2005 JavaPLT group at Rice University (javaplt@rice.edu). All rights reserved.
9  *
10  * Developed by: Java Programming Languages Team, Rice University, http://www.cs.rice.edu/~javaplt/
11  *
12  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
13  * documentation files (the "Software"), to deal with the Software without restriction, including without limitation
14  * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
15  * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
16  *
17  * - Redistributions of source code must retain the above copyright notice, this list of conditions and the
18  * following disclaimers.
19  * - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
20  * following disclaimers in the documentation and/or other materials provided with the distribution.
21  * - Neither the names of DrJava, the JavaPLT, Rice University, nor the names of its contributors may be used to
22  * endorse or promote products derived from this Software without specific prior written permission.
23  * - Products derived from this software may not be called "DrJava" nor use the term "DrJava" as part of their
24  * names without prior written permission from the JavaPLT group. For permission, write to javaplt@rice.edu.
25  *
26  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
27  * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28  * CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
29  * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
30  * WITH THE SOFTWARE.
31  *
32  *END_COPYRIGHT_BLOCK*/

33
34 package edu.rice.cs.drjava.model.debug;
35
36 import edu.rice.cs.drjava.model.EventNotifier;
37 import edu.rice.cs.drjava.model.OpenDefinitionsDocument;
38
39 import java.awt.EventQueue JavaDoc;
40
41 /** Keeps track of all listeners to a Debugger, and has the ability to notify them of some event.
42  * <p>
43  * This class has a specific role of managing DebugListeners. Other classes with similar names use similar code to
44  * perform the same function for other interfaces, e.g. InteractionsEventNotifier and GlobalEventNotifier. These
45  * classes implement the appropriate interface definition so that they can be used transparently as composite packaging
46  * for a particular listener interface.
47  * <p>
48  * Components which might otherwise manage their own list of listeners use EventNotifiers instead to simplify their
49  * internal implementation. Notifiers should therefore be considered a private implementation detail of the
50  * components, and should not be used directly outside of the "host" component.
51  * <p>
52  * All methods in this class must use the synchronization methods provided by ReaderWriterLock. This ensures that
53  * multiple notifications (reads) can occur simultaneously, but only one thread can be adding or removing listeners
54  * (writing) at a time, and no reads can occur during a write.
55  * <p>
56  * <i>No</i> methods on this class should be synchronized using traditional Java synchronization!
57  * <p>
58  *
59  * @version $Id: DebugEventNotifier.java 4027 2006-11-02 04:00:17Z rcartwright $
60  */

61 public class DebugEventNotifier extends EventNotifier<DebugListener> implements DebugListener {
62   
63   /** Called when debugger mode has been enabled. Must be executed in event thread. */
64   public void debuggerStarted() {
65     assert EventQueue.isDispatchThread();
66     _lock.startRead();
67     try {
68       int size = _listeners.size();
69       for (int i = 0; i < size; i++) {
70         _listeners.get(i).debuggerStarted();
71       }
72     }
73     finally { _lock.endRead(); }
74   }
75
76   /** Called when debugger mode has been disabled. Must be executed in event thread. */
77   public void debuggerShutdown() {
78     assert EventQueue.isDispatchThread();
79     _lock.startRead();
80     try {
81       int size = _listeners.size();
82       for (int i = 0; i < size; i++) {
83         _listeners.get(i).debuggerShutdown();
84       }
85     }
86     finally { _lock.endRead(); }
87   }
88
89   /** Called when the given line is reached by the current thread in the debugger, to request that the line be
90     * displayed. Must be executed only in the event thread.
91     * @param doc Document to display
92     * @param lineNumber Line to display or highlight
93     * @param shouldHighlight true iff the line should be highlighted.
94     */

95   public void threadLocationUpdated(OpenDefinitionsDocument doc, int lineNumber, boolean shouldHighlight) {
96     assert EventQueue.isDispatchThread();
97     _lock.startRead();
98     try {
99       int size = _listeners.size();
100       for (int i = 0; i < size; i++) {
101         _listeners.get(i).threadLocationUpdated(doc, lineNumber, shouldHighlight);
102       }
103     }
104     finally { _lock.endRead(); }
105   }
106
107   /** Called when a breakpoint is set in a document. Must be executed in event thread.
108    * @param bp the breakpoint
109    * @param index the index at which it was added
110    */

111   public void regionAdded(Breakpoint bp, int index) {
112     assert EventQueue.isDispatchThread();
113     _lock.startRead();
114     try {
115       int size = _listeners.size();
116       for (int i = 0; i < size; i++) { _listeners.get(i).regionAdded(bp, index); }
117     }
118     finally { _lock.endRead(); }
119   }
120
121   /** Called when a breakpoint is reached during execution. Must be executed in event thread.
122    * @param bp the breakpoint
123    */

124   public void breakpointReached(Breakpoint bp) {
125     assert EventQueue.isDispatchThread();
126     _lock.startRead();
127     try {
128       int size = _listeners.size();
129       for (int i = 0; i < size; i++) {
130         _listeners.get(i).breakpointReached(bp);
131       }
132     }
133     finally {
134       _lock.endRead();
135     }
136   }
137
138   /** Called when a breakpoint is changed during execution. Must be executed in event thread.
139    * @param bp the breakpoint
140    * @param index the index at which it was changed
141    */

142   public void regionChanged(Breakpoint bp, int index) {
143     assert EventQueue.isDispatchThread();
144     _lock.startRead();
145     try {
146       int size = _listeners.size();
147       for (int i = 0; i < size; i++) {
148         _listeners.get(i).regionChanged(bp, index);
149       }
150     }
151     finally {
152       _lock.endRead();
153     }
154   }
155   
156   /** Called when a watch is set. Must be executed in event thread.
157    * @param w the watch
158    */

159   public void watchSet(DebugWatchData w) {
160     assert EventQueue.isDispatchThread();
161     _lock.startRead();
162     try {
163       int size = _listeners.size();
164       for (int i = 0; i < size; i++) { _listeners.get(i).watchSet(w); }
165     }
166     finally { _lock.endRead(); }
167   }
168   
169   /** Called when a watch is removed. Must be executed in event thread.
170    * @param w the watch
171    */

172   public void watchRemoved(DebugWatchData w) {
173     assert EventQueue.isDispatchThread();
174     _lock.startRead();
175     try {
176       int size = _listeners.size();
177       for (int i = 0; i < size; i++) { _listeners.get(i).watchRemoved(w); }
178     }
179     finally { _lock.endRead(); }
180   }
181
182   /** Called when a breakpoint is removed from a document. Must be executed in event thread.
183    * @param bp the breakpoint
184    */

185   public void regionRemoved(Breakpoint bp) {
186     assert EventQueue.isDispatchThread();
187     _lock.startRead();
188     try {
189       int size = _listeners.size();
190       for (int i = 0; i < size; i++) _listeners.get(i).regionRemoved(bp);
191     }
192     finally { _lock.endRead(); }
193   }
194
195   /** Called when a step is requested on the current thread. Must be executed in event thread. */
196   public void stepRequested() {
197     assert EventQueue.isDispatchThread();
198     _lock.startRead();
199     try {
200       int size = _listeners.size();
201       for (int i = 0; i < size; i++) _listeners.get(i).stepRequested();
202     }
203     finally { _lock.endRead(); }
204   }
205
206   /** Called when the current thread is suspended. */
207   public void currThreadSuspended() {
208     _lock.startRead();
209     try {
210       int size = _listeners.size();
211       for (int i = 0; i < size; i++) _listeners.get(i).currThreadSuspended();
212     }
213     finally { _lock.endRead(); }
214   }
215
216   /** Called when the current thread is resumed. Must be executed in event thread. */
217   public void currThreadResumed() {
218     assert EventQueue.isDispatchThread();
219     _lock.startRead();
220     try {
221       int size = _listeners.size();
222       for (int i = 0; i < size; i++) _listeners.get(i).currThreadResumed();
223     }
224     finally { _lock.endRead(); }
225   }
226
227   /** Called when a thread starts. Must be executed in event thread. */
228   public void threadStarted() {
229     assert EventQueue.isDispatchThread();
230     _lock.startRead();
231     try {
232       int size = _listeners.size();
233       for (int i = 0; i < size; i++) _listeners.get(i).threadStarted();
234     }
235     finally { _lock.endRead(); }
236   }
237
238   /** Called when the current thread dies. Must be executed in event thread. */
239   public void currThreadDied() {
240     assert EventQueue.isDispatchThread();
241     _lock.startRead();
242     try {
243       int size = _listeners.size();
244       for (int i = 0; i < size; i++) _listeners.get(i).currThreadDied();
245     }
246     finally { _lock.endRead(); }
247   }
248
249   /** Called when any thread other than the current thread dies. Must be executed in event thread. */
250   public void nonCurrThreadDied() {
251     assert EventQueue.isDispatchThread();
252     _lock.startRead();
253     try {
254       int size = _listeners.size();
255       for (int i = 0; i < size; i++) _listeners.get(i).nonCurrThreadDied();
256     }
257     finally { _lock.endRead(); }
258   }
259
260   /** Called when the current (selected) thread is set in the debugger.
261    * @param thread the thread that was set as current
262    */

263   public void currThreadSet(DebugThreadData thread) {
264     _lock.startRead();
265     try {
266       int size = _listeners.size();
267       for (int i = 0; i < size; i++) {
268         _listeners.get(i).currThreadSet(thread);
269       }
270     }
271     finally { _lock.endRead(); }
272   }
273 }
274
Popular Tags