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.
Sometimes I need to remove all active listeners for a certain element without them individually (e.g. for supressing the deployment of change events during loading, see the thread "Disabling Events" on mdr-dev for details). This is a very important feature that is available in most of the common event/listener architectures. It also helps to raise the performance of mdr and to avoid memory leaks. I'm thinking of some kind of removeAllListeners() either on the MDRObject itself or on the repository with the MDRObject to remove listeners from being provided as parameter.
Hi Thorsten. Let me better understand the requirements. Do you want to remove all the listeners? Are there any listeners that someone else registered (3rd party plugins) that also need to be removed? Does the removal need to be conditional/parametrizable in any way (remove only events related to associations, instances but keep listeners on transaction events, etc.)? Should there be a method that registers back all the listeners previously removed by removeAll method, or you don't care?
Hi Martin, initially, we need a removeAll that removes all listeners from listening to anything in the repository, no matter where they got registered from (I already added that as a very dirty hack to our local version of MDR). In addition to that, parameterized versions of removeAll based on objects/types from the repository or on event types can be very useful and convenient. It would give us more control and flexibility. Holding and readding the listeners is something that can be very convenient, but it is nothing we currently care about.
Hi Thorsten, I have solved the issue using a little bit different approach - hopefully it will be sufficient for you. The functionality that I have added to MDR allows you to turn off events (instead of removing all the listeners) - this way the registered listeners still stay registered (i.e. they do not need to be re-added) and there should be a performance boost because the event objects are not even created. The events are turned off only for the currently opened transaction (i.e. they will be turned on automatically after the transaction is commited or rolled back). To turn off the events, the only thing you need to do is to call ((NBMDRepositoryImpl) repository).disableEvents() immediately (or later) after you start a transaction. Note that you have to re-cast the repository object to NBMDRepositoryImpl, as I haven't made this method part of the official API.