1 16 package org.jmanage.testapp.jsr160; 17 18 import javax.management.NotificationListener ; 19 import javax.management.Notification ; 20 import javax.management.MBeanServerConnection ; 21 import javax.management.ObjectName ; 22 import javax.management.remote.JMXConnectorFactory ; 23 import javax.management.remote.JMXConnector ; 24 import javax.management.remote.JMXServiceURL ; 25 26 31 public class NotificationListenerTest { 32 33 public static void main(String [] args) 34 throws Exception { 35 36 JMXServiceURL url = new JMXServiceURL ("service:jmx:rmi:///jndi/rmi://localhost:9999/testApp"); 37 JMXConnector jmxc = JMXConnectorFactory.connect(url, null); 38 MBeanServerConnection mbsc = jmxc.getMBeanServerConnection(); 39 mbsc.addNotificationListener( 40 new ObjectName ("jmanage:name=TimeNotificationBroadcaster"), 41 new MyNotificationListener(), null, null); 42 43 while(true){ 44 try { 45 Thread.sleep(100000); 46 } catch (InterruptedException e) { 47 } 48 } 49 } 50 51 public static class MyNotificationListener implements NotificationListener { 52 53 public void handleNotification(Notification notification, 54 Object bindVariables) { 55 System.out.println("Notification: type=" + notification.getType() 56 + ", seq# " + notification.getSequenceNumber()); 57 } 58 } 59 } 60 | Popular Tags |