Documentation ¶
Overview ¶
Package roc 每个 micserver 进程会持有一份 ROC 缓存单例,维护了所有已知的ROC对象所处的位置
Package roc Remote Object Call. ROC ,是 micserver 重要的分布式目标调用思想。 如果一个对象,例如房间/商品/玩家/工会,需要提供一个可供远程执行的操作, 这在以前称之为 RPC 调用,在 micserver 中,任意一个构造了这种对象的模块, 均可以通过 BaseModule.GetROC(objtype).GetOrRegObj(obj) 来 注册一个 ROC 对象,在其他模块中,只需要通过 BaseModule.ROCCallNR 等方法,提供 目标对象的类型及ID,即可发起针对该对象的远程操作。 因此,在任意模块中,发起的任意针对其他模块的调用,都不应该使用模块ID来操作, 因为使用统一的 ROC 至少包含以下好处:
无需知道目标对象在哪个模块上; 只需要关心目标对象的ID(目标的类型你当然是知道的); 在模块更新时,可以统一将该模块的 ROC 对象迁移到新版本模块中实现热更; 可以将对象存储到数据库并且在其他模块中加载(基于第一点好处); 对象的位置/调用路由等由底层系统维护,可提供一个高可用/强一致/易维护的分布式网络。
Index ¶
- Constants
- Variables
- type Cache
- func (c *Cache) Del(objType ObjType, objID string, moduleID string) bool
- func (c *Cache) DelM(objType ObjType, objIDs []string, moduleID string) int
- func (c *Cache) Get(objType ObjType, objID string) string
- func (c *Cache) RandomObjIDByType(objType ObjType, limitModuleIDs map[string]bool) string
- func (c *Cache) RangeByType(objType ObjType, f func(id string, location string) bool, ...)
- func (c *Cache) Set(objType ObjType, objID string, moduleID string) error
- func (c *Cache) SetM(objType ObjType, objIDs []string, moduleID string) error
- type IObj
- type IROCObjEventHook
- type IROCServer
- type Manager
- func (rocManager *Manager) Call(callstr string, arg []byte) ([]byte, error)
- func (rocManager *Manager) CallPathDecode(kstr string) (ObjType, string)
- func (rocManager *Manager) GetObj(objType ObjType, objID string) (IObj, bool)
- func (rocManager *Manager) GetROC(objtype ObjType) *ROC
- func (rocManager *Manager) HookObjEvent(hook IROCObjEventHook)
- func (rocManager *Manager) NewROC(objtype ObjType) *ROC
- func (rocManager *Manager) OnROCObjAdd(obj IObj)
- func (rocManager *Manager) OnROCObjDel(obj IObj)
- func (rocManager *Manager) RegObj(obj IObj) error
- type ObjType
- type Path
- type ROC
- func (roc *ROC) DelObj(obj IObj) error
- func (roc *ROC) DelObjByID(id string) error
- func (roc *ROC) GetObj(id string) (IObj, bool)
- func (roc *ROC) GetOrRegObj(id string, obj IObj) (IObj, bool)
- func (roc *ROC) HookObjEvent(hook IROCObjEventHook)
- func (roc *ROC) Init()
- func (roc *ROC) RangeObj(f func(obj IObj) bool)
- func (roc *ROC) RegObj(obj IObj) error
Constants ¶
const (
CachePoolGroupSum = 8
)
ROC缓存分组数量
const (
PoolGroupSum = 8
)
ROC 对象分组数
Variables ¶
var ( ErrUnregisterROC = errors.New("unregistered roc") ErrUnknowObj = errors.New("unknow roc obj") )
ROC错误定义
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache ROC缓存管理器
func (*Cache) RandomObjIDByType ¶
RandomObjIDByType 随机获取一个目标类型的缓存对象ID
func (*Cache) RangeByType ¶
func (c *Cache) RangeByType(objType ObjType, f func(id string, location string) bool, limitModuleIDs map[string]bool)
RangeByType 遍历指定类型的ROC对象
type IObj ¶
type IObj interface { GetROCObjType() ObjType GetROCObjID() string OnROCCall(*Path, []byte) ([]byte, error) }
IObj ROC对象需要实现的接口
type IROCObjEventHook ¶
IROCObjEventHook ROC事件处理需要实现的接口
type IROCServer ¶
type IROCServer interface { GetROC(ObjType) *ROC NewROC(ObjType) *ROC ROCCallNR(*Path, []byte) error ROCCallBlock(*Path, []byte) ([]byte, error) GetROCCachedLocation(ObjType, string) string RangeROCCachedByType(ObjType, func(id string, location string) bool) RandomROCCachedByType(ObjType) string }
IROCServer ROC服务器实现的接口
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager ROC 管理器,每个 Module 都包含了一个ROC管理器,管理了本 Module 已注册的所有ROC类型及ROC对象。
func (*Manager) CallPathDecode ¶
CallPathDecode 解码ROC调用路径
func (*Manager) HookObjEvent ¶
func (rocManager *Manager) HookObjEvent(hook IROCObjEventHook)
HookObjEvent 监听ROC事件
func (*Manager) OnROCObjAdd ¶
OnROCObjAdd 当增加一个ROC对象时调用
func (*Manager) OnROCObjDel ¶
OnROCObjDel 当删除一个ROC对象时调用
type Path ¶
type Path struct {
// contains filtered or unexported fields
}
Path ROC调用的路径
type ROC ¶
type ROC struct {
// contains filtered or unexported fields
}
ROC 一个类型的ROC,维护了这个类型的所有 ROC 对象
func (*ROC) GetOrRegObj ¶
GetOrRegObj 获取或者注册一个ROC对象