1、Client有五个内部类,分别是Call,ParallelCall,ParallelResult,Connetion,ConnectionId

其实这五个类就是去完成两件事情的,一件事情是连接,另外一件事情是调用,而连接呢主要通过Connection来完成,ConnectionId是它的辅助类。调用呢,Call为主,由于会同时和NameNode和其他DataNode通讯,所以需要一个ParallelCall来完成这件事,调用完了总有个返回值吧,所以要有ParallelResult这个类。

2、先来看ConnectionId

This class holds the address and the user ticket. The client connections to servers are uniquely identified by <remoteAddress, protocol, ticket>这个是源码的解释,

下边有10个属性,最核心也就是address,ticket,protocol,连接相关的有rpcTimeout,serverPrincipal,maxIdleTime,connectionRetryPolicy,tcpNoDelay,pingInterval

Nagle算法是以他的发明人John Nagle的名字命名的,它用于自动连接许多的小缓冲器消息;这一过程(称为nagling)通过减少必须发送包的个数来增加网络软件系统的效率。Nagle的算 法通常会在TCP程 序里添加两行代码,在未确认数据发送的时候让发送器把数据送到缓存里。任何数据随后继续直到得到明显的数据确认或者直到攒到了一定数量的数据了再发包。

InetSocketAddress address;
     UserGroupInformation ticket;
     Class<?> protocol;
     private static final int PRIME = 16777619;//这个家伙也就是在hashcode里边用了一下
     private int rpcTimeout;
     private String serverPrincipal;
     private int maxIdleTime; //connections will be culled if it was idle for maxIdleTime msecs
     private final RetryPolicy connectionRetryPolicy;
     private boolean tcpNoDelay; // if T then disable Nagle's Algorithm
     private int pingInterval; // how often sends ping to the server in msecs
3、再来看看Connection,

Thread that reads responses and notifies callers.  Each connection owns a socket connected to a remote address.  Calls are multiplexed through this socket: responses may be delivered out of order.

这个家伙继承了Thread这个类,主要读取相应通知调用者,每个连接都维护一个到远端的连接。调用时多路复用:响应不是按序的?

里边也包含了一个内部类PingInputStream

This class sends a ping to the remote side when timeout on reading. If no failure is detected, it retries until at least  a byte is read.

如果没有检测到失败,它会坚持重试到最后一个字节被读取
   private class PingInputStream extends FilterInputStream {}

下面的属性

private InetSocketAddress server;             // server ip:port,这个ConnectionId里边有
  private String serverPrincipal;  // server's krb5 principal name   kerberos这个是一种安全认证系统,如果失败了会用SASL :简单认证与安全层(Simple Authentication And Security Layer),简单认证和安全层,简单身份验证和安全层 ?
  private ConnectionHeader header;              // connection header
  private final ConnectionId remoteId;                // connection id
  private AuthMethod authMethod; // authentication method
  private boolean useSasl;
  private Token<? extends TokenIdentifier> token;
  private SaslRpcClient saslRpcClient;
 
  private Socket socket = null;                 // connected socket
  private DataInputStream in;
  private DataOutputStream out;

下面这几个ConnectionId里边也有
  private int rpcTimeout;
  private int maxIdleTime; //connections will be culled if it was idle for maxIdleTime msecs
  private final RetryPolicy connectionRetryPolicy;
  private boolean tcpNoDelay; // if T then disable Nagle's Algorithm
  private int pingInterval; // how often sends ping to the server in msecs

// currently active calls,并发的这几个要注意下,自己不是很熟,以前自己也没见过把Exception定义为属性变量
  private Hashtable<Integer, Call> calls = new Hashtable<Integer, Call>();
  private AtomicLong lastActivity = new AtomicLong();// last I/O activity time
  private AtomicBoolean shouldCloseConnection = new AtomicBoolean();  // indicate if the connection is closed
  private IOException closeException; // close reason

4、上边的calls里边出现了Call这个类,

A call waiting for a value.

这个简单,就5个属性,分别是id,参数,返回值,异常,结束标志位,平时我们一个方法调用也不过是个参数列表,返回值,异常,只不过这个加了个id和结束标志位done。

int id;                                       // call id
   Writable param;                               // parameter
   Writable value;                               // value, null if error
   IOException error;                            // exception, null if value
   boolean done;                                 // true when call is done

5、在看看这个ParallelCall

Call implementation used for parallel calls.

这个里边就两个属性,当然它继承至Call的属性暂时忽略

private ParallelResults results;
private int index;
6、上面的第一个属性ParallelResults,看看这个内部类

Result collector for parallel calls.

三个属性,也很简单

private Writable[] values;// store the value
private int size;//if (count == size)     notify();                          // if all values are in  then notify waiting caller
private int count; // count it

最新文章

  1. nginx服务器http重定向到https的正确写法
  2. KMP模板
  3. sqlserver查询数据的所有表名和行数
  4. css3 animation 属性众妙
  5. MyEclipse使用总结——设置MyEclipse使用的Tomcat服务器 设置JDK
  6. Python之re模块
  7. C#实现对邮件的发送
  8. Qt中文乱码问题(比较清楚,同一个二进制串被解释成不同的语言)
  9. typedef使用
  10. CI 模板解析器类
  11. js动画学习(三)
  12. 【Android Developers Training】 69. 视图切换的淡入淡出效果
  13. 10. 管理Apache ZooKeeper配置
  14. http.request请求及在node中post请求参数解析
  15. 基于 IJKPlayer-concat 协议的视频无缝拼接技术实现
  16. TRY
  17. Python基础-用户验证
  18. 【译】9. Java反射——泛型
  19. 关于Java变量的可见性问题
  20. 牛客网数据库SQL实战(11-15)

热门文章

  1. spring data jpa 创建方法名进行简单查询
  2. Java中的Double类型计算
  3. 【摘抄】meta系列用法总结【持续更新中】
  4. CSS3_概述、发展史、模块介绍、与浏览器之间的关系
  5. Css3_浏览器支持
  6. git服务器搭建
  7. OpenCV_轮廓的查找、表达、绘制、特性及匹配
  8. 腾讯云从零部署nodejs站点
  9. this(C# 参考)
  10. [JavaScript] 函数同名问题