Java Reference
In-Depth Information
@ManagedOperation(description = "Replicate files")
public void replicate() throws IOException {
new Notification("replication.start", this, sequenceNumber));
new Notification("replication.complete", this, sequenceNumber));
In this file replicator, you send a JMX notification whenever a replication starts or completes. The
notification is visible both in the standard output in the console as well as in the Notifications node for
your service in JConsole. To see them, you must click Subscribe. Then invoke the replicate() method,
and you'll see two new notifications arrive, much like your e-mail's inbox. The first argument in the
Notification constructor is the notification type, while the second is the notification source. Each
notification requires a sequence number. You can use the same sequence for a notification pair to keep
track of them.
Listening to JMX Notifications
Now let's create a notification listener to listen to JMX notifications. Because a listener will be notified of
many different types of notifications, such as when an
MBean's attribute has changed, you have to filter those notifications that you are interested in handling.
package com.apress.springenterpriserecipes.replicator;
public class ReplicationNotificationListener implements NotificationListener {
public void handleNotification(Notification notification, Object handback) {
if (notification.getType().startsWith("replication")) {
notification.getSource() + " " +
notification.getType() + " #" +
Then you can register this notification listener with your MBean exporter to listen to notifications
emitted from certain MBeans.
<bean id="mbeanExporter"
<property name="defaultDomain" value="bean" />
<property name="notificationListenerMappings">
Search WWH ::

Custom Search