ewgmail
Nov 8th, 2006, 05:23 PM
Hi,
I have a problem implementing a notification publisher in my bean. I implement NotificationPublisherAware but spring never sets my noficationPublisher. Can someone please enlighten on what I am doing wrong.
Thanks
Eric
package com.acme.app.management;
import javax.management.Notification;
import org.springframework.jmx.export.annotation.ManagedR esource;
import org.springframework.jmx.export.notification.Notifi cationPublisher;
import org.springframework.jmx.export.notification.Notifi cationPublisherAware;
import com.acme.eventframework.BaseEventListener;
import com.acme.eventframework.Event;
import com.acme.eventframework.EventFilter;
@ManagedResource(objectName = "bean:name=eventListener", description = "event listener", log = true, logFile = "jmx.log", currencyTimeLimit = 15)
public class NotificationEmitterEventListener extends BaseEventListener implements NotificationPublisherAware {
private NotificationPublisher notificationPublisher;
private long sequenceNumber = 0;
public NotificationEmitterEventListener() {
this.setEventFilter(new EventFilter() {
public boolean evaluate(Event event) {
return true;
}
});
}
public void setNotificationPublisher(NotificationPublisher notificationPublisher) {
this.notificationPublisher = notificationPublisher;
}
public void handleEvent(Event event) {
// Map the event to the JMX event
Notification notification = new Notification(event.getTopic(), this, sequenceNumber, event.getMessage());
notification.setUserData(event.getData());
if (notificationPublisher != null) {
notificationPublisher.sendNotification(notificatio n);
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<!-- this bean must not be lazily initialized if the exporting is to happen -->
<bean id="exporter"
class="org.springframework.jmx.export.MBeanExporter">
<property name="assembler" ref="assembler" />
<property name="namingStrategy" ref="namingStrategy" />
<property name="beans">
<map>
<entry key="bean:name=eventListener" value-ref="notificationEmitterEventListenerListener"/>
</map>
</property>
</bean>
<bean id="jmxAttributeSource"
class="org.springframework.jmx.export.annotation.Annotati onJmxAttributeSource" />
<!-- will create management interface using annotation metadata -->
<bean id="assembler"
class="org.springframework.jmx.export.assembler.MetadataM BeanInfoAssembler">
<property name="attributeSource" ref="jmxAttributeSource" />
</bean>
<!-- will pick up ObjectName from annotation -->
<bean id="namingStrategy"
class="org.springframework.jmx.export.naming.MetadataNami ngStrategy">
<property name="attributeSource" ref="jmxAttributeSource" />
</bean>
<bean id="notificationEmitterEventListener"
class="acme.app.management.NotificationEmitterEventListen er">
<property name="eventDispatcher" ref="eventDispatcher" />
</bean>
</beans>
I have a problem implementing a notification publisher in my bean. I implement NotificationPublisherAware but spring never sets my noficationPublisher. Can someone please enlighten on what I am doing wrong.
Thanks
Eric
package com.acme.app.management;
import javax.management.Notification;
import org.springframework.jmx.export.annotation.ManagedR esource;
import org.springframework.jmx.export.notification.Notifi cationPublisher;
import org.springframework.jmx.export.notification.Notifi cationPublisherAware;
import com.acme.eventframework.BaseEventListener;
import com.acme.eventframework.Event;
import com.acme.eventframework.EventFilter;
@ManagedResource(objectName = "bean:name=eventListener", description = "event listener", log = true, logFile = "jmx.log", currencyTimeLimit = 15)
public class NotificationEmitterEventListener extends BaseEventListener implements NotificationPublisherAware {
private NotificationPublisher notificationPublisher;
private long sequenceNumber = 0;
public NotificationEmitterEventListener() {
this.setEventFilter(new EventFilter() {
public boolean evaluate(Event event) {
return true;
}
});
}
public void setNotificationPublisher(NotificationPublisher notificationPublisher) {
this.notificationPublisher = notificationPublisher;
}
public void handleEvent(Event event) {
// Map the event to the JMX event
Notification notification = new Notification(event.getTopic(), this, sequenceNumber, event.getMessage());
notification.setUserData(event.getData());
if (notificationPublisher != null) {
notificationPublisher.sendNotification(notificatio n);
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<!-- this bean must not be lazily initialized if the exporting is to happen -->
<bean id="exporter"
class="org.springframework.jmx.export.MBeanExporter">
<property name="assembler" ref="assembler" />
<property name="namingStrategy" ref="namingStrategy" />
<property name="beans">
<map>
<entry key="bean:name=eventListener" value-ref="notificationEmitterEventListenerListener"/>
</map>
</property>
</bean>
<bean id="jmxAttributeSource"
class="org.springframework.jmx.export.annotation.Annotati onJmxAttributeSource" />
<!-- will create management interface using annotation metadata -->
<bean id="assembler"
class="org.springframework.jmx.export.assembler.MetadataM BeanInfoAssembler">
<property name="attributeSource" ref="jmxAttributeSource" />
</bean>
<!-- will pick up ObjectName from annotation -->
<bean id="namingStrategy"
class="org.springframework.jmx.export.naming.MetadataNami ngStrategy">
<property name="attributeSource" ref="jmxAttributeSource" />
</bean>
<bean id="notificationEmitterEventListener"
class="acme.app.management.NotificationEmitterEventListen er">
<property name="eventDispatcher" ref="eventDispatcher" />
</bean>
</beans>