KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdi > internal > request > EventRequestManagerImpl


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdi.internal.request;
12
13
14 import java.util.ArrayList JavaDoc;
15 import java.util.Enumeration JavaDoc;
16 import java.util.HashSet JavaDoc;
17 import java.util.Hashtable JavaDoc;
18 import java.util.Iterator JavaDoc;
19 import java.util.List JavaDoc;
20
21 import org.eclipse.jdi.internal.FieldImpl;
22 import org.eclipse.jdi.internal.LocationImpl;
23 import org.eclipse.jdi.internal.MirrorImpl;
24 import org.eclipse.jdi.internal.ReferenceTypeImpl;
25 import org.eclipse.jdi.internal.ThreadReferenceImpl;
26 import org.eclipse.jdi.internal.VirtualMachineImpl;
27 import org.eclipse.jdi.internal.event.AccessWatchpointEventImpl;
28 import org.eclipse.jdi.internal.event.BreakpointEventImpl;
29 import org.eclipse.jdi.internal.event.ClassPrepareEventImpl;
30 import org.eclipse.jdi.internal.event.ClassUnloadEventImpl;
31 import org.eclipse.jdi.internal.event.EventImpl;
32 import org.eclipse.jdi.internal.event.ExceptionEventImpl;
33 import org.eclipse.jdi.internal.event.MethodEntryEventImpl;
34 import org.eclipse.jdi.internal.event.MethodExitEventImpl;
35 import org.eclipse.jdi.internal.event.ModificationWatchpointEventImpl;
36 import org.eclipse.jdi.internal.event.MonitorContendedEnterEventImpl;
37 import org.eclipse.jdi.internal.event.MonitorContendedEnteredEventImpl;
38 import org.eclipse.jdi.internal.event.MonitorWaitEventImpl;
39 import org.eclipse.jdi.internal.event.MonitorWaitedEventImpl;
40 import org.eclipse.jdi.internal.event.StepEventImpl;
41 import org.eclipse.jdi.internal.event.ThreadDeathEventImpl;
42 import org.eclipse.jdi.internal.event.ThreadStartEventImpl;
43 import org.eclipse.jdi.internal.event.VMDeathEventImpl;
44
45 import com.ibm.icu.text.MessageFormat;
46 import com.sun.jdi.Field;
47 import com.sun.jdi.Location;
48 import com.sun.jdi.ObjectCollectedException;
49 import com.sun.jdi.ReferenceType;
50 import com.sun.jdi.ThreadReference;
51 import com.sun.jdi.VMMismatchException;
52 import com.sun.jdi.request.AccessWatchpointRequest;
53 import com.sun.jdi.request.BreakpointRequest;
54 import com.sun.jdi.request.ClassPrepareRequest;
55 import com.sun.jdi.request.ClassUnloadRequest;
56 import com.sun.jdi.request.DuplicateRequestException;
57 import com.sun.jdi.request.EventRequest;
58 import com.sun.jdi.request.EventRequestManager;
59 import com.sun.jdi.request.ExceptionRequest;
60 import com.sun.jdi.request.InvalidRequestStateException;
61 import com.sun.jdi.request.MethodEntryRequest;
62 import com.sun.jdi.request.MethodExitRequest;
63 import com.sun.jdi.request.ModificationWatchpointRequest;
64 import com.sun.jdi.request.MonitorContendedEnterRequest;
65 import com.sun.jdi.request.MonitorContendedEnteredRequest;
66 import com.sun.jdi.request.MonitorWaitRequest;
67 import com.sun.jdi.request.MonitorWaitedRequest;
68 import com.sun.jdi.request.StepRequest;
69 import com.sun.jdi.request.ThreadDeathRequest;
70 import com.sun.jdi.request.ThreadStartRequest;
71 import com.sun.jdi.request.VMDeathRequest;
72
73 /**
74  * this class implements the corresponding interfaces
75  * declared by the JDI specification. See the com.sun.jdi package
76  * for more information.
77  *
78  */

79 public class EventRequestManagerImpl extends MirrorImpl implements EventRequestManager, org.eclipse.jdi.hcr.EventRequestManager {
80     /** Indexes used in arrays of request types. */
81     private static final int ACCESS_WATCHPOINT_INDEX = 0;
82     private static final int BREAKPOINT_INDEX = 1;
83     private static final int CLASS_PREPARE_INDEX = 2;
84     private static final int CLASS_UNLOAD_INDEX = 3;
85     private static final int EXCEPTION_INDEX = 4;
86     private static final int METHOD_ENTRY_INDEX = 5;
87     private static final int METHOD_EXIT_INDEX = 6;
88     private static final int MODIFICATION_WATCHPOINT_INDEX = 7;
89     private static final int STEP_INDEX = 8;
90     private static final int THREAD_DEATH_INDEX = 9;
91     private static final int THREAD_START_INDEX = 10;
92     private static final int VM_DEATH_INDEX = 11;
93     private static final int MONITOR_CONTENDED_ENTERED_INDEX = 12;
94     private static final int MONITOR_CONTENDED_ENTER_INDEX = 13;
95     private static final int MONITOR_WAITED_INDEX = 14;
96     private static final int MONITOR_WAIT_INDEX = 15;
97
98     /** Set of all existing requests per request type. */
99     private HashSet JavaDoc[] fRequests;
100
101     /** Maps per request type of requestIDs to enabled requests. */
102     private Hashtable JavaDoc[] fEnabledRequests;
103     
104     /**
105      * Creates new EventRequestManager.
106      */

107     public EventRequestManagerImpl(VirtualMachineImpl vmImpl) {
108         super("EventRequestManager", vmImpl); //$NON-NLS-1$
109

110         // Initialize list of requests.
111
fRequests = new HashSet JavaDoc[MONITOR_WAIT_INDEX + 1];
112         for (int i = 0; i < fRequests.length; i++)
113             fRequests[i] = new HashSet JavaDoc();
114             
115         // Initialize map of request IDs to enabled requests.
116
fEnabledRequests = new Hashtable JavaDoc[MONITOR_WAIT_INDEX + 1];
117         for (int i = 0; i < fEnabledRequests.length; i++)
118             fEnabledRequests[i] = new Hashtable JavaDoc();
119     }
120
121     /**
122      * Creates AccessWatchpointRequest.
123      */

124     public AccessWatchpointRequest createAccessWatchpointRequest(Field field) {
125         FieldImpl fieldImpl = (FieldImpl)field;
126         AccessWatchpointRequestImpl req = new AccessWatchpointRequestImpl(virtualMachineImpl());
127         req.addFieldFilter(fieldImpl);
128         addEventRequest(ACCESS_WATCHPOINT_INDEX, req);
129         return req;
130     }
131
132     /**
133      * Creates BreakpointRequest.
134      */

135     public BreakpointRequest createBreakpointRequest(Location location) throws VMMismatchException {
136         LocationImpl locImpl = (LocationImpl)location;
137         BreakpointRequestImpl req = new BreakpointRequestImpl(virtualMachineImpl());
138         req.addLocationFilter(locImpl);
139         addEventRequest(BREAKPOINT_INDEX, req);
140         return req;
141     }
142
143     /**
144      * Creates ClassPrepareRequest.
145      */

146     public ClassPrepareRequest createClassPrepareRequest() {
147         ClassPrepareRequestImpl req = new ClassPrepareRequestImpl(virtualMachineImpl());
148         addEventRequest(CLASS_PREPARE_INDEX, req);
149         return req;
150     }
151     
152     /**
153      * Creates ClassUnloadRequest.
154      */

155     public ClassUnloadRequest createClassUnloadRequest() {
156         ClassUnloadRequestImpl req = new ClassUnloadRequestImpl(virtualMachineImpl());
157         addEventRequest(CLASS_UNLOAD_INDEX, req);
158         return req;
159     }
160
161     /**
162      * Creates ExceptionRequest.
163      */

164     public ExceptionRequest createExceptionRequest(ReferenceType refType, boolean notifyCaught, boolean notifyUncaught) {
165         ReferenceTypeImpl refTypeImpl = (ReferenceTypeImpl)refType;
166         ExceptionRequestImpl req = new ExceptionRequestImpl(virtualMachineImpl());
167         req.addExceptionFilter(refTypeImpl, notifyCaught, notifyUncaught);
168         addEventRequest(EXCEPTION_INDEX, req);
169         return req;
170     }
171
172     /**
173      * Creates MethodEntryRequest.
174      */

175     public MethodEntryRequest createMethodEntryRequest() {
176         MethodEntryRequestImpl req = new MethodEntryRequestImpl(virtualMachineImpl());
177         addEventRequest(METHOD_ENTRY_INDEX, req);
178         return req;
179     }
180
181     /**
182      * Creates MethodExitRequest.
183      */

184     public MethodExitRequest createMethodExitRequest() {
185         MethodExitRequestImpl req = new MethodExitRequestImpl(virtualMachineImpl());
186         addEventRequest(METHOD_EXIT_INDEX, req);
187         return req;
188     }
189     
190     /**
191      * Creates a MonitorContendedEnteredRequest
192      * @since 3.3
193      */

194     public MonitorContendedEnteredRequest createMonitorContendedEnteredRequest() {
195         MonitorContendedEnteredRequestImpl req = new MonitorContendedEnteredRequestImpl(virtualMachineImpl());
196         addEventRequest(MONITOR_CONTENDED_ENTERED_INDEX, req);
197         return req;
198     }
199     
200     /**
201      * Creates a MonitorContendedEnterRequest
202      * @since 3.3
203      */

204     public MonitorContendedEnterRequest createMonitorContendedEnterRequest() {
205         MonitorContendedEnterRequestImpl req = new MonitorContendedEnterRequestImpl(virtualMachineImpl());
206         addEventRequest(MONITOR_CONTENDED_ENTER_INDEX, req);
207         return req;
208     }
209     
210     /**
211      * Creates a MonitorWaitedRequest
212      * @since 3.3
213      */

214     public MonitorWaitedRequest createMonitorWaitedRequest() {
215         MonitorWaitedRequestImpl req = new MonitorWaitedRequestImpl(virtualMachineImpl());
216         addEventRequest(MONITOR_WAITED_INDEX, req);
217         return req;
218     }
219     
220     /**
221      * Creates a MonitorWaitRequest
222      * @since 3.3
223      */

224     public MonitorWaitRequest createMonitorWaitRequest() {
225         MonitorWaitRequestImpl req = new MonitorWaitRequestImpl(virtualMachineImpl());
226         addEventRequest(MONITOR_WAIT_INDEX, req);
227         return req;
228     }
229     
230     /**
231      * Creates ModificationWatchpointRequest.
232      */

233     public ModificationWatchpointRequest createModificationWatchpointRequest(Field field) {
234         FieldImpl fieldImpl = (FieldImpl)field;
235         ModificationWatchpointRequestImpl req = new ModificationWatchpointRequestImpl(virtualMachineImpl());
236         req.addFieldFilter(fieldImpl);
237         addEventRequest(MODIFICATION_WATCHPOINT_INDEX, req);
238         return req;
239     }
240     
241     /**
242      * Creates StepRequest.
243      */

244     public StepRequest createStepRequest(ThreadReference thread, int size, int depth) throws DuplicateRequestException, ObjectCollectedException {
245         ThreadReferenceImpl threadImpl = (ThreadReferenceImpl)thread;
246         StepRequestImpl req = new StepRequestImpl(virtualMachineImpl());
247         req.addStepFilter(threadImpl, size, depth);
248         addEventRequest(STEP_INDEX, req);
249         return req;
250     }
251
252     /**
253      * Creates ThreadDeathRequest.
254      */

255     public ThreadDeathRequest createThreadDeathRequest() {
256         ThreadDeathRequestImpl req = new ThreadDeathRequestImpl(virtualMachineImpl());
257         addEventRequest(THREAD_DEATH_INDEX, req);
258         return req;
259     }
260
261     /**
262      * Creates ThreadStartRequest.
263      */

264     public ThreadStartRequest createThreadStartRequest() {
265         ThreadStartRequestImpl req = new ThreadStartRequestImpl(virtualMachineImpl());
266         addEventRequest(THREAD_START_INDEX, req);
267         return req;
268     }
269     
270
271     /*
272      * @see EventRequestManager#createVMDeathRequest()
273      */

274     public VMDeathRequest createVMDeathRequest() {
275         VMDeathRequestImpl req = new VMDeathRequestImpl(virtualMachineImpl());
276         addEventRequest(VM_DEATH_INDEX, req);
277         return req;
278     }
279
280     /**
281      * Creates ReenterStepRequest (for OTI specific Hot Code Replacement).
282      */

283     public org.eclipse.jdi.hcr.ReenterStepRequest createReenterStepRequest(ThreadReference thread) {
284         virtualMachineImpl().checkHCRSupported();
285         ThreadReferenceImpl threadImpl = (ThreadReferenceImpl)thread;
286         ReenterStepRequestImpl req = new ReenterStepRequestImpl(virtualMachineImpl());
287         // Note that the StepFilter is only used to specify the thread.
288
// The size is ignored and the depth will always be writter as HCR_STEP_DEPTH_REENTER_JDWP.
289
req.addStepFilter(threadImpl, StepRequest.STEP_MIN, 0);
290         // Since this is a special case of a step request, we use the same request list.
291
addEventRequest(STEP_INDEX, req);
292         return req;
293     }
294     
295     /**
296      * Enables class prepare requests for all loaded classes. This is
297      * necessary for current versions of the KVM to function correctly.
298      * This method is only called when the remote VM is determined to be
299      * the KVM.
300      */

301     public void enableInternalClassPrepareEvent() {
302         // Note that these requests are not stored in the set of outstanding requests because
303
// they must be invisible from outside.
304
ClassPrepareRequestImpl requestPrepare =
305             new ClassPrepareRequestImpl(virtualMachineImpl());
306         requestPrepare.setGeneratedInside();
307         requestPrepare.setSuspendPolicy(EventRequest.SUSPEND_NONE);
308
309         requestPrepare.enable();
310     }
311     
312     /**
313      * Creates ClassUnloadRequest for maintaining class information for within JDI.
314      * Needed to known when to flush the cache.
315      */

316     public void enableInternalClasUnloadEvent(/* tbd: ReferenceTypeImpl refType*/) {
317         // Note that these requests are not stored in the set of outstanding requests because
318
// they must be invisible from outside.
319
ClassUnloadRequestImpl reqUnload = new ClassUnloadRequestImpl(virtualMachineImpl());
320         reqUnload.setGeneratedInside();
321         // tbd: It is now yet possible to only ask for unload events for
322
// classes that we know of due to a limitation in the J9 VM.
323
// reqUnload.addClassFilter(refType);
324
reqUnload.setSuspendPolicy(EventRequest.SUSPEND_NONE);
325         reqUnload.enable();
326     }
327
328     /**
329      * Checks if a steprequest is for the given thread is already enabled.
330      */

331     boolean existsEnabledStepRequest(ThreadReferenceImpl threadImpl) {
332         Enumeration JavaDoc enumeration = fEnabledRequests[STEP_INDEX].elements();
333         StepRequestImpl step;
334         while (enumeration.hasMoreElements()) {
335             step = (StepRequestImpl)enumeration.nextElement();
336             if (step.thread() == threadImpl)
337                 return true;
338         }
339         return false;
340     }
341
342     /**
343      * Deletes all Breakpoints.
344      */

345     public void deleteAllBreakpoints() {
346         EventRequestImpl.clearAllBreakpoints(this);
347         fRequests[BREAKPOINT_INDEX].clear();
348         fEnabledRequests[BREAKPOINT_INDEX].clear();
349     }
350
351     /**
352      * Adds an EventRequests to the given list.
353      */

354     public void addEventRequest(int index, EventRequest req) {
355         fRequests[index].add(req);
356     }
357
358     /**
359      * Deletes an EventRequest.
360      */

361     private void deleteEventRequest(int index, EventRequest req) throws VMMismatchException {
362         // Remove request from list of requests and from the mapping of requestIDs to requests.
363
checkVM(req);
364         EventRequestImpl requestImpl = (EventRequestImpl)req;
365         fRequests[index].remove(requestImpl);
366         if (requestImpl.requestID() != null)
367             fEnabledRequests[index].remove(requestImpl.requestID());
368     }
369
370     /**
371      * Deletes an EventRequest.
372      */

373     public void deleteEventRequest(EventRequest req) {
374         // Disable request, note that this also causes the event request to be removed from fEnabledRequests.
375
try {
376             req.disable();
377         } catch (InvalidRequestStateException exception) {
378             // The event has already been removed from the VM.
379
}
380         
381         // Remove request from list.
382
if (req instanceof AccessWatchpointRequestImpl)
383             deleteEventRequest(ACCESS_WATCHPOINT_INDEX, req);
384         else if (req instanceof BreakpointRequestImpl)
385             deleteEventRequest(BREAKPOINT_INDEX, req);
386         else if (req instanceof ClassPrepareRequestImpl)
387             deleteEventRequest(CLASS_PREPARE_INDEX, req);
388         else if (req instanceof ClassUnloadRequestImpl)
389             deleteEventRequest(CLASS_UNLOAD_INDEX, req);
390         else if (req instanceof ExceptionRequestImpl)
391             deleteEventRequest(EXCEPTION_INDEX, req);
392         else if (req instanceof MethodEntryRequestImpl)
393             deleteEventRequest(METHOD_ENTRY_INDEX, req);
394         else if (req instanceof MethodExitRequestImpl)
395             deleteEventRequest(METHOD_EXIT_INDEX, req);
396         else if (req instanceof ModificationWatchpointRequestImpl)
397             deleteEventRequest(MODIFICATION_WATCHPOINT_INDEX, req);
398         else if (req instanceof StepRequestImpl)
399             deleteEventRequest(STEP_INDEX, req);
400         else if (req instanceof ThreadDeathRequestImpl)
401             deleteEventRequest(THREAD_DEATH_INDEX, req);
402         else if (req instanceof ThreadStartRequestImpl)
403             deleteEventRequest(THREAD_START_INDEX, req);
404         else if(req instanceof MonitorContendedEnterRequestImpl) {
405             deleteEventRequest(MONITOR_CONTENDED_ENTER_INDEX, req);
406         }
407         else if(req instanceof MonitorContendedEnteredRequestImpl) {
408             deleteEventRequest(MONITOR_CONTENDED_ENTERED_INDEX, req);
409         }
410         else if(req instanceof MonitorWaitRequestImpl) {
411             deleteEventRequest(MONITOR_WAIT_INDEX, req);
412         }
413         else if(req instanceof MonitorWaitedRequestImpl) {
414             deleteEventRequest(MONITOR_WAITED_INDEX, req);
415         }
416         else
417         
418         throw new InternalError JavaDoc(MessageFormat.format(RequestMessages.EventRequestManagerImpl_EventRequest_type_of__0__is_unknown_1, new String JavaDoc[]{req.toString()}));
419     }
420
421     /**
422      * Deletes all EventRequests from the given list.
423      */

424     public void deleteEventRequests(List JavaDoc requests) throws VMMismatchException {
425         Iterator JavaDoc iter = requests.iterator();
426         while(iter.hasNext()) {
427             Object JavaDoc obj = iter.next();
428             deleteEventRequest((EventRequest)obj);
429         }
430     }
431
432     /**
433      * @return Returns list of AccessWatchpointRequests.
434      * For changes, the appropriate EventRequestManager methods should be used.
435      */

436     public List JavaDoc accessWatchpointRequests() {
437         return new ArrayList JavaDoc(fRequests[ACCESS_WATCHPOINT_INDEX]);
438     }
439
440     /**
441      * @return Returns list of BreakpointRequests.
442      * For changes, the appropriate EventRequestManager methods should be used.
443      */

444     public List JavaDoc breakpointRequests() {
445         return new ArrayList JavaDoc(fRequests[BREAKPOINT_INDEX]);
446     }
447
448     /**
449      * @return Returns list of ClassPrepareRequests.
450      * For changes, the appropriate EventRequestManager methods should be used.
451      */

452     public List JavaDoc classPrepareRequests() {
453         return new ArrayList JavaDoc(fRequests[CLASS_PREPARE_INDEX]);
454     }
455
456     /**
457      * @return Returns list of ClassUnloadRequests.
458      * For changes, the appropriate EventRequestManager methods should be used.
459      */

460     public List JavaDoc classUnloadRequests() {
461         return new ArrayList JavaDoc(fRequests[CLASS_UNLOAD_INDEX]);
462     }
463
464     /**
465      * @return Returns list of ExceptionRequests.
466      * For changes, the appropriate EventRequestManager methods should be used.
467      */

468     public List JavaDoc exceptionRequests() {
469         return new ArrayList JavaDoc(fRequests[EXCEPTION_INDEX]);
470     }
471
472     /**
473      * @return Returns list of MethodEntryRequests.
474      * For changes, the appropriate EventRequestManager methods should be used.
475      */

476     public List JavaDoc methodEntryRequests() {
477         return new ArrayList JavaDoc(fRequests[METHOD_ENTRY_INDEX]);
478     }
479
480     /**
481      * @return Returns list of MethodExitRequests.
482      * For changes, the appropriate EventRequestManager methods should be used.
483      */

484     public List JavaDoc methodExitRequests() {
485         return new ArrayList JavaDoc(fRequests[METHOD_EXIT_INDEX]);
486     }
487     
488     /**
489      * @return Returns list of ModificationWatchpointRequests.
490      * For changes, the appropriate EventRequestManager methods should be used.
491      */

492     public List JavaDoc modificationWatchpointRequests() {
493         return new ArrayList JavaDoc(fRequests[MODIFICATION_WATCHPOINT_INDEX]);
494     }
495
496     /**
497      * @return Returns list of StepRequests.
498      * For changes, the appropriate EventRequestManager methods should be used.
499      */

500     public List JavaDoc stepRequests() {
501         return new ArrayList JavaDoc(fRequests[STEP_INDEX]);
502     }
503
504     /**
505      * @return Returns list of ThreadDeathRequests.
506      * For changes, the appropriate EventRequestManager methods should be used.
507      */

508     public List JavaDoc threadDeathRequests() {
509         return new ArrayList JavaDoc(fRequests[THREAD_DEATH_INDEX]);
510     }
511
512     /**
513      * @return Returns list of ThreadStartRequests.
514      * For changes, the appropriate EventRequestManager methods should be used.
515      */

516     public List JavaDoc threadStartRequests() {
517         return new ArrayList JavaDoc(fRequests[THREAD_START_INDEX]);
518     }
519     
520     /**
521      * @return Returns list of VMDeathRequests.
522      * For changes, the appropriate EventRequestManager methods should be used.
523      */

524     public List JavaDoc vmDeathRequests() {
525         return new ArrayList JavaDoc(fRequests[VM_DEATH_INDEX]);
526     }
527
528     public void removeRequestIDMapping(EventRequestImpl req) {
529         if (req instanceof AccessWatchpointRequestImpl)
530             fEnabledRequests[ACCESS_WATCHPOINT_INDEX].remove(req.requestID());
531         else if (req instanceof BreakpointRequestImpl)
532             fEnabledRequests[BREAKPOINT_INDEX].remove(req.requestID());
533         else if (req instanceof ClassPrepareRequestImpl)
534             fEnabledRequests[CLASS_PREPARE_INDEX].remove(req.requestID());
535         else if (req instanceof ClassUnloadRequestImpl)
536             fEnabledRequests[CLASS_UNLOAD_INDEX].remove(req.requestID());
537         else if (req instanceof ExceptionRequestImpl)
538             fEnabledRequests[EXCEPTION_INDEX].remove(req.requestID());
539         else if (req instanceof MethodEntryRequestImpl)
540             fEnabledRequests[METHOD_ENTRY_INDEX].remove(req.requestID());
541         else if (req instanceof MethodExitRequestImpl)
542             fEnabledRequests[METHOD_EXIT_INDEX].remove(req.requestID());
543         else if (req instanceof ModificationWatchpointRequestImpl)
544             fEnabledRequests[MODIFICATION_WATCHPOINT_INDEX].remove(req.requestID());
545         else if (req instanceof StepRequestImpl)
546             fEnabledRequests[STEP_INDEX].remove(req.requestID());
547         else if (req instanceof ThreadDeathRequestImpl)
548             fEnabledRequests[THREAD_DEATH_INDEX].remove(req.requestID());
549         else if (req instanceof ThreadStartRequestImpl)
550             fEnabledRequests[THREAD_START_INDEX].remove(req.requestID());
551         else if(req instanceof MonitorContendedEnterRequestImpl) {
552             fEnabledRequests[MONITOR_CONTENDED_ENTER_INDEX].remove(req.requestID());
553         }
554         else if(req instanceof MonitorContendedEnteredRequestImpl) {
555             fEnabledRequests[MONITOR_CONTENDED_ENTERED_INDEX].remove(req.requestID());
556         }
557         else if(req instanceof MonitorWaitRequestImpl) {
558             fEnabledRequests[MONITOR_WAIT_INDEX].remove(req.requestID());
559         }
560         else if(req instanceof MonitorWaitedRequestImpl) {
561             fEnabledRequests[MONITOR_WAITED_INDEX].remove(req.requestID());
562         }
563     }
564     
565     /**
566      * Maps a request ID to requests.
567      */

568     public void addRequestIDMapping(EventRequestImpl req) {
569         if (req instanceof AccessWatchpointRequestImpl)
570             fEnabledRequests[ACCESS_WATCHPOINT_INDEX].put(req.requestID(), req);
571         else if (req instanceof BreakpointRequestImpl)
572             fEnabledRequests[BREAKPOINT_INDEX].put(req.requestID(), req);
573         else if (req instanceof ClassPrepareRequestImpl)
574             fEnabledRequests[CLASS_PREPARE_INDEX].put(req.requestID(), req);
575         else if (req instanceof ClassUnloadRequestImpl)
576             fEnabledRequests[CLASS_UNLOAD_INDEX].put(req.requestID(), req);
577         else if (req instanceof ExceptionRequestImpl)
578             fEnabledRequests[EXCEPTION_INDEX].put(req.requestID(), req);
579         else if (req instanceof MethodEntryRequestImpl)
580             fEnabledRequests[METHOD_ENTRY_INDEX].put(req.requestID(), req);
581         else if (req instanceof MethodExitRequestImpl)
582             fEnabledRequests[METHOD_EXIT_INDEX].put(req.requestID(), req);
583         else if (req instanceof ModificationWatchpointRequestImpl)
584             fEnabledRequests[MODIFICATION_WATCHPOINT_INDEX].put(req.requestID(), req);
585         else if (req instanceof StepRequestImpl)
586             fEnabledRequests[STEP_INDEX].put(req.requestID(), req);
587         else if (req instanceof ThreadDeathRequestImpl)
588             fEnabledRequests[THREAD_DEATH_INDEX].put(req.requestID(), req);
589         else if (req instanceof ThreadStartRequestImpl)
590             fEnabledRequests[THREAD_START_INDEX].put(req.requestID(), req);
591         else if(req instanceof MonitorWaitRequestImpl) {
592             fEnabledRequests[MONITOR_WAIT_INDEX].put(req.requestID(), req);
593         }
594         else if(req instanceof MonitorWaitedRequestImpl) {
595             fEnabledRequests[MONITOR_WAITED_INDEX].put(req.requestID(), req);
596         }
597         else if(req instanceof MonitorContendedEnterRequestImpl) {
598             fEnabledRequests[MONITOR_CONTENDED_ENTER_INDEX].put(req.requestID(), req);
599         }
600         else if(req instanceof MonitorContendedEnteredRequestImpl) {
601             fEnabledRequests[MONITOR_CONTENDED_ENTERED_INDEX].put(req.requestID(), req);
602         }
603     }
604
605     /**
606      * Find Request that matches event.
607      */

608     public EventRequestImpl findRequest(EventImpl event) {
609         if (event instanceof AccessWatchpointEventImpl)
610             return (EventRequestImpl)fEnabledRequests[ACCESS_WATCHPOINT_INDEX].get(event.requestID());
611         else if (event instanceof BreakpointEventImpl)
612             return (EventRequestImpl)fEnabledRequests[BREAKPOINT_INDEX].get(event.requestID());
613         else if (event instanceof ClassPrepareEventImpl)
614             return (ClassPrepareRequestImpl)fEnabledRequests[CLASS_PREPARE_INDEX].get(event.requestID());
615         else if (event instanceof ClassUnloadEventImpl)
616             return (EventRequestImpl)fEnabledRequests[CLASS_UNLOAD_INDEX].get(event.requestID());
617         else if (event instanceof ExceptionEventImpl)
618             return (EventRequestImpl)fEnabledRequests[EXCEPTION_INDEX].get(event.requestID());
619         else if (event instanceof MethodEntryEventImpl)
620             return (EventRequestImpl)fEnabledRequests[METHOD_ENTRY_INDEX].get(event.requestID());
621         else if (event instanceof MethodExitEventImpl)
622             return (EventRequestImpl)fEnabledRequests[METHOD_EXIT_INDEX].get(event.requestID());
623         else if (event instanceof ModificationWatchpointEventImpl)
624             return (EventRequestImpl)fEnabledRequests[MODIFICATION_WATCHPOINT_INDEX].get(event.requestID());
625         else if (event instanceof StepEventImpl)
626             return (EventRequestImpl)fEnabledRequests[STEP_INDEX].get(event.requestID());
627         else if (event instanceof ThreadDeathEventImpl)
628             return (EventRequestImpl)fEnabledRequests[THREAD_DEATH_INDEX].get(event.requestID());
629         else if (event instanceof ThreadStartEventImpl)
630             return (EventRequestImpl)fEnabledRequests[THREAD_START_INDEX].get(event.requestID());
631         else if (event instanceof VMDeathEventImpl)
632             return (EventRequestImpl)fEnabledRequests[VM_DEATH_INDEX].get(event.requestID());
633         else if(event instanceof MonitorWaitEventImpl) {
634             return (EventRequestImpl)fEnabledRequests[MONITOR_WAIT_INDEX].get(event.requestID());
635         }
636         else if(event instanceof MonitorWaitedEventImpl) {
637             return (EventRequestImpl)fEnabledRequests[MONITOR_WAITED_INDEX].get(event.requestID());
638         }
639         else if(event instanceof MonitorContendedEnterEventImpl) {
640             return (EventRequestImpl)fEnabledRequests[MONITOR_CONTENDED_ENTER_INDEX].get(event.requestID());
641         }
642         else if(event instanceof MonitorContendedEnteredEventImpl) {
643             return (EventRequestImpl)fEnabledRequests[MONITOR_CONTENDED_ENTERED_INDEX].get(event.requestID());
644         }
645         else
646             throw new InternalError JavaDoc(RequestMessages.EventRequestManagerImpl_Got_event_of_unknown_type_2);
647     }
648
649     /**
650      * @see com.sun.jdi.request.EventRequestManager#monitorContendedEnterRequests()
651      * @since 3.3
652      */

653     public List JavaDoc monitorContendedEnterRequests() {
654         return new ArrayList JavaDoc(fRequests[MONITOR_CONTENDED_ENTER_INDEX]);
655     }
656     
657     /**
658      * @see com.sun.jdi.request.EventRequestManager#monitorContendedEnteredRequests()
659      * @since 3.3
660      */

661     public List JavaDoc monitorContendedEnteredRequests() {
662         return new ArrayList JavaDoc(fRequests[MONITOR_CONTENDED_ENTERED_INDEX]);
663     }
664     
665     /**
666      * @see com.sun.jdi.request.EventRequestManager#monitorWaitRequests()
667      * @since 3.3
668      */

669     public List JavaDoc monitorWaitRequests() {
670         return new ArrayList JavaDoc(fRequests[MONITOR_WAIT_INDEX]);
671     }
672     
673     /**
674      * @see com.sun.jdi.request.EventRequestManager#monitorWaitedRequests()
675      * @since 3.3
676      */

677     public List JavaDoc monitorWaitedRequests() {
678         return new ArrayList JavaDoc(fRequests[MONITOR_WAITED_INDEX]);
679     }
680 }
681
Popular Tags