» tagged pages
» logout
Spring
Return to Spring's corner

JMX notifications with Spring (2)

Tags Applied to this Entry

1 person has tagged this page:

The second part of the thread describe the end of the support of JMX notifications in Spring. Like the previous one, it describes the patch I have written to address the issue SPR-680 in JIRA.

See the second zip file (SpringJMX_Notification_v1.1.zip) on the issue for the implementation of this patch.

Support of filters

When a JMX notification listener is added to an MBean, you can pass a filter to select notifications the listener will accept. In our case, we use the class NotificationFilterSupport which implements NotificationFilter and allow configure the allow and deny of notifications types.

public class NotificationListenerSupport {
  ...
  public synchronized boolean isNotificationEnabled(
                       Notification notification) {...}
  public synchronized void enableType(String type)
               throws IllegalArgumentException {...}
  public synchronized void disableType(String type) {...}
  public synchronized void disableAllTypes() {...}
  public synchronized Vector getEnabledTypes() {...}
  ...
}

To associate filters with listeners on the MBeanExporter class, you need to set the notificationFilters property which tokens are delimited by the character ','. If the element starts with the character '+', the nofication type is allowed and if it starts with '-', the type is denied. The following listing shows an example of use.

<bean id="exporter" class="org.springframework.jmx.export.MBeanExporter">
  <property name="beans">
    ...
  </property>
  <property name="notificationListeners">
    <list>
      <ref local="listener"/>
    </list>
  </property>
  <property name="notificationFilters">
    <value>DENY_ALL_TYPES,+test</value>
  </property>
</bean>

Note: This feature is supported on the NotifierFactoryBean class too.

Support of handback

Handback is an object specified on the call of addNotificationListener which is then given to the listener when a notification is triggered. The patch supports now this feature with the handback property of the MBeanExporter class. The following listing shows an example of use.

<bean id="exporter" class="org.springframework.jmx.export.MBeanExporter">
  <property name="beans">
    ...
  </property>
  <property name="notificationListeners">
    <list>
      <ref local="listener"/>
    </list>
  </property>
  <property name="notificationFilters">
    <value>DENY_ALL_TYPES,+test</value>
  </property>
  <property name="handback" value="test handback"/>
</bean>

Note: This feature is supported on the NotifierFactoryBean class too.

Username:
Password:
(or Cancel)