annotate src/goodjava/rpc/Rpc.java @ 1450:28b1ddacfad3

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