|
ngl_server 1.0
基于 Actor 模型的 C++ 服务器框架
|
独立调度单元,拥有调度线程和分配到此层的所有actor查找表。 More...
#include <actor_manage.h>
Public Member Functions | |
| schedule_layer () | |
| schedule_layer构造函数 | |
| void | get_type (std::set< i16_actortype > &aactortype) |
| 获取当前层所有actor类型 | |
| bool | add_actor (const ptractor &apactor, const std::function< void()> &afun) |
| 向调度层添加新actor | |
| void | erase_actor (const nguid &aguid, const std::function< void()> &afun=nullptr) |
| 从调度层移除actor | |
| bool | is_have_actor (const nguid &aguid) |
| 检查调度层是否包含指定actor | |
| void | push (const ptractor &apactor, bool aready=true) |
| 将处理完成的actor返回调度层 | |
| bool | push_task_id (const nguid &aguid, handle_pram &apram, bool aismass=true) |
| 向指定GUID的actor推送消息 | |
| bool | push_task_id (const std::set< i64_actorid > &asetguid, handle_pram &apram) |
| 向多个GUID的actor批量推送消息 | |
| void | push_task_type (ENUM_ACTOR atype, handle_pram &apram) |
| 向指定类型的所有actor推送消息 | |
| void | broadcast_task (handle_pram &apram) |
| 向当前层所有广播actor推送消息 | |
| int32_t | actor_count () |
| 获取当前层actor数量 | |
| void | get_actor_stat (std::map< ENUM_ACTOR, msg_actor > &astatmap) |
| 获取当前层actor统计信息 | |
Static Public Member Functions | |
| static nguid | get_clientguid () |
| 获取客户端路由actor的GUID | |
| static nguid | nodetypebyguid () |
| 获取路由actor的GUID | |
独立调度单元,拥有调度线程和分配到此层的所有actor查找表。
该类是分层调度架构的核心组件,负责:
设计特点:
| ngl::schedule_layer::schedule_layer | ( | ) |
schedule_layer构造函数
立即启动调度线程。线程在m_sem信号量上阻塞直到actor被推入, 因此与actor_manage::init()不存在竞争。线程是分离的,在进程 生命周期内运行,没有join或停止逻辑。
| int32_t ngl::schedule_layer::actor_count | ( | ) |
获取当前层actor数量
| bool ngl::schedule_layer::add_actor | ( | const ptractor & | apactor, |
| const std::function< void()> & | afun ) |
向调度层添加新actor
将actor注册到ID索引表、类型索引表和广播表中, 并通知路由actor新actor的存在以便远程节点发现。 路由actor(ACTOR_CLIENT/ACTOR_SERVER)立即可用无需同步。
| [in] | apactor | 要添加的actor智能指针 |
| [in] | afun | 添加完成后的回调函数 |
| void ngl::schedule_layer::broadcast_task | ( | handle_pram & | apram | ) |
向当前层所有广播actor推送消息
遍历广播表中的所有可用actor并推送消息。
| [in] | apram | 消息处理参数 |
| void ngl::schedule_layer::erase_actor | ( | const nguid & | aguid, |
| const std::function< void()> & | afun = nullptr ) |
从调度层移除actor
从所有查找表中移除actor,通知路由actor进行远程注销。 根据actor当前状态决定立即执行回调还是延迟到工作线程返回后执行。
| [in] | aguid | 要移除的actor的GUID |
| [in] | afun | 移除完成后的回调函数(可选) |
| void ngl::schedule_layer::get_actor_stat | ( | std::map< ENUM_ACTOR, msg_actor > & | astatmap | ) |
获取当前层actor统计信息
收集当前层所有actor类型和各区域的actor ID列表。
| [out] | astatmap | 输出参数,按actor类型存储统计信息 |
|
static |
获取客户端路由actor的GUID
| void ngl::schedule_layer::get_type | ( | std::set< i16_actortype > & | aactortype | ) |
获取当前层所有actor类型
收集当前调度层中所有注册的actor类型到集合中。
| [out] | aactortype | 输出参数,存储所有actor类型 |
| bool ngl::schedule_layer::is_have_actor | ( | const nguid & | aguid | ) |
检查调度层是否包含指定actor
| [in] | aguid | 要检查的actor的GUID |
|
static |
获取路由actor的GUID
根据当前节点类型返回对应的路由actor GUID。
| void ngl::schedule_layer::push | ( | const ptractor & | apactor, |
| bool | aready = true ) |
将处理完成的actor返回调度层
根据actor状态决定下一步操作:
| [in] | apactor | 处理完成的actor智能指针 |
| [in] | aready | 是否强制入队(默认true,仅当队列非空时入队) |
| bool ngl::schedule_layer::push_task_id | ( | const nguid & | aguid, |
| handle_pram & | apram, | ||
| bool | aismass = true ) |
向指定GUID的actor推送消息
在本地查找actor并推送消息。如果本地未找到且aismass为true, 将消息转发给路由actor进行远程投递。
| [in] | aguid | 目标actor的GUID |
| [in] | apram | 消息处理参数 |
| [in] | aismass | 是否允许转发到路由actor(默认true) |
| bool ngl::schedule_layer::push_task_id | ( | const std::set< i64_actorid > & | asetguid, |
| handle_pram & | apram ) |
向多个GUID的actor批量推送消息
遍历GUID集合,逐一调用单GUID版本的push_task_id, 不允许转发到路由actor。
| [in] | asetguid | 目标actor的GUID集合 |
| [in] | apram | 消息处理参数 |
| void ngl::schedule_layer::push_task_type | ( | ENUM_ACTOR | atype, |
| handle_pram & | apram ) |
向指定类型的所有actor推送消息
遍历当前层中指定类型的所有可用actor并推送消息。
| [in] | atype | 目标actor类型 |
| [in] | apram | 消息处理参数 |