annotate src/goodjava/rpc/RpcClient.java @ 1767:9157e0d5936e

minor fix
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 06 Jun 2023 20:31:19 -0600
parents 27efb1fcbcb5
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: 1119
diff changeset
1 package goodjava.rpc;
1118
e4710ddfd287 start luan/lib/rpc
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2
e4710ddfd287 start luan/lib/rpc
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3 import java.net.Socket;
e4710ddfd287 start luan/lib/rpc
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 import java.util.List;
e4710ddfd287 start luan/lib/rpc
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5 import java.util.ArrayList;
e4710ddfd287 start luan/lib/rpc
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6
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 public class RpcClient extends RpcCon {
e4710ddfd287 start luan/lib/rpc
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9
1119
87c674f3f6b7 add RpcError
Franklin Schmidt <fschmidt@gmail.com>
parents: 1118
diff changeset
10 public RpcClient(Socket socket)
87c674f3f6b7 add RpcError
Franklin Schmidt <fschmidt@gmail.com>
parents: 1118
diff changeset
11 throws RpcError
87c674f3f6b7 add RpcError
Franklin Schmidt <fschmidt@gmail.com>
parents: 1118
diff changeset
12 {
1118
e4710ddfd287 start luan/lib/rpc
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13 super(socket);
e4710ddfd287 start luan/lib/rpc
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14 }
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 public void write(RpcCall call)
1119
87c674f3f6b7 add RpcError
Franklin Schmidt <fschmidt@gmail.com>
parents: 1118
diff changeset
17 throws RpcError
1118
e4710ddfd287 start luan/lib/rpc
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
18 {
e4710ddfd287 start luan/lib/rpc
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19 List list = new ArrayList();
e4710ddfd287 start luan/lib/rpc
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20 list.add(call.cmd);
e4710ddfd287 start luan/lib/rpc
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21 for( Object arg : call.args ) {
e4710ddfd287 start luan/lib/rpc
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
22 list.add(arg);
e4710ddfd287 start luan/lib/rpc
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23 }
e4710ddfd287 start luan/lib/rpc
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24 write(call.in,call.lenIn,list);
e4710ddfd287 start luan/lib/rpc
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25 }
e4710ddfd287 start luan/lib/rpc
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26
e4710ddfd287 start luan/lib/rpc
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27 public RpcResult read()
1119
87c674f3f6b7 add RpcError
Franklin Schmidt <fschmidt@gmail.com>
parents: 1118
diff changeset
28 throws RpcError, RpcException
1118
e4710ddfd287 start luan/lib/rpc
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
29 {
e4710ddfd287 start luan/lib/rpc
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30 List list = readJson();
e4710ddfd287 start luan/lib/rpc
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
31 boolean ok = (Boolean)list.remove(0);
e4710ddfd287 start luan/lib/rpc
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
32 if( !ok ) {
e4710ddfd287 start luan/lib/rpc
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
33 String errorId = (String)list.remove(0);
e4710ddfd287 start luan/lib/rpc
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
34 Object[] args = list.toArray();
e4710ddfd287 start luan/lib/rpc
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
35 throw new RpcException(inBinary,lenBinary,errorId,args);
e4710ddfd287 start luan/lib/rpc
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
36 }
e4710ddfd287 start luan/lib/rpc
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
37 Object[] args = list.toArray();
e4710ddfd287 start luan/lib/rpc
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
38 return new RpcResult(inBinary,lenBinary,args);
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
e4710ddfd287 start luan/lib/rpc
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
41 }