@@ -54,61 +54,74 @@ public static void register(Class serviceInterface, Class serviceInterfaceImpl)
54
54
public static Class getService (String serviceName ) {
55
55
return rpcMap .get (serviceName );
56
56
}
57
-
58
- public static class AndroidRpcInvocationHandler implements InvocationHandler {
59
- private AndroidRpcActivty androidRpcActivty ;
60
- private Class <?> cls ;
61
-
62
- public AndroidRpcInvocationHandler (Class <?> cls , AndroidRpcActivty androidRpcActivty ) {
63
- this .androidRpcActivty = androidRpcActivty ;
64
- this .cls = cls ;
65
- }
66
-
67
- @ Override
68
- public Object invoke (Object proxy , Method method , Object [] args ) throws Throwable {
69
- System .out .println ("开始事务111" );
70
-
71
- Messenger messenger = androidRpcActivty .getmServerMessenger ();
72
- Message message = Message .obtain ();
73
- message .what = MSG_INVOKE_MSG ;
74
- message .replyTo = androidRpcActivty .getmClientMessenger ();
75
- Bundle bundle = new Bundle ();
76
- bundle .putString ("serviceName" , cls .getName ());
77
- bundle .putString ("methodName" , method .getName ());
78
- bundle .putSerializable ("parameterTypes" , method .getParameterTypes ());
79
- bundle .putSerializable ("arguments" , args );
80
- message .setData (bundle );
81
- messenger .send (message );
82
- //阻塞线程等待返回
83
-
84
- //发送消息
85
- System .out .println ("提交事务111" );
86
- return null ;
87
- }
88
- }
89
-
90
-
91
- public static <T > void invoke (final AndroidRpcActivty activity ,Object rpcService , String method , IRpcInvokeListener <T > invokeListener , Object ... args ) {
57
+ //
58
+ // public static class AndroidRpcInvocationHandler implements InvocationHandler {
59
+ // private AndroidRpcActivty androidRpcActivty;
60
+ // private Class<?> cls;
61
+ //
62
+ // public AndroidRpcInvocationHandler(Class<?> cls, AndroidRpcActivty androidRpcActivty) {
63
+ // this.androidRpcActivty = androidRpcActivty;
64
+ // this.cls = cls;
65
+ // }
66
+ //
67
+ // @Override
68
+ // public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
69
+ // System.out.println("开始事务111");
70
+ //
71
+ // Messenger messenger = androidRpcActivty.getmServerMessenger();
72
+ // Message message = Message.obtain();
73
+ // message.what = MSG_INVOKE_MSG;
74
+ // message.replyTo = androidRpcActivty.getmClientMessenger();
75
+ // Bundle bundle = new Bundle();
76
+ // bundle.putString("serviceName", cls.getName());
77
+ // bundle.putString("methodName", method.getName());
78
+ // bundle.putSerializable("parameterTypes", method.getParameterTypes());
79
+ // bundle.putSerializable("arguments", args);
80
+ // message.setData(bundle);
81
+ // messenger.send(message);
82
+ // //阻塞线程等待返回
83
+ //
84
+ // //发送消息
85
+ // System.out.println("提交事务111");
86
+ // return null;
87
+ // }
88
+ // }
89
+
90
+
91
+ public static <T > void invoke (final AndroidRpcActivty activity ,Object rpcService , String methodName , IRpcInvokeListener <T > invokeListener , Object ... args ) {
92
92
93
93
try {
94
94
Method [] methods = rpcService .getClass ().getMethods ();
95
95
for (int i = 0 ; i < methods .length ; i ++) {
96
- if (methods [i ].getName ().equals (method )) {
97
- activity .addRpcInvokeListener (methods [i ].getName (),invokeListener );
98
- methods [i ].invoke (rpcService , args );
96
+ if (methods [i ].getName ().equals (methodName )) {
97
+ Method method = methods [i ];
98
+ activity .addRpcInvokeListener (method .getName (),invokeListener );
99
+ // methods[i].invoke(rpcService, args);
100
+
101
+ Messenger messenger = activity .getmServerMessenger ();
102
+ Message message = Message .obtain ();
103
+ message .what = MSG_INVOKE_MSG ;
104
+ message .replyTo = activity .getmClientMessenger ();
105
+ Bundle bundle = new Bundle ();
106
+ bundle .putString ("serviceName" , rpcService .getClass ().getName ());
107
+ bundle .putString ("methodName" , method .getName ());
108
+ bundle .putSerializable ("parameterTypes" , method .getParameterTypes ());
109
+ bundle .putSerializable ("arguments" , args );
110
+ message .setData (bundle );
111
+ messenger .send (message );
99
112
}
100
113
}
101
114
} catch (Exception e ) {
102
115
e .printStackTrace ();
103
116
}
104
117
}
105
118
106
- public static Object getRpcService (final Class <?> cls , final AndroidRpcActivty activity ) {
107
- return Proxy .newProxyInstance (
108
- cls .getClassLoader (),
109
- new Class []{cls },
110
- new AndroidRpcInvocationHandler (cls , activity )
111
- );
112
- }
119
+ // public static Object getRpcService(final Class<?> cls, final AndroidRpcActivty activity) {
120
+ // return Proxy.newProxyInstance(
121
+ // cls.getClassLoader(),
122
+ // new Class[]{cls},
123
+ // new AndroidRpcInvocationHandler(cls, activity)
124
+ // );
125
+ // }
113
126
}
114
127
0 commit comments