Listing 1

package WLDJ;

import java.io.Serializable;
import javax.management.AttributeChangeNotification;
import javax.management.Notification;
import javax.management.NotificationListener;

public class MyAttributeChangeListener
    implements javax.management.NotificationListener, Serializable
{
    String mbeanName;

    public MyAttributeChangeListener(String mbeanName)
    {
        this.mbeanName = mbeanName;
    }

    public void handleNotification(Notification n, Object handback)
    {
        if (n instanceof AttributeChangeNotification) {
            AttributeChangeNotification acn =
                (AttributeChangeNotification)notification;
            System.out.println("MBean " + mbeanName + " attribute " +
                               acn.getAttributeName() + " of type " +
                               acn.getAttributeType() +
                               " changed from " + acn.getOldValue() +
                               " to " + acn.getNewValue());
        }
        else {
            System.out.println("Unexpected notification type: " +
                               notification.getClass().getName());
        }
    }
}

Listing 2

package WLDJ;

import javax.management.Notification;
import javax.management.NotificationFilter;

public class MyAttributeChangeFilter implements NotificationFilter
{
    public boolean isNotificationEnabled(Notification n)
    {
        if (n instanceof AttributeChangeNotification)
            return true;
        else
            return false;
    }
}

Listing 3

AttributeList monitorAttributes = new AttributeList();
Attribute observedObjectAttribute =
    new Attribute("ObservedObject", queueMBeanName);
monitorAttributes.add(observedObjectAttribute);

Attribute observedAttributeAttribute =
    new Attribute("ObservedAttribute",
                  "PendingRequestCurrentCount");
monitorAttributes.add(observedAttributeAttribute);

...

monitorAttributes =
    mbeanServer.setAttributes(monitorMBeanName,
                              monitorAttributes);

Additional Source Code Zip file 6 KB