1
2
3
4 package org.sourceforge.jemm.comm.shared;
5
6 import java.lang.reflect.InvocationHandler;
7 import java.lang.reflect.Method;
8
9
10
11
12
13
14
15 public class RPCProxyHandler implements InvocationHandler {
16
17 final RPCHandler handler;
18
19
20 final Class<?> ifClass;
21
22
23
24
25
26
27 public RPCProxyHandler(RPCHandler handler, Class<?> ifClass) {
28 this.handler = handler;
29 this.ifClass = ifClass;
30 }
31
32 public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
33 if("public java.lang.String java.lang.Object.toString()".equals(method.toString()))
34 return "" + ifClass.getName() +":Proxy";
35
36 if(method.getReturnType() != void.class || method.getAnnotation(SynchronousCall.class) != null) {
37 RPCCallRespMessage resp = handler.makeSyncCall(ifClass,method.getName(),method.getParameterTypes(),args);
38 if(resp.isCallSuccess())
39 return resp.getReturnValue();
40 else
41 throw (Throwable) resp.getReturnValue();
42 } else {
43
44 handler.makeAsyncCall(ifClass,method.getName(),method.getParameterTypes(),args);
45 return null;
46 }
47 }
48 }