1.服务器端启动流程
(3) RPC.Invoker.invoke()实际方法中调用
Client
对象的call() 方法
(4)
Client.
call()
方法根据RPC.Invocation对象构建Client.Call()对象
(5)
Client.
call()
方法构建 Client.Connection线程
(6) Client.Connection
线程
包括一个ConnectionHeader对象,构建它
(8)将
Client.Call()对象放入Client.Connection
线程的calls字段中
(1) RPC类构建Server对象,Server对象包括Server.Listener
线程
(2) 构建Server.Listener
线程,acceptChannel.socket绑定IP和端口,acceptChannel注册到selector接收事件
(3) Server.Listener
线程包括若干Server.Listener.Reader
线程,构建并运行Server.Listener.Reader线程
(4) Server对象包括Server.Responder
线程,构建Server.Responder线程
(5) Server.Listener
线程运行,Server.Responder
线程运行,构建若干Server.Handler
线程并运行
2.客户端连接流程
(1) RPC返回实现VersionedProtocol代理,需要构建一个RPC.Invoker对象
(2)RPC.Invoker对象包含一个RPC.ConnectionId对象,构建的RPC.ConnectionId对象里面填写了地址、协议等信息
(3) RPC.Invoker对象包含一个Client对象,构建的Client对象,
(4) 请求版本信息,对比版本,此时开始真正的连接
3.客户端发送流程(请求版本信息)
(1)客户端代理调用RPC.Invoker对象的invoke()方法(使用动态代理调用)
(2)此时根据请求参数构建一个RPC.Invocation对象并传送,也传送RPC.ConnectionId对象
(7)将RPC.ConnectionId对象和Client.Connection
线程
放入字段Client.connections字段 (一个HashMap)中,作为缓存
(9)进行Socket连接,
(10)向Socket写入头信息RPCHeader信息(字符串"hrpc")
(11)向Socket写入头信向Socket写入头信息RPCHeader信息(字符串"hrpc")
(12)启动Client.Connection线程
(13)向Socket写入正式请求(Client.Call()对象),之后等待完成(看call.done是否为真)
4.服务器端接收、处理、发送流程
(5)
Server
.
Listener
.Reader
线程
监听到读请求的Server.Connection对象,对Server.Connection对象中的channel读取数据,依次读取rpcHeader、ConnectionHeader,根据ConnectionHeader,构建Connection对象的protocal字段,
(9)Server.Handler线程将结构保留在
Server
.
Call
对象的字段value中,将
Server
.
Call
放在
Server.Connection对象的responseQueue中
5.客户端接收流程
(1)Client.Connection线程从输入流中读取到数据,将call.done设为真,线程运行结束
(2)主线程监测到call.done为真,将call.value返回。