基于Netty HTTP协议实现的轻量级RPC框架
allprojects {
repositories {
maven {
url uri('https://raw.githubusercontent.com/kyle-android/Netty-RPC/master/repo')
}
}
}
implementation 'cn.kyle.support:rpc-core:1.0.0'
annotationProcessor 'cn.kyle.support:rpc-compiler:1.0.2'
@RpcService(ip = "127.0.0.1", port = 8094)
public interface UiAutomator {
@RpcMethod
boolean uiKeyClick(@RpcParam int x, @RpcParam int y) throws RemoteException;
@RpcMethod
@RpcReturnType(type = String.class)
String getUserPhone(@RpcParam(type = String.class) String userId) throws RemoteException;
@RpcMethod
@RpcReturnType(type = List.class, generic = String.class)
List<String> getUserPhoneList(@RpcParam(type = List.class, generic = String.class) List<String> userIds) throws RemoteException;
}
public class UiAutomatorImpl extends UiAutomatorRpc.Stub {
@Override
public boolean uiKeyClick(int x, int y) throws RemoteException {
System.out.println("UiAutomatorImpl execute uiKeyClick");
return true;
}
@Override
public String getUserPhone(String userId) throws RemoteException {
System.out.println("UiAutomatorImpl execute getUserPhone");
return "Kyle";
}
@Override
public List<String> getUserPhoneList(List<String> userIds) throws RemoteException {
System.out.println("UiAutomatorImpl execute getUserPhoneList");
return Arrays.asList("Kyle");
}
}
NettyService.getDefault().addService(new UiAutomatorImpl()).start(8094);
UiAutomator uiAutomator = NettyRpc.create(UiAutomator.class);
try {
boolean result = uiAutomator.uiKeyClick(2, 3);
} catch (RemoteException e) {
e.printStackTrace();
}