Announcement Announcement Module
No announcement yet.
retrieve exported MBean ObjectName ? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • retrieve exported MBean ObjectName ?

    I am using the MBeanExporter for registering various MBeans, specifically for beans that implement NotificationPublisherAware. One of the standard arguments for a Notification object is the source, which it is advised to provide as the MBean's ObjectName. Thus far my MBeans are totally unaware of their ObjectName, and I'm using the standard KeyNamingStrategy.

    Is there a way for exported MBeans to look up their canonical ObjectName at runtime?
    Otherwise it seems I'll have to repeat the "beans" map key string in various places, which isn't pretty.

  • #2
    For more info, here's the relevant javadoc from

    The Notification class represents a notification emitted by an MBean. It contains a reference to the source MBean: if the notification has been forwarded through the MBean server, and the original source of the notification was a reference to the emitting MBean object, then the MBean server replaces it by the MBean's ObjectName. ...
    It is strongly recommended that notification senders use the object name rather than a reference to the MBean object as the source.
    I didn't find an easy way to look up the ObjectName for an exported bean. Here was my solution, for anyone else looking to follow the strong recommendation above. to use MBeanExporter
    public class ObjectNameMBeanExporter extends MBeanExporter {
        protected ObjectName registerBeanNameOrInstance(Object mapValue, String beanKey) throws MBeanExportException {
            ObjectName objectName = super.registerBeanNameOrInstance(mapValue, beanKey);
            if(ObjectNameAware.class.isInstance(mapValue)) {
                ObjectNameAware nameAware = (ObjectNameAware)mapValue;
            return objectName;
    And make the beans you want to export as notification publishers implement this interface:
    public interface ObjectNameAware {
        ObjectName getObjectName();
        void setObjectName(ObjectName objectName);