2010-11-25 7 views
9

He configurado un ManagedBean usando la anotación @ManagedResource usando Spring. Y también asignó un JMX NotificationListener a esto. Pero estoy viendo que el Oyente nunca es expulsado/ejecutado.No puedo hacer que Spring JMX NotificationListener funcione

Éstos son los archivos de configuración relacionados:

<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
          http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> 

    <bean id="myMBeanServer" 
     class="org.springframework.jmx.support.MBeanServerFactoryBean"> 
     <!-- indicate to first look for a server --> 
     <property name="locateExistingServerIfPossible" value="true" /> 
    </bean> 

    <!-- MBean auto exporter --> 
    <bean id="exporter" class="org.springframework.jmx.export.MBeanExporter" 
     lazy-init="false"> 
     <property name="server" ref="myMBeanServer" /> 
     <property name="assembler" ref="assembler" /> 
     <property name="namingStrategy" ref="namingStrategy" /> 
     <property name="notificationListenerMappings"> 
      <map> 
       <entry key="myMBean" 
        value-ref="myMBeanNotificationListener" /> 
      </map> 
     </property> 
    </bean> 

    <!-- The assembler --> 
    <bean id="assembler" 
     class="org.springframework.jmx.export.assembler.MetadataMBeanInfoAssembler"> 
     <property name="attributeSource" ref="attributeSourceStrategy" /> 
    </bean> 

    <!-- The naming strategy --> 
    <bean id="namingStrategy" 
     class="org.springframework.jmx.export.naming.MetadataNamingStrategy"> 
     <property name="attributeSource" ref="attributeSourceStrategy" /> 
    </bean> 

    <!-- The attributeSource strategy --> 
    <bean id="attributeSourceStrategy" 
     class="org.springframework.jmx.export.annotation.AnnotationJmxAttributeSource" /> 

    <!-- MyMBean --> 
    <bean id="myMBean" 
     class="com.sample.MyMBean" /> 

    <!-- MBean Notification Listener --> 
    <bean id="myMBeanNotificationListener" 
     class="com.sample.MyMBeanNotificationListener" /> 
</beans> 

Aquí es cómo se ve la clase MyMBean como:

@ManagedResource(description = "My Mbean", objectName = "com.sample:bean=myMBean") 
public class MyMBean { 

    private boolean isAvailable = true; 

    @ManagedAttribute(description = "isAvailable", defaultValue = "true") 
    public void setAvailable(boolean flag) { 
     this.isAvailable = flag; 
    } 
} 

Y, por último, aquí es como el NotificationListener parece:

public class MyMBeanNotificationListener implements 
     NotificationListener { 

    @Override 
    public void handleNotification(Notification notification, Object handback) { 
     System.out.println("In Notification Listener" + notification); 
    } 

} 

Cualquier idea por la cual NotificationListener es no t ser ejecutado? No hay ninguna excepción lanzada por el código.

¿Alguien ha sacado el JMX NotificationListener s con Spring?

+1

¿Qué esperas si 'MyMBean' no publica las notificaciones? – axtavt

+0

axtavt, por favor revise mi pregunta anterior http://stackoverflow.com/questions/4260398/jmx-spring-when-is-a-jmxnotification-broadcasted allí alguien confirmó que el cambio de atributo difunde una notificación JMX. Con el oyente anterior esperaba capturar eso. ¿Estás seguro de que necesitamos un editor y el cambio de atributo no envía notificaciones automáticamente? ¡Gracias! – peakit

+0

El artículo vinculado en la respuesta a su pregunta anterior dice claramente que necesita transmitir 'AttributeChangeNotification's manualmente. – axtavt

Respuesta

0

¿Has visto las notificaciones aparecer en jConsole o jVisualVM?

pruebe a cambiar:

<entry key="myMBean" value-ref="myMBeanNotificationListener" /> 

a:

<entry key="com.sample:bean=myMBean" value-ref="myMBeanNotificationListener" /> 

Si no fuera por las notificaciones, se podía simpify el XML anterior a:

<context:mbean-export default-domain="myDomain"/> 
Cuestiones relacionadas