Wrapping notification listeners?
Jeremy Boynes <[email protected]>
| Newsgroups | gmane.comp.java.mx4j.devel |
|---|---|
| Message-ID | <[email protected]> |
The JavaDoc for MBeanServer.addNotificationListener() says that if the source of a Notification is a reference to the MBean object the MBeanServer will replace it with the MBean's ObjectName. This implies that the MBeanServer needs to intercept the sending of the notification to do this, which MX4J does by wrapping the supplied NotificationListener in a NotificationListenerMBeanServerInterceptor.ListenerWrapper This means that the listener object passed to the mbean is not the same (as in == is false) as the one supplied. I cannot see anything in the spec that describes such behaviour so presumably this is permissible. However, we also wrap the listener when removing it. As a result, the object passed to the mbean on remove not only != the original but also != the wrapped value supplied during the add. The wrapper does delegate equals() and hashCode() to the original instance, so to anything using the Collections interfaces (like MX4J's impl of NotificationBroadcasterSupport) they will appear the same but if the MBean relies on object identity they will appear different. I can't find anything in the spec that defines how identity behaves here - specifically, I don't see a requirement that the identity has to be the same between add() and remove(). Am I missing something? Thanks -- Jeremy ------------------------------------------------------- This SF.Net email is sponsored by: IntelliVIEW -- Interactive Reporting Tool for open source databases. Create drag-&-drop reports. Save time by over 75%! Publish reports on the web. Export to DOC, XLS, RTF, etc. Download a FREE copy at http://www.intelliview.com/go/osdn_nl