blob: e7fb8d3aa300c3d0323bcaac902cca39e9118225 (
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
35
36
37
38
39
|
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.persistence.rpc;
import com.yahoo.jrt.*;
import java.util.logging.Logger;
/**
* A handler that can be used to register RPC function calls,
* using Vespa JRT. To enable an RPC server, first call addMethod() any number of times,
* then start().
*/
public class RPCHandler {
private final static Logger log = Logger.getLogger(RPCHandler.class.getName());
private final int port;
private final Supervisor supervisor;
private Acceptor acceptor;
public RPCHandler(int port) {
supervisor = new Supervisor(new Transport());
this.port = port;
}
public void start() {
try {
acceptor = supervisor.listen(new Spec(port));
log.info("Listening for RPC requests on port " + port);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public void addMethod(Method method) {
supervisor.addMethod(method);
}
}
|