1 8 9 package mx4j.examples.remote.notification; 10 11 import javax.management.MBeanServerConnection ; 12 import javax.management.Notification ; 13 import javax.management.NotificationListener ; 14 import javax.management.ObjectName ; 15 import javax.management.loading.MLet ; 16 import javax.management.remote.JMXConnector ; 17 import javax.management.remote.JMXConnectorFactory ; 18 import javax.management.remote.JMXServiceURL ; 19 20 27 public class Client 28 { 29 public static void main(String [] args) throws Exception 30 { 31 JMXServiceURL url = new JMXServiceURL ("rmi", "localhost", 0, "/jndi/jmx"); 33 34 JMXConnector cntor = JMXConnectorFactory.connect(url, null); 36 37 MBeanServerConnection connection = cntor.getMBeanServerConnection(); 39 40 NotificationListener listener = new NotificationListener () 42 { 43 public void handleNotification(Notification notification, Object handback) 44 { 45 System.out.println(notification); 46 } 47 }; 48 49 ObjectName delegateName = ObjectName.getInstance("JMImplementation:type=MBeanServerDelegate"); 51 52 connection.addNotificationListener(delegateName, listener, null, null); 53 54 Thread.sleep(1000); 56 57 ObjectName name = ObjectName.getInstance("examples:mbean=mlet"); 60 connection.createMBean(MLet .class.getName(), name, null); 62 connection.unregisterMBean(name); 64 } 65 } 66 | Popular Tags |