blob: b2cb801eee36b4f29f441bc618a1d18366ebc23e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
// Copyright Vespa.ai. 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();
}
}
}
|