Skip to content

Commit aae1dac

Browse files
author
harry.ding
committed
bug
1 parent 9e9c1b6 commit aae1dac

File tree

3 files changed

+59
-47
lines changed

3 files changed

+59
-47
lines changed

androidipc/src/main/java/cn/ding/hu/androidipc/AndroidRpc.java

Lines changed: 58 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -54,61 +54,74 @@ public static void register(Class serviceInterface, Class serviceInterfaceImpl)
5454
public static Class getService(String serviceName) {
5555
return rpcMap.get(serviceName);
5656
}
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) {
9292

9393
try {
9494
Method[] methods = rpcService.getClass().getMethods();
9595
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);
99112
}
100113
}
101114
} catch (Exception e) {
102115
e.printStackTrace();
103116
}
104117
}
105118

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+
// }
113126
}
114127

androidipc/src/main/java/cn/ding/hu/androidipc/AndroidRpcActivty.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ public Messenger getmClientMessenger() {
4848
protected Object result;
4949

5050
private IRpcListener iRpcListener;
51-
private AndroidRpc.AndroidRpcInvocationHandler androidRpcInvocationHandler;
5251

5352
private HashMap<String, IRpcInvokeListener> rpcInvokeListenerHashMap = new HashMap<>();
5453

app/src/main/java/cn/ding/hu/androidipclib/IRpcServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ public class IRpcServiceImpl implements IRpcService {
1010
@Override
1111
public String getName() {
1212
Log.i("rpc","rpc call getName");
13-
return "dinghu-rpc";
13+
return "dinghu-rpc-lixi";
1414
}
1515
}

0 commit comments

Comments
 (0)