Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6440827

StandardEmitter subclasses could be allowed to use "this" as their NotificationEmitter

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P4 P4
    • 7
    • 6
    • core-svc
    • None
    • b34
    • generic
    • generic

      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.

            emcmanus Eamonn McManus
            emcmanus Eamonn McManus
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: