1 8 9 package mx4j.examples.tools.remote.soap; 10 11 import javax.management.MBeanServerConnection ; 12 import javax.management.MBeanServerDelegateMBean ; 13 import javax.management.MBeanServerInvocationHandler ; 14 import javax.management.Notification ; 15 import javax.management.NotificationListener ; 16 import javax.management.ObjectName ; 17 import javax.management.remote.JMXConnector ; 18 import javax.management.remote.JMXConnectorFactory ; 19 import javax.management.remote.JMXServiceURL ; 20 import javax.management.timer.Timer ; 21 22 48 public class Client 49 { 50 public static void main(String [] args) throws Exception 51 { 52 JMXServiceURL address = new JMXServiceURL ("soap", null, 8080, "/jmxconnector"); 55 56 JMXConnector connector = JMXConnectorFactory.connect(address); 58 59 MBeanServerConnection connection = connector.getMBeanServerConnection(); 62 63 ObjectName delegateName = ObjectName.getInstance("JMImplementation:type=MBeanServerDelegate"); 65 Object proxy = MBeanServerInvocationHandler.newProxyInstance(connection, delegateName, MBeanServerDelegateMBean .class, true); 66 MBeanServerDelegateMBean delegate = (MBeanServerDelegateMBean )proxy; 67 68 System.out.println(delegate.getImplementationVendor() + " is cool !"); 69 70 connection.addNotificationListener(delegateName, new NotificationListener () 72 { 73 public void handleNotification(Notification notification, Object handback) 74 { 75 System.out.println("Got the following notification: " + notification); 76 } 77 }, null, null); 78 79 ObjectName timerName = ObjectName.getInstance("services:type=Timer"); 80 connection.createMBean(Timer .class.getName(), timerName, null); 81 82 connection.unregisterMBean(timerName); 84 85 Thread.sleep(1000); 87 88 connector.close(); 89 } 90 } 91 | Popular Tags |