0N/A/*
2362N/A * Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
4378N/A/*
4378N/A * This source code is provided to illustrate the usage of a given feature
4378N/A * or technique and has been deliberately simplified. Additional steps
4378N/A * required for a production-quality application, such as security checks,
4378N/A * input validation and proper error handling, might not be present in
4378N/A * this sample code.
4378N/A */
4378N/A
4378N/A
0N/Apackage com.sun.tools.example.debug.bdi;
0N/A
0N/Aimport com.sun.jdi.*;
0N/Aimport com.sun.jdi.request.*;
0N/A
0N/Aimport java.util.*;
0N/A
0N/Aclass EventRequestSpecList {
0N/A
0N/A // all specs
0N/A private List<EventRequestSpec> eventRequestSpecs = Collections.synchronizedList(
0N/A new ArrayList<EventRequestSpec>());
0N/A
0N/A final ExecutionManager runtime;
0N/A
0N/A EventRequestSpecList(ExecutionManager runtime) {
0N/A this.runtime = runtime;
0N/A }
0N/A
0N/A /**
0N/A * Resolve all deferred eventRequests waiting for 'refType'.
0N/A */
0N/A void resolve(ReferenceType refType) {
0N/A synchronized(eventRequestSpecs) {
28N/A for (EventRequestSpec spec : eventRequestSpecs) {
28N/A spec.attemptResolve(refType);
0N/A }
0N/A }
0N/A }
0N/A
0N/A void install(EventRequestSpec ers, VirtualMachine vm) {
0N/A synchronized (eventRequestSpecs) {
0N/A eventRequestSpecs.add(ers);
0N/A }
0N/A if (vm != null) {
0N/A ers.attemptImmediateResolve(vm);
0N/A }
0N/A }
0N/A
0N/A BreakpointSpec
0N/A createClassLineBreakpoint(String classPattern, int line) {
0N/A ReferenceTypeSpec refSpec =
0N/A new PatternReferenceTypeSpec(classPattern);
0N/A return new LineBreakpointSpec(this, refSpec, line);
0N/A }
0N/A
0N/A BreakpointSpec
0N/A createSourceLineBreakpoint(String sourceName, int line) {
0N/A ReferenceTypeSpec refSpec =
0N/A new SourceNameReferenceTypeSpec(sourceName, line);
0N/A return new LineBreakpointSpec(this, refSpec, line);
0N/A }
0N/A
0N/A BreakpointSpec
0N/A createMethodBreakpoint(String classPattern,
28N/A String methodId, List<String> methodArgs) {
0N/A ReferenceTypeSpec refSpec =
0N/A new PatternReferenceTypeSpec(classPattern);
0N/A return new MethodBreakpointSpec(this, refSpec,
0N/A methodId, methodArgs);
0N/A }
0N/A
0N/A ExceptionSpec
0N/A createExceptionIntercept(String classPattern,
0N/A boolean notifyCaught,
0N/A boolean notifyUncaught) {
0N/A ReferenceTypeSpec refSpec =
0N/A new PatternReferenceTypeSpec(classPattern);
0N/A return new ExceptionSpec(this, refSpec,
0N/A notifyCaught, notifyUncaught);
0N/A }
0N/A
0N/A AccessWatchpointSpec
0N/A createAccessWatchpoint(String classPattern, String fieldId) {
0N/A ReferenceTypeSpec refSpec =
0N/A new PatternReferenceTypeSpec(classPattern);
0N/A return new AccessWatchpointSpec(this, refSpec, fieldId);
0N/A }
0N/A
0N/A ModificationWatchpointSpec
0N/A createModificationWatchpoint(String classPattern, String fieldId) {
0N/A ReferenceTypeSpec refSpec =
0N/A new PatternReferenceTypeSpec(classPattern);
0N/A return new ModificationWatchpointSpec(this, refSpec, fieldId);
0N/A }
0N/A
0N/A void delete(EventRequestSpec ers) {
0N/A EventRequest request = ers.getEventRequest();
0N/A synchronized (eventRequestSpecs) {
0N/A eventRequestSpecs.remove(ers);
0N/A }
0N/A if (request != null) {
0N/A request.virtualMachine().eventRequestManager()
0N/A .deleteEventRequest(request);
0N/A }
0N/A notifyDeleted(ers);
0N/A //### notify delete - here?
0N/A }
0N/A
0N/A List<EventRequestSpec> eventRequestSpecs() {
0N/A // We need to make a copy to avoid synchronization problems
0N/A synchronized (eventRequestSpecs) {
0N/A return new ArrayList<EventRequestSpec>(eventRequestSpecs);
0N/A }
0N/A }
0N/A
0N/A // -------- notify routines --------------------
0N/A
28N/A @SuppressWarnings("unchecked")
28N/A private Vector<SpecListener> specListeners() {
28N/A return (Vector<SpecListener>)runtime.specListeners.clone();
0N/A }
0N/A
0N/A void notifySet(EventRequestSpec spec) {
28N/A Vector<SpecListener> l = specListeners();
0N/A SpecEvent evt = new SpecEvent(spec);
0N/A for (int i = 0; i < l.size(); i++) {
28N/A spec.notifySet(l.elementAt(i), evt);
0N/A }
0N/A }
0N/A
0N/A void notifyDeferred(EventRequestSpec spec) {
28N/A Vector<SpecListener> l = specListeners();
0N/A SpecEvent evt = new SpecEvent(spec);
0N/A for (int i = 0; i < l.size(); i++) {
28N/A spec.notifyDeferred(l.elementAt(i), evt);
0N/A }
0N/A }
0N/A
0N/A void notifyDeleted(EventRequestSpec spec) {
28N/A Vector<SpecListener> l = specListeners();
0N/A SpecEvent evt = new SpecEvent(spec);
0N/A for (int i = 0; i < l.size(); i++) {
28N/A spec.notifyDeleted(l.elementAt(i), evt);
0N/A }
0N/A }
0N/A
0N/A void notifyResolved(EventRequestSpec spec) {
28N/A Vector<SpecListener> l = specListeners();
0N/A SpecEvent evt = new SpecEvent(spec);
0N/A for (int i = 0; i < l.size(); i++) {
28N/A spec.notifyResolved(l.elementAt(i), evt);
0N/A }
0N/A }
0N/A
0N/A void notifyError(EventRequestSpec spec, Exception exc) {
28N/A Vector<SpecListener> l = specListeners();
0N/A SpecErrorEvent evt = new SpecErrorEvent(spec, exc);
0N/A for (int i = 0; i < l.size(); i++) {
28N/A spec.notifyError(l.elementAt(i), evt);
0N/A }
0N/A }
0N/A}