首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 开源软件 >

[HBase]RPC框架之client兑现

2013-03-01 
[HBase]RPC框架之client实现HBase RPC的client主要工作:?1.JDK动态代理获取代理类2.调用对应服务方法,逻辑

[HBase]RPC框架之client实现

HBase RPC的client主要工作:

?

1.JDK动态代理获取代理类

2.调用对应服务方法,逻辑包装在Invoker里,新建连接,发送数据包,等待server端响应,默认超时60s

3.超时使用wait+loop检查实现

其类图如下

?[HBase]RPC框架之client兑现

0.94实现如下

HBaseRPC getProxy入口

?

?Invocation组装

?

?

?调用过程

?

?

?连上之后,初始化IO

?

?

?超时请求检查和处理

?

?

?Reader/WRITER IO操作

?

?SocketOutputStream写

  public void write(byte[] b, int off, int len) throws IOException {    ByteBuffer buf = ByteBuffer.wrap(b, off, len);//循环写,直到写完或抛异常    while (buf.hasRemaining()) {      try {        if (write(buf) < 0) {          throw new IOException("The stream is closed");        }      } catch (IOException e) {        /* Unlike read, write can not inform user of partial writes.         * So will close this if there was a partial write.         */        if (buf.capacity() > buf.remaining()) {          writer.close();        }        throw e;      }    }  }

?业务线程发送请求后,就进入等待状态,read线程则等待server端返回的数据,将返回数据反序列化后,放入call对象,并唤醒业务线程继续处理

?

热点排行