您的位置:首页 > 其它

Finagle源码分析之Mux.client

2018-01-25 16:37 597 查看
Finagle 客户端实现过程,由于协议无关性,这里以Mux协议为例,Http等流程相同。
The core of Finagle is protocol-agnostic,
meaning its internals provide an extensible RPC subsystem without
defining any details of specific client-server protocols.
Thus in order to provide usable APIs for clients and servers,
there are a number of Finagle subprojects
that implement common protocols.


Mux.Client 的 trait 的调用时序如下:1 Mux.apply new org:Mux.Client
2 StackClient StackClient.stack
3 StackClient.stack return new StackBuilder.addModule
4 org:Parameterized , orig.configure
5 orig:Mux.Client orig.newClient6 orig:EndpointerStackClient orig.newClient7 orig:StackClient orig.endpointer8 orig:StackClient orig.copy1
9 copy1:EndpointerStackClient copy1.newTransport10 copy1:Mux.Client copy1.newTransport

11 new EndpointerModule( transport, copy1.newDispatch)

12 orig:Mux.Client copy1.stack11 StackClient StackClient.stack12 StackClient return new StackBuilder.addModule

13 (stack ++ endpointer).make14 endpointer:EndpointModule endpointer.mk
15 Module.mk

16 sf:ServiceFactory sf.apply17 sf_next:ServiceFactory sf_next.apply
18 copy1.newDispatch:EndpointStackClient19 copy1.newDispatch:Mux.client20 newRequestResponse:mux.dispatcher21 createServiceFromDispatcher

22 createServiceAsFilter
23 service.apply
24 filter.apply
25 mux.dispatch service.apply
Mux 调用apply创建新的客户端 Mux.client (步骤1),StackClient 返回需要的 Module (步骤2,3) newClient 创建 ServiceFactory,这里首先创建 endpointer(步骤7)最重要的方法1 newTrsport,2 newDispatch (步骤11), filter 嵌入 在步骤(13) endpointer 绑定到一个 transport,每次请求 service时候,调用一次 newDispath 并提供 transport。 实现这两个模版方法里可以关联不同的协议栈,实现不同类型的客户端如 Mux,http。
转自:https://github.com/mengyuetao
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  finagle