comparison src/goodjava/rpc/Rpc.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/Rpc.java@e4710ddfd287
children 491b355acef7
comparison
equal deleted inserted replaced
1401:ef1620aa99cb 1402:27efb1fcbcb5
1 package goodjava.rpc;
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 }