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

  • ModelMBeanNotificationBroadcaster - addNotificationListener() called multiple times

    hi,

    I have a dynamic MBean which implments the ModelMBeanNotificationBroadcaster interface

    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
    }
    My spring xml file is as follows:

    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>
    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.

    thx,
Working...
X