This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 11519 - Make setSource protected in WeakListener
Summary: Make setSource protected in WeakListener
Status: CLOSED FIXED
Alias: None
Product: platform
Classification: Unclassified
Component: -- Other -- (show other bugs)
Version: 3.x
Hardware: PC Other
: P4 blocker (vote)
Assignee: anovak
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2001-04-18 14:19 UTC by Joseph Cortopassi
Modified: 2008-12-22 19:38 UTC (History)
0 users

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Joseph Cortopassi 2001-04-18 14:19:42 UTC
I'd like to subclass WeakListener for a listener interface used in the server 
registry so that I can take advantage of the existing infrastructure 
WeakListener has for polling. However, since I can't call setSource, or set the
"source" field, the only time instances of my subclass will be removed after 
their referent is collected is when the event source actually generates an 
event. In the case of the server registry, this doesn't happen very often. If
I could call setSource from my subclass, then the weak listeners could get 
collected more often.
Comment 1 Jesse Glick 2001-04-18 17:00:33 UTC
API enhancements are generally not high priority and would not be considered for
3.2 except to fix critical bugs.

Presumably you could copy the parts of WeakListener you need and do whatever you
like. I am not even convinced there is a need for an enhancement at all; if you
*know* when your listeners should be collected, then simply remove them as
listeners from the source to begin with. WeakListener is only a convenience, so
that you can attach listeners without having to worry about details of when to
detach them. Perhaps in your case it is not appropriate to use it.
Comment 2 Joseph Cortopassi 2001-04-18 18:17:45 UTC
I don't have any problem with the lower priority, and, of course, I know I can 
copy what WeakListener does. I still think this is a necessary enhancement if 
you want others to use WeakListener.

My understanding is that the purpose of WeakListener is make it so that objects 
are not held in memory just because they are listening for events on some other 
objects. Given the way Netbeans tries to free up nodes which aren't being 
displayed, WeakListeners seem like something most objects should be using.

In my case, EJBs register with the server registry. As long as the EJB is 
active (i.e. displayed to the user) I want them to be registered with the server
registry. When they aren't active, I want them to deregister. However, I don't
know of a way to tell that an EJB is no longer being displayed (is there a 
way?), so I don't really know when to deregister. If I don't use a WeakListener 
(or my own version of weak listener), the EJB's registration in the server 
registry will keep the EJB in memory for the entire IDE session.

In any case, the way WeakListener is implemented, when the polling cleanup 
routine is called, it calls the no argument version of removeListener(). This
only removes the listener from the event source if the this.source field is
set. As far as I can tell from reading the code, this.source is never set,
so the no argument removeListener never does anything (am I missing 
something?). Instead, the only time the listener is every removed is when an 
event notification is done and the WeakListener.get method is called. This will 
do an actual remove.

I understand that if I use WeakListener in its current state, it won't stop the 
EJBs from getting collected. It will however build up a large chain of 
WeakListener objects in the server registry. These may be small objects, but
it seems like it would be good to get them cleaned up.
Comment 3 Jesse Glick 2001-04-19 14:13:44 UTC
Someone more knowledgeable about how WeakListener works can answer the detailed
questions at the end. In the meantime, I am assuming that your listeners are
part of a Node or Children object? For Children objects, removeNotify() is the
proper place to clean up listeners (if they are not weak anyway). I presume
there is something similar for Node's but I am not sure (at worst, finalize()).

Ales, I believe you are the right person for WeakListener, if not reassign...
Comment 4 Jan Chalupa 2001-05-06 08:13:35 UTC
Target milestone -> 3.3
Comment 5 anovak 2001-09-12 16:38:45 UTC
Fixed in main trunk.
Comment 6 Jan Zajicek 2001-09-13 10:47:00 UTC
rev1.37
Comment 7 Quality Engineering 2003-07-01 16:23:54 UTC
Resolved for 3.4.x or earlier, no new info since then -> closing.