设为首页 加入收藏

TOP

Hadoop源码分析之RPC(Remote Procedure Call Protocol)
2014-11-24 08:45:06 来源: 作者: 【 】 浏览:0
Tags:Hadoop 源码 分析 RPC Remote Procedure Call Protocol

理解这个RPC是不是的先去理解哈动态代理 好多invoke,还有Socket网络编程


先来张eclipse下IPC源码图:




先来看看RPC.java,既然是动态代理,自然会想到Invoke()方法了,先来看看RPC中的Invoker中的invoke()方法


private static class Invoker implements InvocationHandler {
private InetSocketAddress address;
private UserGroupInformation ticket;
private Client client;
private boolean isClosed = false;


public Invoker(InetSocketAddress address, UserGroupInformation ticket,
Configuration conf, SocketFactory factory) {
this.address = address;
this.ticket = ticket;
this.client = CLIENTS.getClient(conf, factory);
}


public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable {
final boolean logDebug = LOG.isDebugEnabled();
long startTime = 0;
if (logDebug) {
startTime = System.currentTimeMillis();
}


ObjectWritable value = (ObjectWritable)
client.call(new Invocation(method, args), address,
method.getDeclaringClass(), ticket);
if (logDebug) {
long callTime = System.currentTimeMillis() - startTime;
LOG.debug("Call: " + method.getName() + " " + callTime);
}
return value.get();
}

/* close the IPC client that's responsible for this invoker's RPCs */
synchronized private void close() {
if (!isClosed) {
isClosed = true;
CLIENTS.stopClient(client);
}
}
}


可以看出动态代理里的invoke()方法其实是RPC里的invocation对方法名,参数做了封装,可以看invocation类的


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇OK6410 uart 简单测试程序 下一篇Android在Activity之间传数据之In..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·有没有哪些高效的c++ (2025-12-27 08:20:57)
·Socket 编程时 Accep (2025-12-27 08:20:54)
·计算机网络知识点总 (2025-12-27 08:20:52)
·一篇说人话的文章, (2025-12-27 07:50:09)
·Python Web框架哪家 (2025-12-27 07:50:06)