1 7 package org.jboss.cache; 8 9 import org.jboss.remoting.transport.socket.SocketClientInvoker; 10 import org.jboss.remoting.InvokerLocator; 11 import org.jboss.remoting.InvocationRequest; 12 import org.jboss.remoting.invocation.NameBasedInvocation; 13 14 import javax.management.ObjectName ; 15 import java.io.Serializable ; 16 import java.lang.reflect.InvocationHandler ; 17 import java.lang.reflect.Method ; 18 19 26 public class TreeCacheProxy implements Serializable , InvocationHandler 27 { 28 static final long serialVersionUID = -4485997268761451933L; 29 30 String remoteURI=null; 31 SocketClientInvoker invoker; 32 ObjectName targetObject=null; 33 34 public TreeCacheProxy(String remoteURI, ObjectName targetObject) { 35 this.remoteURI=remoteURI; 36 this.targetObject=targetObject; 37 } 38 39 40 public Object invoke(Object proxy, Method method, Object [] args) throws Throwable { 41 InvokerLocator invokerLocator=new InvokerLocator(remoteURI); 42 if(invoker == null) { 43 invoker=new SocketClientInvoker(invokerLocator); 44 } 45 46 NameBasedInvocation arg; 48 arg=new NameBasedInvocation("invoke", 49 new Object []{targetObject, method.getName(), args, generateSignatureFromMethod(method)}, 50 new String []{ObjectName .class.getName(), String .class.getName(), 51 Object [].class.getName(), String [].class.getName()}); 52 InvocationRequest req=new InvocationRequest("bla", "JBossCache", arg, null, null, invokerLocator); 53 return invoker.invoke(req); 54 } 55 56 57 private String [] generateSignatureFromMethod(final Method method) { 58 Class [] parameterTypes=method.getParameterTypes(); 59 String [] signature=new String [parameterTypes.length]; 60 for(int i=0; i < parameterTypes.length; i++) { 61 Class parameterType=parameterTypes[i]; 62 signature[i]=parameterType.getName(); 63 } 64 return signature; 65 } 66 } 67 | Popular Tags |