diff options
author | Jon Bratseth <bratseth@yahoo-inc.com> | 2016-06-15 23:09:44 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@yahoo-inc.com> | 2016-06-15 23:09:44 +0200 |
commit | 72231250ed81e10d66bfe70701e64fa5fe50f712 (patch) | |
tree | 2728bba1131a6f6e5bdf95afec7d7ff9358dac50 /jrt/examples/SimpleServer.java |
Publish
Diffstat (limited to 'jrt/examples/SimpleServer.java')
-rw-r--r-- | jrt/examples/SimpleServer.java | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/jrt/examples/SimpleServer.java b/jrt/examples/SimpleServer.java new file mode 100644 index 00000000000..f387e2916c1 --- /dev/null +++ b/jrt/examples/SimpleServer.java @@ -0,0 +1,34 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +import com.yahoo.jrt.*; + +public class SimpleServer { + + public void rpc_add(Request req) { + int n1 = req.parameters().get(0).asInt32(); + int n2 = req.parameters().get(1).asInt32(); + req.returnValues().add(new Int32Value(n1 + n2)); + } + + public static void main(String args[]) { + if (args.length != 1) { + System.err.println("usage: SimpleServer spec"); + System.exit(1); + } + Supervisor supervisor = new Supervisor(new Transport()); + supervisor.addMethod(new Method("add", "ii", "i", + new SimpleServer(), "rpc_add") + .methodDesc("calculate the sum of 2 integers") + .paramDesc(0, "n1", "an integer") + .paramDesc(1, "n2", "another integer") + .returnDesc(0, "ret", "n1 + n2")); + try { + Acceptor acceptor = supervisor.listen(new Spec(args[0])); + System.out.println("Listening at " + args[0]); + supervisor.transport().join(); + acceptor.shutdown().join(); + } catch (ListenFailedException e) { + System.err.println("Could not listen at " + args[0]); + supervisor.transport().shutdown().join(); + } + } +} |