Announcement Announcement Module
No announcement yet.
ModelMBeanNotificationBroadcaster - addNotificationListener() called multiple times Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • ModelMBeanNotificationBroadcaster - addNotificationListener() called multiple times


    I have a dynamic MBean which implments the ModelMBeanNotificationBroadcaster interface

    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);
    	public void removeNotificationListener(NotificationListener listener) throws ListenerNotFoundException {
    		for (NotificationConsumer consumer : consumers) {
    			if (consumer.getListener() == listener) {
    	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
    My spring xml file is as follows:

    HTML Code:
    <?xml version="1.0" encoding="UTF-8"?>
      <bean id="mbeanServer" class="">
        <property name="locateExistingServerIfPossible" value="true"></property>
      <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">
    	    <bean class="org.springframework.jmx.export.NotificationListenerBean">
                        <ref bean="myListener"></ref>
                    <property name="mappedObjectNames">
      <bean id="myConnectionMBean" class="org.asc.MyConnectionDynamicMBean">
    	  <property name="provider" ref="..." />
    	  <property name="dao" ref="..." /> 
      <bean id="myListener" class="org.asc.MyListener" />
    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.

    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.