1 8 9 package mx4j.examples.mbeans.dynamic; 10 11 import javax.management.MBeanServer ; 12 import javax.management.MBeanServerFactory ; 13 import javax.management.Notification ; 14 import javax.management.NotificationListener ; 15 import javax.management.ObjectName ; 16 import javax.management.monitor.GaugeMonitor ; 17 18 26 public class DynamicMBeanExample 27 { 28 public static void main(String [] args) throws Exception 29 { 30 MBeanServer server = MBeanServerFactory.newMBeanServer(); 32 33 DynamicService serviceMBean = new DynamicService(); 35 ObjectName serviceName = new ObjectName ("examples", "mbean", "dynamic"); 36 server.registerMBean(serviceMBean, serviceName); 37 38 GaugeMonitor monitorMBean = new GaugeMonitor (); 42 ObjectName monitorName = new ObjectName ("examples", "monitor", "gauge"); 43 server.registerMBean(monitorMBean, monitorName); 44 45 monitorMBean.setThresholds(new Integer (8), new Integer (4)); 47 monitorMBean.setNotifyHigh(true); 49 monitorMBean.setNotifyLow(true); 50 monitorMBean.setDifferenceMode(false); 52 monitorMBean.addObservedObject(serviceName); 54 monitorMBean.setObservedAttribute("ConcurrentClients"); 55 monitorMBean.setGranularityPeriod(50L); 57 monitorMBean.addNotificationListener(new NotificationListener () 59 { 60 public void handleNotification(Notification notification, Object handback) 61 { 62 System.out.println(notification); 63 } 64 }, null, null); 65 monitorMBean.start(); 67 68 serviceMBean.start(); 70 } 71 } 72 | Popular Tags |