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