【填坑之旅-hadoop-04】hadoop2.10.1 RPC框架 远程过程调用 ClientProtocal 接口协议 底层机制 ipc.RPC/Builder/Server/getProxy

RPC框架 远程过程调用

1.服务端启动服务,
2.客户端获取服务端接口协议的代理对象
3.客户端通过代理对象的接口协议,调用服务端提供的功能(直接通过socket协议通信)

hdfs接口协议对象是 org.apache.hadoop.hdfs.protocol.ClientProtocol;

【填坑之旅-hadoop-04】hadoop2.10.1 RPC框架 远程过程调用 ClientProtocal 接口协议 底层机制 ipc.RPC/Builder/Server/getProxy
【填坑之旅-hadoop-04】hadoop2.10.1 RPC框架 远程过程调用 ClientProtocal 接口协议 底层机制 ipc.RPC/Builder/Server/getProxy

【填坑之旅-hadoop-04】hadoop2.10.1 RPC框架 远程过程调用 ClientProtocal 接口协议 底层机制 ipc.RPC/Builder/Server/getProxy
【填坑之旅-hadoop-04】hadoop2.10.1 RPC框架 远程过程调用 ClientProtocal 接口协议 底层机制 ipc.RPC/Builder/Server/getProxy
rpc hadoop 动态代理 proxy socket

【填坑之旅-hadoop-04】hadoop2.10.1 RPC框架 远程过程调用 ClientProtocal 接口协议 底层机制 ipc.RPC/Builder/Server/getProxy

LoginServiceInterface 接口协议

package cn.itcast.hadoop.rpc;

public interface LoginServiceInterface {
	
	public static final long versionID=1L;
	public String login(String username,String password);

}


LoginServiceImpl 接口实现

package cn.itcast.hadoop.rpc;

public class LoginServiceImpl implements LoginServiceInterface {

	@Override
	public String login(String username, String password) {
		
		return username + " logged in successfully!";
	}

}

Starter 服务端启动 RPC.Builder server.start();

package cn.itcast.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 Starter {

	public static void main(String[] args) throws HadoopIllegalArgumentException, IOException {
		Builder builder = new RPC.Builder(new Configuration());
		
		builder.setBindAddress("cch")
			.setPort(10096)
			.setProtocol(LoginServiceInterface.class)
			.setInstance(new LoginServiceImpl());
		
		//builder.setSecretManager(new TokenIdentifier)
		
		Server server = builder.build();
		
		server.start();
	
	}

}

LoginController 通过proxy代理对象,调用server

package cn.itcast.hadoop.rpc;

import java.net.InetSocketAddress;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hdfs.DFSClient;
import org.apache.hadoop.hdfs.protocol.ClientProtocol;
import org.apache.hadoop.ipc.RPC;

public class LoginController {

	public static void main(String[] args) throws Exception {
		
		//ClientProtocol
		
		//DFSClient
		
		LoginServiceInterface proxy = RPC.getProxy(LoginServiceInterface.class, 
													1L, 
													new InetSocketAddress("cch", 10096), 
													new Configuration());
		
		String result = proxy.login("mijie", "123456");
		
		System.out.println(result);
		
		RPC.stopProxy(proxy);
	}

}

上一篇:❤️Android Binder原理图解❤️


下一篇:IPC$远程植入木马