|
From: Lukas P. <pe...@us...> - 2002-07-17 22:11:18
|
Update of /cvsroot/javaprofiler/jpiimpl/net/sourceforge/javaprofiler/jpiimpl/realtime
In directory usw-pr-cvs1:/tmp/cvs-serv18804
Modified Files:
AllocThreadMethodR.java ImageR.java
Log Message:
added children events to some objects
Index: AllocThreadMethodR.java
===================================================================
RCS file: /cvsroot/javaprofiler/jpiimpl/net/sourceforge/javaprofiler/jpiimpl/realtime/AllocThreadMethodR.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -r1.8 -r1.9
*** AllocThreadMethodR.java 11 Jul 2002 18:17:23 -0000 1.8
--- AllocThreadMethodR.java 17 Jul 2002 22:11:14 -0000 1.9
***************
*** 77,82 ****
/** A list of event listeners for this component. */
! protected EventListenerList listenerList = new EventListenerList();
! protected transient AllocStatEvent allocEvent;
/** Constructs multi-rooted object
--- 77,86 ----
/** A list of event listeners for this component. */
! protected EventListenerList listenerList=new EventListenerList();
! protected transient AllocStatEvent allocEvent;
! private Map listenersMap=new HashMap(1);
! private EventListenerList allocTypeThreadMethodListeners=new
! EventListenerList();
! private EventListenerList allocThreadTraceListeners=new EventListenerList();
/** Constructs multi-rooted object
***************
*** 211,218 ****
--- 215,228 ----
void addAllocTypeThreadMethod(AllocTypeThreadMethodRef o) {
allocTypeThreadMethods.add(o);
+ image.fireChildrenAdded(new ChildrenEvent(this, Constants.
+ ALLOC_TYPE_THREAD_METHOD, new Object[]{o}, new int[]{
+ allocTypeThreadMethods.size()-1}), listenersMap);
}
void addAllocThreadTrace(AllocThreadTraceRef o) {
allocThreadTraces.add(o);
+ image.fireChildrenAdded(new ChildrenEvent(this, Constants.
+ ALLOC_THREAD_TRACE, new Object[]{o}, new int[]{
+ allocThreadTraces.size()-1}), listenersMap);
}
***************
*** 330,339 ****
// ---------- listeners
! public void removeChildrenListener(int type, ChildrenListener listener) {
! // PENDING
! }
!
! public void addChildrenListener(int type, ChildrenListener listener) {
! // PENDING
}
--- 340,368 ----
// ---------- listeners
! /**
! * Removes an <code>ChildrenListener</code> from this object.
! * @param type Type of children to listen events for. Constants are defined
! * in net.sourceforge.javaprofiler.jpi.Constants.
! * @param l the listener to be removed
! */
! public void removeChildrenListener(int type, ChildrenListener l) {
! image.removeChildrenListenerChecked(type, l, listenersMap,
! new int[] {Constants.ALLOC_TYPE_THREAD_METHOD,
! Constants.ALLOC_THREAD_TRACE});
! }
!
! /**
! * Adds an <code>ChildrenListener</code> to this object.
! * <strong>Warning:</strong> Events are not dispatched in the swing event-
! * dispatching thread, rather they are dispatched in the thread which
! * caused new data to be loaded.
! * @param type Type of children to listen events for. Constants are defined
! * in net.sourceforge.javaprofiler.jpi.Constants.
! * @param l the listener to be added
! */
! public void addChildrenListener(int type, ChildrenListener l) {
! image.addChildrenListenerChecked(type, l, listenersMap,
! new int[] {Constants.ALLOC_TYPE_THREAD_METHOD,
! Constants.ALLOC_THREAD_TRACE});
}
Index: ImageR.java
===================================================================
RCS file: /cvsroot/javaprofiler/jpiimpl/net/sourceforge/javaprofiler/jpiimpl/realtime/ImageR.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -r1.10 -r1.11
*** ImageR.java 17 Jul 2002 12:25:36 -0000 1.10
--- ImageR.java 17 Jul 2002 22:11:14 -0000 1.11
***************
*** 1224,1240 ****
if (type==Constants.THREAD)
threadListeners.remove(ChildrenListener.class, l);
! if (type==Constants.TYPE)
typeListeners.remove(ChildrenListener.class, l);
! if (type==Constants.CLASS)
classListeners.remove(ChildrenListener.class, l);
! if (type==Constants.METHOD)
methodListeners.remove(ChildrenListener.class, l);
! if (type==Constants.CPU_TRACE)
CPUTraceListeners.remove(ChildrenListener.class, l);
! if (type==Constants.ALLOC_TRACE)
allocTraceListeners.remove(ChildrenListener.class, l);
! if (type==Constants.MON_TRACE)
monTraceListeners.remove(ChildrenListener.class, l);
! if (type==Constants.THREADGROUP)
threadgroupListeners.remove(ChildrenListener.class, l);
else
--- 1224,1240 ----
if (type==Constants.THREAD)
threadListeners.remove(ChildrenListener.class, l);
! else if (type==Constants.TYPE)
typeListeners.remove(ChildrenListener.class, l);
! else if (type==Constants.CLASS)
classListeners.remove(ChildrenListener.class, l);
! else if (type==Constants.METHOD)
methodListeners.remove(ChildrenListener.class, l);
! else if (type==Constants.CPU_TRACE)
CPUTraceListeners.remove(ChildrenListener.class, l);
! else if (type==Constants.ALLOC_TRACE)
allocTraceListeners.remove(ChildrenListener.class, l);
! else if (type==Constants.MON_TRACE)
monTraceListeners.remove(ChildrenListener.class, l);
! else if (type==Constants.THREADGROUP)
threadgroupListeners.remove(ChildrenListener.class, l);
else
***************
*** 1254,1270 ****
if (type==Constants.THREAD)
threadListeners.add(ChildrenListener.class, l);
! if (type==Constants.TYPE)
typeListeners.add(ChildrenListener.class, l);
! if (type==Constants.CLASS)
classListeners.add(ChildrenListener.class, l);
! if (type==Constants.METHOD)
methodListeners.add(ChildrenListener.class, l);
! if (type==Constants.CPU_TRACE)
CPUTraceListeners.add(ChildrenListener.class, l);
! if (type==Constants.ALLOC_TRACE)
allocTraceListeners.add(ChildrenListener.class, l);
! if (type==Constants.MON_TRACE)
monTraceListeners.add(ChildrenListener.class, l);
! if (type==Constants.THREADGROUP)
threadgroupListeners.add(ChildrenListener.class, l);
else
--- 1254,1270 ----
if (type==Constants.THREAD)
threadListeners.add(ChildrenListener.class, l);
! else if (type==Constants.TYPE)
typeListeners.add(ChildrenListener.class, l);
! else if (type==Constants.CLASS)
classListeners.add(ChildrenListener.class, l);
! else if (type==Constants.METHOD)
methodListeners.add(ChildrenListener.class, l);
! else if (type==Constants.CPU_TRACE)
CPUTraceListeners.add(ChildrenListener.class, l);
! else if (type==Constants.ALLOC_TRACE)
allocTraceListeners.add(ChildrenListener.class, l);
! else if (type==Constants.MON_TRACE)
monTraceListeners.add(ChildrenListener.class, l);
! else if (type==Constants.THREADGROUP)
threadgroupListeners.add(ChildrenListener.class, l);
else
***************
*** 1295,1298 ****
--- 1295,1368 ----
for (int i = listeners.length-2; i>=0; i-=2) {
((ChildrenListener)listeners[i+1]).childrenAdded(e);
+ }
+ }
+
+ // ---------------------------------------------- children listener support
+
+ /** Removes an ChildrenListener from a specific event listener list.
+ * Event listener lists for different child types are hold in a Map.
+ * @param type Describes child type. Constants are defined in
+ * net.sourceforge.javaprofiler.jpi.Constants.
+ * @param l the listener to be added
+ * @param lMap map holding listener lists for different child types
+ * @param allowed Values that are allowed in the type argument. Other
+ * values cause an exception to be thrown
+ */
+ void removeChildrenListenerChecked(int type, ChildrenListener l, Map lMap,
+ int[] allowed) {
+ int i;
+ for (i=0; i<allowed.length; i++)
+ if (type==allowed[i]) break;
+ if (i==allowed.length)
+ throw new RuntimeException("Illegal child type.");
+
+ EventListenerList list=(EventListenerList) lMap.get(new Integer(type));
+ if (list!=null) {
+ list.remove(ChildrenListener.class, l);
+ }
+ }
+
+ /** Adds an ChildrenListener into a specific event listener list. Event
+ * listener lists for different child types are hold in a Map.
+ * @param type Describes child type. Constants are defined in
+ * net.sourceforge.javaprofiler.jpi.Constants.
+ * @param l the listener to be added
+ * @param lMap map holding listener lists for different child types
+ * @param allowed Values that are allowed in the type argument. Other
+ * values cause an exception to be thrown
+ */
+ void addChildrenListenerChecked(int type, ChildrenListener l, Map lMap,
+ int[] allowed) {
+ int i;
+ for (i=0; i<allowed.length; i++)
+ if (type==allowed[i]) break;
+ if (i==allowed.length)
+ throw new RuntimeException("Illegal child type.");
+
+ EventListenerList list=(EventListenerList) lMap.get(new Integer(type));
+ if (list==null) {
+ list=new EventListenerList();
+ lMap.put(new Integer(type), list);
+ }
+ list.add(ChildrenListener.class, l);
+ }
+
+ /**
+ * Notifies all listeners that have registered interest for notification
+ * on this event type. Listeners list is taken from a map.
+ * @param e event to be fired
+ * @param lMap map holding listener lists for different child types
+ */
+ void fireChildrenAdded(ChildrenEvent e, Map lMap) {
+ int type=e.getType();
+ EventListenerList list=(EventListenerList) lMap.get(new Integer(type));
+ if (list!=null) {
+ // Guaranteed to return a non-null array
+ Object[] listeners = list.getListenerList();
+ // Process the listeners last to first, notifying
+ // those that are interested in this event
+ for (int i = listeners.length-2; i>=0; i-=2) {
+ ((ChildrenListener)listeners[i+1]).childrenAdded(e);
+ }
}
}
|