001: //
002: // This file is part of the prose package.
003: //
004: // The contents of this file are subject to the Mozilla Public License
005: // Version 1.1 (the "License"); you may not use this file except in
006: // compliance with the License. You may obtain a copy of the License at
007: // http://www.mozilla.org/MPL/
008: //
009: // Software distributed under the License is distributed on an "AS IS" basis,
010: // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
011: // for the specific language governing rights and limitations under the
012: // License.
013: //
014: // The Original Code is prose.
015: //
016: // The Initial Developer of the Original Code is Andrei Popovici. Portions
017: // created by Andrei Popovici are Copyright (C) 2002 Andrei Popovici.
018: // All Rights Reserved.
019: //
020: // Contributor(s):
021: // $Id: JoinPointRequest.java,v 1.2 2005/06/25 16:53:43 anicoara Exp $
022: // =====================================================================
023: //
024: // (history at end)
025: //
026:
027: package ch.ethz.prose.engine;
028:
029: /**
030: * Abstract class JoinPointRequest represents a request for some execution
031: * event (reaching a joinpoint) inside a virtual machine. The request will serve
032: * as key to a hashtable managed by <code>JoinPointManager</code>.
033: * This hashtable maps joinpoints (<code>JoinPointRequest</code>) to
034: * lists of listeners (<code>JoinPointListeners</code>).
035: *
036: * @version $Revision: 1.2 $
037: * @author Andrei Popovici
038: */
039: public abstract class JoinPointRequest {
040:
041: public abstract int getMask();
042:
043: public abstract String getKind();
044:
045: transient protected final JoinPointManager owner;
046:
047: /**
048: * Constructor.
049: *
050: * @param o Reference to the owner (join point manager)
051: * of this request
052: */
053: protected JoinPointRequest(JoinPointManager o) {
054: this .owner = o;
055: }
056:
057: protected JoinPointRequest() {
058: owner = null;
059: }
060:
061: /**
062: * Enables notification of joinpoint-events which have a
063: * signature equal to this request. This method will instruct the
064: * jvmai-system to set a watch on the joinpoin denoted by this request.
065: * Successive calls to this method without disabling the joinpoint will
066: * be recognized and dropped.
067: *
068: * @param listeners List of <code>JoinPointListener</code>s. This list will
069: * be registered as the aop-tag of the watch set here. When a joinpoint-event
070: * has occured, <code>JoinPointManager</code> will receive this aop-tag as part
071: * of the <code>JoinPoint</code>-object. The content of this tag will be casted
072: * to a list and all <code>JoinPointListener</code> included will be notified.
073: * <p>
074: * <b>Important:</b> Allways use the same list of <code>JoinPointListener<code> for
075: * the same joinpoint! Remember that the instance has been registered as the aop-tag.
076: * If you create a new list and try to enable the same joinpoint with the new list,
077: * the call to this method will be dropped and the new list won't be registered.
078: * To insert a new list, first disable the joinpoint (this will delete the associated
079: * aop-tag) and reenable it then with the new list.
080: */
081: public void enableJoinPoint(Object listeners) {
082: synchronized (owner.enabledJoinPoints) {
083: //System.out.println("JoinPointRequest - this.getClass => " + this.getClass());
084: if (owner.enabledJoinPoints.contains(this ))
085: return;
086:
087: setWatch(listeners);
088: owner.enabledJoinPoints.add(this );
089: }
090: }
091:
092: /**
093: * Disable the notification of joinpoint-events which have
094: * the a signature equal to this request. This method will delete
095: * the watch and the associated aop-tag in the underlying jvmai-system.
096: */
097: public void disableJoinPoint() {
098: synchronized (owner.enabledJoinPoints) {
099: if (!owner.enabledJoinPoints.contains(this ))
100: return;
101: clearWatch();
102: owner.enabledJoinPoints.remove(this );
103: }
104: }
105:
106: /**
107: * Sets the watch in the underlzing jvmai-system. This method has to
108: * be implemented by subclasses of <code>JoinPointRequest</code>.
109: * It will be called only by <code>enableJoinPoint(List listeners)</code>.
110: */
111: protected abstract void setWatch(Object listeners);
112:
113: /**
114: * Clears the watch in the underlzing jvmai-system. This method has to
115: * be implemented by subclasses of <code>JoinPointRequest</code>.
116: * It will be called only by <code>disableJoinPoint()</code>.
117: */
118: protected abstract void clearWatch();
119:
120: /**
121: * Every subclass of <code>JoinPointRequest</code> must provide an
122: * implementation for this method in order to be used as key to the
123: * hashtable administrated by the <code>JoinPointManager</code>.
124: */
125: public abstract boolean equals(Object other);
126:
127: /**
128: * Every subclass of <code>JoinPointRequest</code> must provide an
129: * implementation for this method in order to be used as key to the
130: * hashtable administrated by the <code>JoinPointManager</code>.
131: */
132: public abstract int hashCode();
133:
134: }
135:
136: //======================================================================
137: //
138: // $Log: JoinPointRequest.java,v $
139: // Revision 1.2 2005/06/25 16:53:43 anicoara
140: // Added additional comments
141: //
142: // Revision 1.1.1.1 2003/07/02 15:30:51 apopovic
143: // Imported from ETH Zurich
144: //
145: // Revision 1.2 2003/05/20 16:05:04 popovici
146: //
147: // New QueryManager replaces functionality in AspectManager (better Soc)
148: // New 'Surrogate' classes for usage in the QueryManager
149: // The 'RemoteAspectManager' and tools modified to use the Surrogates and the QueryManager
150: //
151: // Revision 1.1 2003/05/05 13:58:27 popovici
152: // renaming from runes to prose
153: //
154: // Revision 1.10 2003/04/26 18:51:38 popovici
155: // 1 Bug fix which lead to a refactoring step:
156: // 1. the bug: 'JoinPointRequests' used to write to a static list, which survived a startup/teardown;
157: // now this list belongs to the JoinPointManager;
158: // 2. the refactoring: the JoinPointManager now creates (and shares state) with join-points.
159: //
160: // Revision 1.9 2003/04/17 12:49:27 popovici
161: // Refactoring of the crosscut package
162: // ExceptionCut renamed to ThrowCut
163: // McutSignature is now SignaturePattern
164: //
165: // Revision 1.8 2003/04/17 08:47:58 popovici
166: // Important functionality additions
167: // - Cflow specializers
168: // - Restructuring of the MethodCut, SetCut, ThrowCut, and GetCut (they are much smaller)
169: // - Transactional capabilities
170: // - Total refactoring of Specializer evaluation, which permits fine-grained distinction
171: // between static and dynamic specializers.
172: // - Functionality pulled up in abstract classes
173: // - Uniformization of advice methods patterns and names
174: //
175: // Revision 1.7 2003/03/04 18:36:04 popovici
176: // Organization of imprts
177: //
178: // Revision 1.6 2003/03/04 11:27:31 popovici
179: // Important refactorization step (march):
180: // - removal of 'JoinPointEvents'; JoinPoints now have the same function as events
181: // - reimplementation of the JVMAIDebuggerAspectInterface (better performance, coding conventions, removal of ProseVM
182: // structures
183: //
184: // Revision 1.5 2003/02/11 14:28:47 popovici
185: // Serialization Problems solved; for MethodCut; Used to deserialize
186: // with null values for 'AdviceMethod'. Insertion caused problems
187: //
188: // Revision 1.4 2002/03/28 13:48:50 popovici
189: // Mozilla-ified
190: //
191: // Revision 1.3 2002/02/21 12:44:30 popovici
192: // Dispatching efficiency issues:
193: // - Hook methods in the join point manager are now inlined (they
194: // do not use any more 'notifyListeners'
195: // - Aop tags are now of type 'ListenerList' which allows efficient
196: // array iteration
197: // - 'setWatch' methods modifiy to accomodate ListenerLists on EventRequests
198: //
199: // Revision 1.2 2002/02/05 10:01:09 smarkwal
200: // JVMDI-specific code replaced by JVMAI. Prose-implementation classes and reflection package removed.
201: //
202: // Revision 1.1.1.1 2001/11/29 18:13:19 popovici
203: // Sources from runes
204: //
205: // Revision 1.1.2.1 2000/10/16 20:01:09 popovici
206: // Documentation added.
207: //
208: // Revision 1.1 2000/10/16 11:55:40 popovici
209: // Initial Revision
210: //
|