JDK-6440827 : StandardEmitter subclasses could be allowed to use "this" as their NotificationEmitter
  • Type: Enhancement
  • Component: core-svc
  • Sub-Component: javax.management
  • Affected Version: 6
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2006-06-20
  • Updated: 2010-07-29
  • Resolved: 2008-09-17
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 7
7 b34Fixed
Related Reports
Relates :  
Description
Creating a subclass of StandardEmitterMBean could be simplified by removing the necessity to create a NotificationEmitter instance.  Currently you have to do something like this:

public class MyEmitter extends StandardEmitterMBean implements MyMBean {
    public MyEmitter() {
        super(MyMBean.class, makeNotificationEmitter());
    }

    private static final MBeanNotificationInfo notificationInfo =
        new MBeanNotificationInfo(new String[] {"a.b", "c.d"},
                                  Notification.class.getName(),
                                  "Description");

    private static NotificationEmitter makeNotificationEmitter() {
        return new NotificationBroadcasterSupport(notificationInfo);
    }
}

It would be nice to be able to do this instead:

public class MyEmitter extends StandardEmitterMBean implements MyMBean {
    public MyEmitter() {
        super(this, MyMBean.class);
    }

    private static final MBeanNotificationInfo notificationInfo =
        new MBeanNotificationInfo(new String[] {"a.b", "c.d"},
                                  Notification.class.getName(),
                                  "Description");

    @Override
    public MBeanNotificationInfo[] getNotificationInfo() {
        return notificationInfo;
    }
}

The current need to construct the NotificationEmitter within the superconstructor call is not obvious, and this simpler pattern would be more so.

This change does not imply a change to the API signature but it does imply changing the implementation.  Currently the replacement code above will lead to an infinite recursion.

Comments
SUGGESTED FIX For "this" read "null".
18-06-2008

EVALUATION The current plan is to allow the NotificationEmitter parameter of any of the constructors to be null, which will cause a NotificationBroadcasterSupport to be instantiated. The user will then have no way to access this NotificationBroadcasterSupport directly, but since they rarely want to do anything other than sendNotification with that is not a problem. sendNotification is accessible through StandardEmitterMBean.sendNotification. The use of "this" as originally suggested would be confusing.
18-06-2008

SUGGESTED FIX The implication is that the StandardEmitterMBean protected constructors should notice when the NotificationEmitter parameter is "this" and replace it with a new NotificationBroadcasterSupport.
20-06-2006

EVALUATION Simple implementation change. Would need to be accompanied by an example in the documentation.
20-06-2006