1118
|
1 package luan.lib.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 }
|