1118
|
1 package luan.lib.rpc;
|
|
2
|
|
3 import java.io.IOException;
|
|
4 import java.net.Socket;
|
|
5 import java.util.List;
|
|
6 import java.util.ArrayList;
|
|
7
|
|
8
|
|
9 public class RpcServer extends RpcCon {
|
|
10
|
|
11 public RpcServer(Socket socket) throws IOException {
|
|
12 super(socket);
|
|
13 }
|
|
14
|
|
15 public RpcCall read()
|
|
16 throws IOException
|
|
17 {
|
|
18 List list = readJson();
|
|
19 String cmd = (String)list.remove(0);
|
|
20 Object[] args = list.toArray();
|
|
21 return new RpcCall(inBinary,lenBinary,cmd,args);
|
|
22 }
|
|
23
|
|
24 public void write(RpcResult result)
|
|
25 throws IOException
|
|
26 {
|
|
27 List list = new ArrayList();
|
|
28 list.add(true);
|
|
29 for( Object val : result.returnValues ) {
|
|
30 list.add(val);
|
|
31 }
|
|
32 write(result.in,result.lenIn,list);
|
|
33 }
|
|
34
|
|
35 public void write(RpcException ex)
|
|
36 throws IOException
|
|
37 {
|
|
38 List list = new ArrayList();
|
|
39 list.add(false);
|
|
40 for( Object val : ex.values ) {
|
|
41 list.add(val);
|
|
42 }
|
|
43 write(ex.in,ex.lenIn,list);
|
|
44 }
|
|
45
|
|
46 }
|