下面介绍在整个处理机制中怎么把具体的Request Call转换并调用到整体的实现逻辑。
主要以NameNode Client PRC Server作为例子来说明,整个转换通过Google Protocol Buffer RPC来实现。
final Call call = callQueue.take(); // pop the queue; maybe blocked here
.....
CurCall.set(call);
try {
// Make the call as the user via Subject.doAs, thus associating the call with the Subject
if (call.connection.user == null) {
value = call(call.rpcKind, call.connection.protocolName, call.rpcRequest,
call.timestamp);
} else {
value =
call.connection.user.doAs
(new PrivilegedExceptionAction<Writable>() {
@Override
public Writable run() throws Exception {
// make the call
return call(call.rpcKind, call.connection.protocolName,
call.rpcRequest, call.timestamp);
}
}
);
}
} catch (Throwable e) {
//process exception
}
CurCall.set(null);
synchronized (call.connection.responseQueue) {

本文深入剖析Hadoop RPC机制,以NameNode Client RPC Server为例,讲解如何将Request Call转化为具体方法调用。通过Google Protocol Buffer,实现Request/Response的序列化和反序列化,利用Java NIO进行数据传输,最终在Server端通过RPC转换执行实际逻辑。
最低0.47元/天 解锁文章
1059

被折叠的 条评论
为什么被折叠?



