hi,
I have a dynamic MBean which implments the ModelMBeanNotificationBroadcaster interface
My spring xml file is as follows:Code:public class MyDynamicMBean implements DynamicMBean, SelfNaming, ModelMBeanNotificationBroadcaster { List<NotificationConsumer> consumers = new ArrayList<NotificationConsumer>(); // ModelMBeanNotificationBroadcaster methods public void addNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback) throws IllegalArgumentException { System.out.println("adding notification listener now -----"); NotificationConsumer consumer = new NotificationConsumer(listener, filter, handback); consumers.add(consumer); } public void removeNotificationListener(NotificationListener listener) throws ListenerNotFoundException { for (NotificationConsumer consumer : consumers) { if (consumer.getListener() == listener) { consumers.remove(consumer); break; } } } ..... protected class NotificationConsumer { private NotificationListener listener; private NotificationFilter filter; private Object handback; public NotificationConsumer(NotificationListener listener, NotificationFilter filter, Object handback) { this.listener = listener; this.filter = filter; this.handback = handback; } public NotificationFilter getFilter() { return filter; } public Object getHandback() { return handback; } public NotificationListener getListener() { return listener; } } // class NotificationConsumer }
I deploy my app. in tomcat. What I notice is that addNotificationListener() gets called once when the app. starts up. This is ok and what I expect. But whats unexpected is that when I launch JDK JConsole to view my MBean, addNotificationListener() is called again.HTML Code:<?xml version="1.0" encoding="UTF-8"?> <beans> <bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean"> <property name="locateExistingServerIfPossible" value="true"></property> </bean> <bean id="exporter" class="org.springframework.jmx.export.MBeanExporter" lazy-init="false"> <property name="autodetect" value="true"/> <property name="assembler" ref="assembler"/> <property name="namingStrategy" ref="namingStrategy"/> <property name="server" ref="mbeanServer" /> <property name="exposeManagedResourceClassLoader" value="true"/> <property name="notificationListeners"> <list> <bean class="org.springframework.jmx.export.NotificationListenerBean"> <constructor-arg> <ref bean="myListener"></ref> </constructor-arg> <property name="mappedObjectNames"> <list> <value>myConnectionMBean</value> </list> </property> </bean> </list> </property> </bean> <bean id="myConnectionMBean" class="org.asc.MyConnectionDynamicMBean"> <property name="provider" ref="..." /> <property name="dao" ref="..." /> </bean> <bean id="myListener" class="org.asc.MyListener" /> .... </beans>
My question is why is it called a second time. My beans are singletons.. so how is it even possible for addNotificationListener() to be called again.
thx,


Reply With Quote