-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHelloService.java
More file actions
74 lines (58 loc) · 1.73 KB
/
Copy pathHelloService.java
File metadata and controls
74 lines (58 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package server.json;
import org.json.JSONObject;
import rpc.exception.RpcException;
import rpc.framework.server.RpcServiceInterface;
import rpc.json.message.RpcRequest;
import rpc.json.message.RpcResponse;
import rpc.util.RpcLog;
public class HelloService implements RpcServiceInterface {
private static final String TAG = "HelloService";
String mName = "no one";
public HelloService() {
}
@Override
public String[] list() {
return new String[] {
"HelloService.add",
"HelloService.sayName",
"HelloService.giveName"
};
}
@Override
public RpcResponse execute(RpcRequest request) throws RpcException {
String method = request.getMethod();
if ("HelloService.add".equals(method)) {
return add(request);
} else if ("HelloService.sayName".equals(method)) {
return sayName(request);
} else if ("HelloService.giveName".equals(method)) {
return giveName(request);
} else {
RpcLog.e(TAG, "unsupport method: " + method);
return null;
}
}
public String sayName() {
return mName;
}
public int add(int a, int b) {
return a +b;
}
public void giveName(String name) {
mName = name;
}
private RpcResponse sayName(RpcRequest request) {
return new RpcResponse(request.getId(), sayName(), true);
}
private RpcResponse add(RpcRequest request) {
JSONObject args = (JSONObject)request.getParams();
int a = args.getInt("a");
int b = args.getInt("b");
return new RpcResponse(request.getId(), add(a,b), true);
}
private RpcResponse giveName(RpcRequest request) {
JSONObject args = (JSONObject)request.getParams();
giveName(args.getString("name"));
return new RpcResponse(request.getId(), null, true);
}
}