Mercurial Hosting > luan
comparison src/goodjava/rpc/RpcServer.java @ 1402:27efb1fcbcb5
move luan.lib to goodjava
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 17 Sep 2019 01:35:01 -0400 |
parents | src/luan/lib/rpc/RpcServer.java@e8fc6712b468 |
children | aaac1d29edea |
comparison
equal
deleted
inserted
replaced
1401:ef1620aa99cb | 1402:27efb1fcbcb5 |
---|---|
1 package goodjava.rpc; | |
2 | |
3 import java.io.EOFException; | |
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) | |
12 throws RpcError | |
13 { | |
14 super(socket); | |
15 } | |
16 | |
17 public RpcCall read() | |
18 throws RpcError | |
19 { | |
20 try { | |
21 List list = readJson(); | |
22 String cmd = (String)list.remove(0); | |
23 Object[] args = list.toArray(); | |
24 return new RpcCall(inBinary,lenBinary,cmd,args); | |
25 } catch(RpcError e) { | |
26 if( !readSome && e.getCause() instanceof EOFException ) | |
27 return null; | |
28 throw e; | |
29 } | |
30 } | |
31 | |
32 public void write(RpcResult result) | |
33 throws RpcError | |
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) | |
44 throws RpcError | |
45 { | |
46 List list = new ArrayList(); | |
47 list.add(false); | |
48 list.add(ex.getMessage()); | |
49 for( Object val : ex.values ) { | |
50 list.add(val); | |
51 } | |
52 write(ex.in,ex.lenIn,list); | |
53 } | |
54 | |
55 } |