hadoop中rpc的示例分析
这篇文章主要介绍hadoop中rpc的示例分析,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
[root@localhost hadoop-2.4.1]# service network restart启动网卡
windos 端的UserLoginController
package cn.itcast.bigdata.hadoop.rpc;
import java.io.IOException;
import java.net.InetSocketAddress;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.ipc.RPC;
public class UserLoginController {
public static void main(String[] args) throws Exception {//先启动服务器端
Configuration conf = new Configuration();
LoginServiceInterface loginServiceImpl = RPC.getProxy(LoginServiceInterface.class, 1L, new InetSocketAddress("192.168.88.155", 10000), conf);
String res = loginServiceImpl.login("angelababy", "123");
System.out.println(res);
}
}
package cn.itcast.bigdata.hadoop.rpc;
public interface LoginServiceInterface {
public static final long versionID = 1L;
public String login(String username,String password);
}
linux端的
package cn.itcast.bigdata.hadoop.rpc;
public class LoginServiceImpl implements LoginServiceInterface{
@Override
public String login(String username, String password) {
return username + "logged in successfully!";
}
}
package cn.itcast.bigdata.hadoop.rpc;
public interface LoginServiceInterface {
public static final long versionID = 1L;
public String login(String username,String password);
}
package cn.itcast.bigdata.hadoop.rpc;
import java.io.IOException;
import org.apache.hadoop.HadoopIllegalArgumentException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.ipc.RPC;
import org.apache.hadoop.ipc.RPC.Builder;
import org.apache.hadoop.ipc.RPC.Server;
public class ServerStarter {
public static void main(String[] args) throws HadoopIllegalArgumentException, IOException {//先启动服务器端的
Configuration conf = new Configuration();
Builder builder = new RPC.Builder(conf);
builder.setInstance(new LoginServiceImpl()).setBindAddress("192.168.88.155").setPort(10000).setProtocol(LoginServiceInterface.class);
Server server = builder.build();
server.start();
}
}
以上是“hadoop中rpc的示例分析”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注行业资讯频道!