1 8 9 package mx4j.examples.tools.remote.hessian; 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 41 public class Client 42 { 43 public static void main(String [] args) throws Exception 44 { 45 JMXServiceURL address = new JMXServiceURL ("hessian", null, 8080, "/hessian"); 48 49 JMXConnector connector = JMXConnectorFactory.connect(address); 51 52 MBeanServerConnection connection = connector.getMBeanServerConnection(); 55 56 ObjectName delegateName = ObjectName.getInstance("JMImplementation:type=MBeanServerDelegate"); 58 Object proxy = MBeanServerInvocationHandler.newProxyInstance(connection, delegateName, MBeanServerDelegateMBean .class, true); 59 MBeanServerDelegateMBean delegate = (MBeanServerDelegateMBean )proxy; 60 61 System.out.println(delegate.getImplementationVendor() + " is cool !"); 62 63 connection.addNotificationListener(delegateName, new NotificationListener () 65 { 66 public void handleNotification(Notification notification, Object handback) 67 { 68 System.out.println("Got the following notification: " + notification); 69 } 70 }, null, null); 71 72 ObjectName timerName = ObjectName.getInstance("services:type=Timer"); 73 connection.createMBean(Timer .class.getName(), timerName, null); 74 75 connection.unregisterMBean(timerName); 77 78 Thread.sleep(1000); 80 81 connector.close(); 82 } 83 } 84 | Popular Tags |