Mercurial Hosting > luan
diff src/luan/lib/rpc/Rpc.java @ 1118:e4710ddfd287
start luan/lib/rpc
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 06 Aug 2017 20:11:11 -0600 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/luan/lib/rpc/Rpc.java Sun Aug 06 20:11:11 2017 -0600 @@ -0,0 +1,36 @@ +package luan.lib.rpc; + +import java.io.IOException; + + +// static utils +public class Rpc { + private Rpc() {} // never + + public static final RpcResult OK = new RpcResult(); + + public static final RpcCall CLOSE = new RpcCall("close"); + public static final RpcCall PING = new RpcCall("ping"); + public static final String ECHO = "echo"; + + public static final RpcException COMMAND_NOT_FOUND = new RpcException("command_not_found"); + + public static boolean handle(RpcServer server,RpcCall call) + throws IOException + { + if( CLOSE.cmd.equals(call.cmd) ) { + server.close(); + return true; + } + if( PING.cmd.equals(call.cmd) ) { + server.write(OK); + return true; + } + if( ECHO.equals(call.cmd) ) { + server.write(new RpcResult(call.args)); + return true; + } + return false; + } + +}