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