2021SC@SDUSC
Hadoop RPC
实现ClientProtocol类,该类定义了接口协议,在该接口中定义了两个方法:echo和add。而在Hadoop中所有的协议接口都需要实现VersionedProtocol接口。
package com.cszjo.hadoop.rpc;
import org.apache.hadoop.ipc.VersionedProtocol;
import java.io.IOException;
/**
* RPC Protocol 类
* Created by hansiming on 2017/9/8.
*/
public interface ClientProtocol extends VersionedProtocol {
public static final long versionID = 1L;
String echo(String value) throws IOException;
int add(int a, int b) throws IOException;
}
在服务端编写具体的实现类ClientProtocolImpl,实现了协议ClientProtocol接口:
package com.cszjo.hadoop.rpc;
import org.apache.hadoop.ipc.ProtocolSignature;
import java.io.IOException;
/**
* 具体实现类
* Created by hansiming on 2017/9/8.
*/
public class ClientProtocolImpl implements ClientProtocol {
public String echo(String value) throws IOException {
return value;
}