Mercurial Hosting > luan
annotate src/goodjava/rpc/Rpc.java @ 1435:3aae37efbf40
minor
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 06 Jan 2020 17:47:10 -0700 |
parents | 27efb1fcbcb5 |
children | 491b355acef7 |
rev | line source |
---|---|
1402
27efb1fcbcb5
move luan.lib to goodjava
Franklin Schmidt <fschmidt@gmail.com>
parents:
1118
diff
changeset
|
1 package goodjava.rpc; |
1118 | 2 |
3 import java.io.IOException; | |
4 | |
5 | |
6 // static utils | |
7 public class Rpc { | |
8 private Rpc() {} // never | |
9 | |
10 public static final RpcResult OK = new RpcResult(); | |
11 | |
12 public static final RpcCall CLOSE = new RpcCall("close"); | |
13 public static final RpcCall PING = new RpcCall("ping"); | |
14 public static final String ECHO = "echo"; | |
15 | |
16 public static final RpcException COMMAND_NOT_FOUND = new RpcException("command_not_found"); | |
17 | |
18 public static boolean handle(RpcServer server,RpcCall call) | |
19 throws IOException | |
20 { | |
21 if( CLOSE.cmd.equals(call.cmd) ) { | |
22 server.close(); | |
23 return true; | |
24 } | |
25 if( PING.cmd.equals(call.cmd) ) { | |
26 server.write(OK); | |
27 return true; | |
28 } | |
29 if( ECHO.equals(call.cmd) ) { | |
30 server.write(new RpcResult(call.args)); | |
31 return true; | |
32 } | |
33 return false; | |
34 } | |
35 | |
36 } |