1 8 9 package mx4j.tools.stats; 10 11 import java.util.Date ; 12 import javax.management.AttributeChangeNotification ; 13 import javax.management.AttributeChangeNotificationFilter ; 14 import javax.management.Notification ; 15 import javax.management.NotificationListener ; 16 17 24 public class NotificationStatisticsRecorder extends ObserverStatisticsRecorder implements NotificationListener 25 { 26 protected boolean registered = false; 27 28 protected void startObserving() throws Exception 29 { 30 AttributeChangeNotificationFilter filter = new AttributeChangeNotificationFilter (); 31 filter.enableAttribute(observedAttribute); 32 server.addNotificationListener(observedName, this, filter, null); 33 registered = true; 34 } 35 36 protected void stopObserving() throws Exception 37 { 38 if (registered) 39 { 40 server.removeNotificationListener(observedName, this); 41 } 42 } 43 44 public void handleNotification(Notification notification, Object object) 45 { 46 AttributeChangeNotification anot = (AttributeChangeNotification )notification; 47 addEntry(new Date (), (Number )anot.getNewValue()); 48 } 49 50 public String toString() 51 { 52 return "NotificationStatisticsRecorder"; 53 } 54 } 55 | Popular Tags |