服务端代码放在org.apache.hadoop.yarn.server.api.impl.pb.server包中,且类名为Resource-TrackerPBServerImpl,实现如下
- public class ResourceTrackerPBServiceImpl implements ResourceTrackerPB {
- private ResourceTracker real;
- public ResourceTrackerPBServiceImpl(ResourceTracker impl) {
- this.real = impl;
- }
- @Override
- public RegisterNodeManagerResponseProto registerNodeManager(
- RpcController controller, RegisterNodeManagerRequestProto proto)
- throws ServiceException {
- RegisterNodeManagerRequestPBImpl request = new RegisterNodeManagerRequestPBImpl(proto);
- try {
- RegisterNodeManagerResponse response = real.registerNodeManager(request);
- return ((RegisterNodeManagerResponsePBImpl)response).getProto();
- } catch (YarnException e) {
- throw new ServiceException(e);
- } catch (IOException e) {
- throw new ServiceException(e);
- }
- }
- ...
- }
总结上面几个步骤,为了实现基于Protocol Buffers序列化框架的YARN RPC通信协议ResourceTracker,YARN实现了一系列Java接口定义和Protocol Buffers封装,具体如图3-12所示(以服务器端实现为例)。