Tars 实体关系图
2018-08-31 15:35:22 4 举报
tars框架核心ER图
作者其他创作
大纲/内容
*
1
2.1 //在全局域中注册Servant名字Application::addServant(servantId);
//4.1业务逻辑处理流程//将具体servant类指向自己servant-setHandle(this);
4.1 启动业务处理线程for (auto& kv : _handleGroups){handle-start()}
#6.2 //IO线程 eventloopNetThread::run(){ int iEvNum = _epoller.wait(2000); switch(h) { case ET_LISTEN: ret = accept(fd); case ET_CLOSE: case ET_NOTIFY: processPipe(); case ET_NET: processNet(ev); }}
ServantHandle
- initialize();//具体实现- addServant();- setHandle(BindAdapter& adapter)
3.3 handle-setHandleGroup(hg);
BindAdapter
+ name+_handleGroupPtr:HandleGroupPtr- _pEpollserver:EpollServerPtr
+ main- initialize() = 0 :virtual- addServant();- setHandle(BindAdapter& adapter)
//4.1业务逻辑处理流程ServantHandle::initialize(){ // 创建Servant实例 ServantPtr servant = ServantHelperManager::create(adpit-first); // 缓存起来 __servants[servant-getName()] = servant; //将具体servant类指向自己 servant-setHandle(this); //调用具体servant类的初始化函数 servant-initialize();}
Reactor域
#1. //将bindAdapter(业务handler)绑定到IO线程上去Applicaiton::BindAdapter(AdaptersPtr)
#3. //为adapter绑定handleGroup3.1、为HandleGroup绑定对应的业务处理接口(虚接口)Application::setHandle[4Adapter](adapterPtr)
ServantImp
//需实现+ initialize() //servant初始化。+ virtual int onDispatch()+ virtual int doResponse();+ virtual int doClose();
#5. //给IO线程加入到Epoll队列中EpollServer::createEpoll();
Server
//配置文件中绑定app、server、adapter(servant、handleGroup)
- initialize(){ Applicaiton::addServant(ServantImpId) Applicaiton::addServantProtocol()}
#4. //启动业务处理线程EpollServer::startHandle();
Applicaiton g_app;int main(){ g_app.main(); g_app.waitForShutdown();}
业务代码域
Handle(桥接,ReactorHandler)
+_adapters:vector- _epollserver:EpollServer*//处理器所关联的epollloop- _handleGroup: HandleGroupPtr//处理线程所属的组
+ void run()// epollLoop{ initialize(); //纯虚函数 handleImp();//纯虚函数}//依赖关系处理void setEpollServer(TC_EpollServer *pEpollServer);- EpollServer* getEpollServer();void setHandleGroup(HandleGroupPtr& pHandleGroup);HandleGroupPtr& getHandleGroup();//虚函数virtual void handle(const tagRecvData &stRecvData) = 0;virtual void initialize() {};virtual void notifyFilter();virtual void startHandle() {}virtual void stopHandle() {}virtual void heartbeat() {}virtual void handleClose(const tagRecvData &stRecvData);virtual void handleTimeout(const tagRecvData &stRecvData);
TC_Config
- Application- Server- adapterDomain
#6. //启动所有IO线程EpollServer::waitForShutdown();
Servant
+ _name:string+_adapters:vector- _handle:EpollServer::Handle* //归属+ _asyncResponseQueue;异步响应队列
+ setHandle(HandlePtr handler);Handle* Servant::getHandle();virtual void initialize() = 0;//虚函数//区分Tars和非Tars协议,处理不同virtual int dispatch();//分发收到的请求virtual int onDispatch();virtual int doResponse();virtual int doClose();
1.2 _epollServer-bind(adapterPtr);//创建 epollServer::listeners
+ run():overwrite// epollLoop+ bind(AdapterPtr);+ createEpoll();- processNet()- processPipe- close();- recvBuffer()
1.2.1 netThread0-bind(adapter);//启动业务处理线程
3.6 设置关联关系 HandleGroup::_adapters[adapter-getName()] = adapter; adapter-_handleGroup = it-second;
Thread
+ _running:bool+ _tid:pthread_t+ _lock:TC_ThreadLock
+start()- run()= 0 :virtual
5.2 监听linstener. 创建 客户端连接池 connLists 5.2.1 0号IO线程:将listeners 加入到epoll监听队列中_netThread[i]::createEpoll(index);5.2.2 所有线程初始化 客户端连接池connList_
Handle域
Applicaiton
- _conf: TC_Config;// Application Server- _adapters:vector- _epollserver:EpollServer
+ main{ - initServer();//初始化IO EventLoop //#0 - bindAdapter(_adapters) //#1 - initialize() = 0 :virtual //#2 - addServant(BindAdapter adapter);//添加Servant的模板方法 - addServantProtocol() - setHandle(BindAdapter& adapter)#3 - _epollServer-StartHandle();//启动业务处理线程#4 - _epollSeerver-create_epoll();//启动IO网络线程#5}
#6.1 //启动所有IO线程netThreads[i]-start();
ServantHelperMgr
#2. //子类每个Server初始化。添加各ServantApplication::initialise();
5.1 //启动所有IO线程netThread[i]::createEpoll(index);
HandleGroup
/** * 按name对handle分组, * 每组handle处理一个或多个Adapter消息 * 每个handle对象一个线程 */
3.3 handle-setEpollServer(this);
#0. //创建EventLoop IO多线程_epollServer = new EpollServer(IPOThreadNum)
收藏
0 条评论
回复 删除
下一页