Mercurial Hosting > luan
annotate src/goodjava/rpc/RpcServer.java @ 1823:36dfc31fd607 default tip
install fix
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Wed, 07 Aug 2024 18:29:58 -0600 |
parents | aaac1d29edea |
children |
rev | line source |
---|---|
1402
27efb1fcbcb5
move luan.lib to goodjava
Franklin Schmidt <fschmidt@gmail.com>
parents:
1120
diff
changeset
|
1 package goodjava.rpc; |
1118 | 2 |
1120
e8fc6712b468
luan Rpc uses luan.lib.rpc
Franklin Schmidt <fschmidt@gmail.com>
parents:
1119
diff
changeset
|
3 import java.io.EOFException; |
1118 | 4 import java.net.Socket; |
5 import java.util.List; | |
6 import java.util.ArrayList; | |
7 | |
8 | |
9 public class RpcServer extends RpcCon { | |
10 | |
1119 | 11 public RpcServer(Socket socket) |
12 throws RpcError | |
13 { | |
1118 | 14 super(socket); |
15 } | |
16 | |
17 public RpcCall read() | |
1119 | 18 throws RpcError |
1118 | 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 | 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 | 30 } |
31 | |
32 public void write(RpcResult result) | |
1119 | 33 throws RpcError |
1118 | 34 { |
35 List list = new ArrayList(); | |
36 list.add(true); | |
37 for( Object val : result.returnValues ) { | |
38 list.add(val); | |
39 } | |
40 write(result.in,result.lenIn,list); | |
41 } | |
42 | |
43 public void write(RpcException ex) | |
1119 | 44 throws RpcError |
1118 | 45 { |
46 List list = new ArrayList(); | |
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 | 49 for( Object val : ex.values ) { |
50 list.add(val); | |
51 } | |
52 write(ex.in,ex.lenIn,list); | |
53 } | |
54 | |
55 } |