1 16 17 package org.mc4j.console.connection.proxy; 18 19 import org.mc4j.console.swing.SwingUtility; 20 import org.mc4j.console.util.ConnectionInfoAction; 21 22 import javax.management.MBeanServer ; 23 import javax.management.MBeanServerConnection ; 24 import java.lang.reflect.InvocationHandler ; 25 import java.lang.reflect.Method ; 26 import java.lang.reflect.Proxy ; 27 28 29 34 public class JMXRemotingMBeanServerProxy implements InvocationHandler { 35 36 private MBeanServerConnection remoteServer; 37 38 private static final Class [] INTERFACES = { MBeanServer .class }; 39 40 41 42 public JMXRemotingMBeanServerProxy(MBeanServerConnection remoteServer) { 43 this.remoteServer = remoteServer; 44 } 45 46 47 public Object invoke( 48 Object proxy, Method m, Object [] args) 49 throws Throwable { 50 51 SwingUtility.eventThreadAlert(); 52 53 55 Class serverClass = MBeanServerConnection .class; 57 Method method = serverClass.getMethod(m.getName(),m.getParameterTypes()); 58 59 return method.invoke(this.remoteServer, args); 62 } 63 64 public static MBeanServer buildServerProxy(Object server) { 65 66 Object proxy = 67 Proxy.newProxyInstance( 68 JMXRemotingMBeanServerProxy.class.getClassLoader(), 69 JMXRemotingMBeanServerProxy.INTERFACES, 70 new JMXRemotingMBeanServerProxy((MBeanServerConnection ) server)); 71 72 return (MBeanServer ) proxy; 73 } 74 } 75 | Popular Tags |