服务
public interface MyBiz extends VersionedProtocol {
long PROTOCOL_VERSION = 12321443L;
String hello(String name);
}
public class MyBizImpl implements MyBiz {
@Override
public long getProtocolVersion(String arg0, long arg1) throws IOException {
return PROTOCOL_VERSION;
}
@Override
public String hello(String name) {
System. out.println( "invoked");
return "hello " + name;
}
}
服务器
public class MyServer {
public static final String SERVER_ADDRESS = "localhost";
public static final int SERVER_PORT = 12345;
public static void main(String[] args) throws IOException {
Server server = RPC. getServer(new MyBizImpl(), SERVER_ADDRESS, SERVER_PORT , new Configuration());
server.start();
}
}
客户端
public class MyClient {
public static void main(String[] args) throws IOException {
MyBiz proxy = (MyBiz) RPC. getProxy(MyBiz.class, MyBiz.PROTOCOL_VERSION,
new InetSocketAddress(MyServer. SERVER_ADDRESS,MyServer.SERVER_PORT),
new Configuration());
String result = proxy.hello( "5");
System. out.println(result);
RPC.stopProxy(proxy);
}
}
HADOOP_PRC
最新推荐文章于 2023-05-04 09:16:19 发布