JDK-6252526 : Create subclass of javax.management.StandardMBean that is a NotificationEmitter
  • Type: Enhancement
  • Component: core-svc
  • Sub-Component: javax.management
  • Affected Version: 5.0,6
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic,windows_xp
  • CPU: generic,x86
  • Submitted: 2005-04-08
  • Updated: 2010-07-29
  • Resolved: 2005-06-08
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6
6 b40Fixed
Related Reports
Relates :  
Relates :  
Description
The class javax.management.StandardMBean allows you to create a custom Standard MBean.  This is useful when (a) your MBean can't have the naming link between the class Something and the interface SomethingMBean, and (b) when you want to override certain methods that allow you to customize the contents of the MBeanInfo for your MBean.

However, if your MBean must be a NotificationBroadcaster (or NotificationEmitter) then you must do the following:
(1) Subclass StandardMBean.
(2) Override getMBeanInfo() so that it calls super.getMBeanInfo() and the constructs another MBeanInfo that takes the attributes, operations, etc and adds the MBeanNotificationInfo[] appropriate for your MBean.
(3) Implements the NotificationEmitter interface, typically by forwarding its four methods to an instance of NotificationBroadcasterSupport.

This is all doable, but tedious.  It would be very useful if a subclass of StandardMBean were already defined to do this for you.  It might look something like this:

public class StandardEmitterMBean extends StandardMBean implements NotificationEmitter {
    public <T> StandardEmitterMBean(T implementation, Class<T> mbeanInterface,
                                    NotificationEmitter emitter) {...}
    protected StandardEmitterMBean(Class<?> mbeanInterface,
                                   NotificationEmitter emitter) {...}
    // ...methods from NotificationEmitter implemented by forwarding to
    // this.emitter
}

Now, to make a StandardMBean that emits notifications, you do this:
- construct your MBeanNotificationInfo[]
- construct a NotificationBroadcasterSupport whose getMBeanInfo() returns
  your MBeanNotificationInfo[] (see RFE 4506105 for an easy way to do this)
- construct a StandardEmitterMBean with the appropriate implementation class
  and your NotificationBroadcasterSupport

There is an even easier option, which is for the "implementation" parameter to already implement NotificationEmitter (for instance by subclassing NotificationBroadcasterSupport), in which case you can do:
    new StandardEmitterMBean(impl, SomethingMBean.class, impl);

Although it is tempting to avoid adding a new class and simply add additional constructors to the existing StandardMBean class, this is not a good idea.  For it to work, StandardMBean would have to implement NotificationEmitter.  Much existing code assumes that if a class implements NotificationEmitter then it really does emit notifications, but with this change *all* StandardMBeans would implement NotificationEmitter.
###@###.### 2005-04-08 12:59:58 GMT

Comments
EVALUATION Not much more needed than what is covered in the Description. ###@###.### 2005-04-08 12:59:58 GMT Could be useful also to have shorthand constructors that take an MBeanNotificationInfo[] instead of NotificationEmitter and that make a NotificationEmitter based on that. In that case, there would need to be a public sendNotification method that forwards to the private NotificationEmitter's sendNotification method. ###@###.### 2005-04-25 09:19:08 GMT
08-04-2005