Hi all,
I want this feature, when I add notificationListenerMappings, MBeanExporter can support ObjectName wildcard characters.
For example
MBeanExporter will add EnglishListen to all MBeans that ObjectName match com.toabao.jmx:type=en*HTML Code:<property name="notificationListenerMappings"> <map> <entry key="com.taobao.jmx:type=en*"> <bean class="com.taobao.jmx.spring.notification.EnglishListen" /> </entry> </map> </property>
the code of registerNotificationListeners method now is:
just change these toCode:private void registerNotificationListeners() throws MBeanExportException { for (int i = 0; i < this.notificationListeners.length; i++) { NotificationListenerBean bean = this.notificationListeners[i]; NotificationListener listener = bean.getNotificationListener(); NotificationFilter filter = bean.getNotificationFilter(); Object handback = bean.getHandback(); ObjectName[] namesToRegisterWith = getObjectNamesForNotificationListener(bean); for (int j = 0; j < namesToRegisterWith.length; j++) { ObjectName objectName = namesToRegisterWith[j]; try { this.server.addNotificationListener(objectName, listener, filter, handback); } catch (InstanceNotFoundException ex) { throw new MBeanExportException("Unable to register NotificationListener for MBean [" + objectName + "] because that MBean instance does not exist", ex); } } } }
Code:for (int i = 0; i < this.notificationListeners.length; i++) { NotificationListenerBean bean = this.notificationListeners[i]; NotificationListener listener = bean.getNotificationListener(); NotificationFilter filter = bean.getNotificationFilter(); Object handback = bean.getHandback(); ObjectName[] namesToRegisterWith = getObjectNamesForNotificationListener(bean); for (int j = 0; j < namesToRegisterWith.length; j++) { ObjectName objectName = namesToRegisterWith[j]; try { Set<ObjectName> objectNameList = server.queryNames(objectName, null); if(objectNameList != null && objectNameList.size() > 0) { for(ObjectName oname : ObjectName) { this.server.addNotificationListener(oname, listener, filter, handback); } } } catch (InstanceNotFoundException ex) { throw new MBeanExportException("Unable to register NotificationListener for MBean [" + objectName + "] because that MBean instance does not exist", ex); } } } }


Reply With Quote