CentOS 6.9 32位 Linux和Windows版的Eclipse 32位 Hadoop 2.4.1版本 JDK 7+
package cn.joker.hadoop.rpc; public interface LoginServiceInterface { public static final long versionID=1L; public String login(String username,String password); }
package cn.joker.hadoop.rpc; public class LoginServiceImpl implements LoginServiceInterface { @Override public String login(String username, String password) { // TODO Auto-generated method stub return username + " logged in successfully!"; } }
package cn.joker.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.Server; public class Starter { public static void main(String[] args) throws HadoopIllegalArgumentException, IOException { Builder builder = new RPC.Builder(new Configuration()); builder.setBindAddress("weekend110").setPort(10000).setProtocol(LoginServiceInterface.class).setInstance(new LoginServiceImpl()); Server server = builder.build(); server.start(); } }
package cn.joker.hadoop.rpc; public interface LoginServiceInterface { public static final long versionID=1L; public String login(String username,String password); }
package cn.joker.hadoop.rpc; import java.net.InetSocketAddress; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.ipc.RPC; public class LoginController { public static void main(String[] args) throws Exception { LoginServiceInterface proxy = RPC.getProxy(LoginServiceInterface.class, 1L, new InetSocketAddress("weekend110", 10000), new Configuration()); String result = proxy.login("kevintan", "abc1234"); System.out.println(result); } }