For more info, here's the relevant javadoc from javax.management.Notification:
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.
ObjectNameMBeanExporter.java to use MBeanExporter
Code:
public class ObjectNameMBeanExporter extends MBeanExporter {
@Override
protected ObjectName registerBeanNameOrInstance(Object mapValue, String beanKey) throws MBeanExportException {
ObjectName objectName = super.registerBeanNameOrInstance(mapValue, beanKey);
if(ObjectNameAware.class.isInstance(mapValue)) {
ObjectNameAware nameAware = (ObjectNameAware)mapValue;
nameAware.setObjectName(objectName);
}
return objectName;
}
}
And make the beans you want to export as notification publishers implement this interface:
Code:
public interface ObjectNameAware {
ObjectName getObjectName();
void setObjectName(ObjectName objectName);
}