annotate src/goodjava/rpc/RpcServer.java @ 1752:b4fa42c1e999

minor
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 25 Jan 2023 12:22:09 -0700
parents aaac1d29edea
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1402
27efb1fcbcb5 move luan.lib to goodjava
Franklin Schmidt <fschmidt@gmail.com>
parents: 1120
diff changeset
1 package goodjava.rpc;
1118
e4710ddfd287 start luan/lib/rpc
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2
1120
e8fc6712b468 luan Rpc uses luan.lib.rpc
Franklin Schmidt <fschmidt@gmail.com>
parents: 1119
diff changeset
3 import java.io.EOFException;
1118
e4710ddfd287 start luan/lib/rpc
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 import java.net.Socket;
e4710ddfd287 start luan/lib/rpc
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5 import java.util.List;
e4710ddfd287 start luan/lib/rpc
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 import java.util.ArrayList;
e4710ddfd287 start luan/lib/rpc
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7
e4710ddfd287 start luan/lib/rpc
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8
e4710ddfd287 start luan/lib/rpc
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9 public class RpcServer extends RpcCon {
e4710ddfd287 start luan/lib/rpc
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10
1119
87c674f3f6b7 add RpcError
Franklin Schmidt <fschmidt@gmail.com>
parents: 1118
diff changeset
11 public RpcServer(Socket socket)
87c674f3f6b7 add RpcError
Franklin Schmidt <fschmidt@gmail.com>
parents: 1118
diff changeset
12 throws RpcError
87c674f3f6b7 add RpcError
Franklin Schmidt <fschmidt@gmail.com>
parents: 1118
diff changeset
13 {
1118
e4710ddfd287 start luan/lib/rpc
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14 super(socket);
e4710ddfd287 start luan/lib/rpc
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
15 }
e4710ddfd287 start luan/lib/rpc
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16
e4710ddfd287 start luan/lib/rpc
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17 public RpcCall read()
1119
87c674f3f6b7 add RpcError
Franklin Schmidt <fschmidt@gmail.com>
parents: 1118
diff changeset
18 throws RpcError
1118
e4710ddfd287 start luan/lib/rpc
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19 {
1120
e8fc6712b468 luan Rpc uses luan.lib.rpc
Franklin Schmidt <fschmidt@gmail.com>
parents: 1119
diff changeset
20 try {
e8fc6712b468 luan Rpc uses luan.lib.rpc
Franklin Schmidt <fschmidt@gmail.com>
parents: 1119
diff changeset
21 List list = readJson();
e8fc6712b468 luan Rpc uses luan.lib.rpc
Franklin Schmidt <fschmidt@gmail.com>
parents: 1119
diff changeset
22 String cmd = (String)list.remove(0);
e8fc6712b468 luan Rpc uses luan.lib.rpc
Franklin Schmidt <fschmidt@gmail.com>
parents: 1119
diff changeset
23 Object[] args = list.toArray();
e8fc6712b468 luan Rpc uses luan.lib.rpc
Franklin Schmidt <fschmidt@gmail.com>
parents: 1119
diff changeset
24 return new RpcCall(inBinary,lenBinary,cmd,args);
e8fc6712b468 luan Rpc uses luan.lib.rpc
Franklin Schmidt <fschmidt@gmail.com>
parents: 1119
diff changeset
25 } catch(RpcError e) {
1492
aaac1d29edea better io
Franklin Schmidt <fschmidt@gmail.com>
parents: 1402
diff changeset
26 if( e.getCause() instanceof EOFException )
1120
e8fc6712b468 luan Rpc uses luan.lib.rpc
Franklin Schmidt <fschmidt@gmail.com>
parents: 1119
diff changeset
27 return null;
e8fc6712b468 luan Rpc uses luan.lib.rpc
Franklin Schmidt <fschmidt@gmail.com>
parents: 1119
diff changeset
28 throw e;
e8fc6712b468 luan Rpc uses luan.lib.rpc
Franklin Schmidt <fschmidt@gmail.com>
parents: 1119
diff changeset
29 }
1118
e4710ddfd287 start luan/lib/rpc
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30 }
e4710ddfd287 start luan/lib/rpc
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
31
e4710ddfd287 start luan/lib/rpc
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
32 public void write(RpcResult result)
1119
87c674f3f6b7 add RpcError
Franklin Schmidt <fschmidt@gmail.com>
parents: 1118
diff changeset
33 throws RpcError
1118
e4710ddfd287 start luan/lib/rpc
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
34 {
e4710ddfd287 start luan/lib/rpc
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
35 List list = new ArrayList();
e4710ddfd287 start luan/lib/rpc
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
36 list.add(true);
e4710ddfd287 start luan/lib/rpc
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
37 for( Object val : result.returnValues ) {
e4710ddfd287 start luan/lib/rpc
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
38 list.add(val);
e4710ddfd287 start luan/lib/rpc
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
39 }
e4710ddfd287 start luan/lib/rpc
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
40 write(result.in,result.lenIn,list);
e4710ddfd287 start luan/lib/rpc
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
41 }
e4710ddfd287 start luan/lib/rpc
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
42
e4710ddfd287 start luan/lib/rpc
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
43 public void write(RpcException ex)
1119
87c674f3f6b7 add RpcError
Franklin Schmidt <fschmidt@gmail.com>
parents: 1118
diff changeset
44 throws RpcError
1118
e4710ddfd287 start luan/lib/rpc
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
45 {
e4710ddfd287 start luan/lib/rpc
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
46 List list = new ArrayList();
e4710ddfd287 start luan/lib/rpc
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
47 list.add(false);
1120
e8fc6712b468 luan Rpc uses luan.lib.rpc
Franklin Schmidt <fschmidt@gmail.com>
parents: 1119
diff changeset
48 list.add(ex.getMessage());
1118
e4710ddfd287 start luan/lib/rpc
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
49 for( Object val : ex.values ) {
e4710ddfd287 start luan/lib/rpc
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
50 list.add(val);
e4710ddfd287 start luan/lib/rpc
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
51 }
e4710ddfd287 start luan/lib/rpc
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
52 write(ex.in,ex.lenIn,list);
e4710ddfd287 start luan/lib/rpc
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
53 }
e4710ddfd287 start luan/lib/rpc
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
54
e4710ddfd287 start luan/lib/rpc
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
55 }