读书人

[HBase]RPC框架之client兑现

发布时间: 2013-03-01 18:33:02 作者: rapoo

[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对象,并唤醒业务线程继续处理

?

读书人网 >开源软件

热点推荐