Documentation
¶
Overview ¶
Package service 服务相关类与函数。
- 服务上下文(Context)
- 实体管理器(IEntityMgr)
Index ¶
- func GetInheritor[T any](ctx Context) T
- func UnsafeContext(ctx Context) _UnsafeContext
- type Context
- type ContextBehavior
- func (ctx *ContextBehavior) AsyncCall(entityID ec.ID, segment func(entity ec.Entity) Ret) <-chan Ret
- func (ctx *ContextBehavior) AsyncCallNoRet(entityID ec.ID, segment func(entity ec.Entity))
- func (ctx *ContextBehavior) AsyncCallNoRetWithSerialNo(entityID ec.ID, entitySerialNo int64, segment func(entity ec.Entity))
- func (ctx *ContextBehavior) AsyncCallWithSerialNo(entityID ec.ID, entitySerialNo int64, segment func(entity ec.Entity) Ret) <-chan Ret
- func (ctx *ContextBehavior) GenPersistID() ec.ID
- func (ctx *ContextBehavior) GenSerialNo() int64
- func (ctx *ContextBehavior) GetEntityMgr() IEntityMgr
- func (ctx *ContextBehavior) GetEntityPt(prototype string) (pt.EntityPt, bool)
- func (ctx *ContextBehavior) GetName() string
- func (ctx *ContextBehavior) GetPlugin(pluginName string) (util.FaceAny, bool)
- func (ctx *ContextBehavior) SyncCall(entityID ec.ID, segment func(entity ec.Entity) Ret) Ret
- func (ctx *ContextBehavior) SyncCallNoRet(entityID ec.ID, segment func(entity ec.Entity))
- func (ctx *ContextBehavior) SyncCallNoRetWithSerialNo(entityID ec.ID, entitySerialNo int64, segment func(entity ec.Entity))
- func (ctx *ContextBehavior) SyncCallWithSerialNo(entityID ec.ID, entitySerialNo int64, segment func(entity ec.Entity) Ret) Ret
- type ContextOption
- type ContextOptions
- type IEntityMgr
- type Ret
- type WithContextOption
- func (WithContextOption) AutoRecover(v bool) ContextOption
- func (WithContextOption) Context(v context.Context) ContextOption
- func (WithContextOption) Default() ContextOption
- func (WithContextOption) EntityLib(v pt.EntityLib) ContextOption
- func (WithContextOption) GenPersistID(v func() ec.ID) ContextOption
- func (WithContextOption) Inheritor(v util.Face[Context]) ContextOption
- func (WithContextOption) Name(v string) ContextOption
- func (WithContextOption) PluginBundle(v plugin.PluginBundle) ContextOption
- func (WithContextOption) ReportError(v chan error) ContextOption
- func (WithContextOption) StartedCallback(v func(serviceCtx Context)) ContextOption
- func (WithContextOption) StoppedCallback(v func(serviceCtx Context)) ContextOption
- func (WithContextOption) StoppingCallback(v func(serviceCtx Context)) ContextOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func UnsafeContext ¶
func UnsafeContext(ctx Context) _UnsafeContext
Types ¶
type Context ¶
type Context interface {
internal.Context
internal.RunningMark
plugin.PluginResolver
pt.PtResolver
// GetName 获取名称
GetName() string
// GenSerialNo 生成流水号(运行时唯一)
GenSerialNo() int64
// GenPersistID 生成持久化ID(全局唯一)
GenPersistID() ec.ID
// GetEntityMgr 获取实体管理器
GetEntityMgr() IEntityMgr
// contains filtered or unexported methods
}
Context 服务上下文
func UnsafeNewContext ¶
func UnsafeNewContext(options ContextOptions) Context
type ContextBehavior ¶
type ContextBehavior struct {
internal.ContextBehavior
internal.RunningMarkBehavior
// contains filtered or unexported fields
}
ContextBehavior 服务上下文行为,在需要扩展服务上下文能力时,匿名嵌入至服务上下文结构体中
func (*ContextBehavior) AsyncCall ¶
func (ctx *ContextBehavior) AsyncCall(entityID ec.ID, segment func(entity ec.Entity) Ret) <-chan Ret
AsyncCall 异步调用。查找实体,并获取实体的运行时,将代码片段压入运行时的任务流水线,串行化的进行调用,不会阻塞,会返回result channel。
注意: - 代码片段中的线程安全问题。 - 在代码片段中,如果向调用方所在的运行时发起同步调用,并且调用方也在阻塞result channel等待返回值,那么会造成线程死锁。 - 调用过程中的panic信息,均会转换为error返回。
func (*ContextBehavior) AsyncCallNoRet ¶
func (ctx *ContextBehavior) AsyncCallNoRet(entityID ec.ID, segment func(entity ec.Entity))
AsyncCallNoRet 异步调用,无返回值。查找实体,并获取实体的运行时,将代码片段压入运行时的任务流水线,串行化的进行调用,不会阻塞,没有返回值。
注意: - 代码片段中的线程安全问题。 - 调用过程中的panic信息,均会抛弃。
func (*ContextBehavior) AsyncCallNoRetWithSerialNo ¶
func (ctx *ContextBehavior) AsyncCallNoRetWithSerialNo(entityID ec.ID, entitySerialNo int64, segment func(entity ec.Entity))
AsyncCallNoRetWithSerialNo 与AsyncCallNoRet相同,只是同时使用id与serialNo可以在多线程环境中准确定位实体
func (*ContextBehavior) AsyncCallWithSerialNo ¶
func (ctx *ContextBehavior) AsyncCallWithSerialNo(entityID ec.ID, entitySerialNo int64, segment func(entity ec.Entity) Ret) <-chan Ret
AsyncCallWithSerialNo 与AsyncCall相同,只是同时使用id与serialNo可以在多线程环境中准确定位实体
func (*ContextBehavior) GenPersistID ¶
func (ctx *ContextBehavior) GenPersistID() ec.ID
GenPersistID 生成持久化ID(全局唯一)
func (*ContextBehavior) GenSerialNo ¶
func (ctx *ContextBehavior) GenSerialNo() int64
GenSerialNo 生成流水号(运行时唯一)
func (*ContextBehavior) GetEntityMgr ¶
func (ctx *ContextBehavior) GetEntityMgr() IEntityMgr
GetEntityMgr 获取实体管理器
func (*ContextBehavior) GetEntityPt ¶
func (ctx *ContextBehavior) GetEntityPt(prototype string) (pt.EntityPt, bool)
GetEntityPt 获取实体原型
func (*ContextBehavior) GetPlugin ¶
func (ctx *ContextBehavior) GetPlugin(pluginName string) (util.FaceAny, bool)
GetPlugin 获取插件
func (*ContextBehavior) SyncCall ¶
SyncCall 同步调用。查找实体,并获取实体的运行时,将代码片段压入运行时的任务流水线,串行化的进行调用,会阻塞并等待返回值。
注意: - 代码片段中的线程安全问题。 - 当运行时的SyncCallTimeout选项设置为0时,在代码片段中,如果向调用方所在的运行时发起同步调用,那么会造成线程死锁。 - 调用过程中的panic信息,均会转换为error返回。
func (*ContextBehavior) SyncCallNoRet ¶
func (ctx *ContextBehavior) SyncCallNoRet(entityID ec.ID, segment func(entity ec.Entity))
SyncCallNoRet 同步调用,无返回值。查找实体,并获取实体的运行时,将代码片段压入运行时的任务流水线,串行化的进行调用,会阻塞,没有返回值。
注意: - 代码片段中的线程安全问题。 - 当运行时的SyncCallTimeout选项设置为0时,在代码片段中,如果向调用方所在的运行时发起同步调用,那么会造成线程死锁。 - 调用过程中的panic信息,均会抛弃。
func (*ContextBehavior) SyncCallNoRetWithSerialNo ¶
func (ctx *ContextBehavior) SyncCallNoRetWithSerialNo(entityID ec.ID, entitySerialNo int64, segment func(entity ec.Entity))
SyncCallNoRetWithSerialNo 与SyncCallNoRet相同,只是同时使用id与serialNo可以在多线程环境中准确定位实体
func (*ContextBehavior) SyncCallWithSerialNo ¶
func (ctx *ContextBehavior) SyncCallWithSerialNo(entityID ec.ID, entitySerialNo int64, segment func(entity ec.Entity) Ret) Ret
SyncCallWithSerialNo 与SyncCall相同,只是同时使用id与serialNo可以在多线程环境中准确定位实体
type ContextOptions ¶
type ContextOptions struct {
Inheritor util.Face[Context] // 继承者,需要扩展服务上下文自身能力时需要使用
Context context.Context // 父Context
AutoRecover bool // 是否开启panic时自动恢复
ReportError chan error // panic时错误写入的error channel
Name string // 服务名称
GenPersistID func() ec.ID // 生成持久化ID的函数
EntityLib pt.EntityLib // 实体原型库
PluginBundle plugin.PluginBundle // 插件包
StartedCallback func(serviceCtx Context) // 启动运行时回调函数
StoppingCallback func(serviceCtx Context) // 开始停止运行时回调函数
StoppedCallback func(serviceCtx Context) // 完全停止运行时回调函数
}
ContextOptions 创建服务上下文的所有选项
type IEntityMgr ¶
type IEntityMgr interface {
// GetServiceCtx 获取服务上下文
GetServiceCtx() Context
// GetEntity 查询实体
GetEntity(id ec.ID) (ec.Entity, bool)
// GetEntityWithSerialNo 查询实体,同时使用id与serialNo可以在多线程环境中准确定位实体
GetEntityWithSerialNo(id ec.ID, serialNo int64) (ec.Entity, bool)
// GetOrAddEntity 查询或添加实体
GetOrAddEntity(entity ec.Entity) (ec.Entity, bool, error)
// AddEntity 添加实体
AddEntity(entity ec.Entity) error
// GetAndRemoveEntity 查询并删除实体
GetAndRemoveEntity(id ec.ID) (ec.Entity, bool)
// GetAndRemoveEntityWithSerialNo 查询并删除实体,同时使用id与serialNo可以在多线程环境中准确定位实体
GetAndRemoveEntityWithSerialNo(id ec.ID, serialNo int64) (ec.Entity, bool)
// RemoveEntity 删除实体
RemoveEntity(id ec.ID)
// RemoveEntityWithSerialNo 删除实体,同时使用id与serialNo可以在多线程环境中准确定位实体
RemoveEntityWithSerialNo(id ec.ID, serialNo int64)
}
IEntityMgr 实体管理器接口
type WithContextOption ¶
type WithContextOption struct{}
WithContextOption 创建服务上下文的所有选项设置器
func (WithContextOption) AutoRecover ¶
func (WithContextOption) AutoRecover(v bool) ContextOption
AutoRecover 是否开启panic时自动恢复
func (WithContextOption) Context ¶
func (WithContextOption) Context(v context.Context) ContextOption
Context 父Context
func (WithContextOption) EntityLib ¶
func (WithContextOption) EntityLib(v pt.EntityLib) ContextOption
EntityLib 实体原型库
func (WithContextOption) GenPersistID ¶
func (WithContextOption) GenPersistID(v func() ec.ID) ContextOption
GenPersistID 生成持久化ID的函数
func (WithContextOption) Inheritor ¶
func (WithContextOption) Inheritor(v util.Face[Context]) ContextOption
Inheritor 继承者,需要扩展服务上下文自身能力时需要使用
func (WithContextOption) PluginBundle ¶
func (WithContextOption) PluginBundle(v plugin.PluginBundle) ContextOption
PluginBundle 插件包
func (WithContextOption) ReportError ¶
func (WithContextOption) ReportError(v chan error) ContextOption
ReportError panic时错误写入的error channel
func (WithContextOption) StartedCallback ¶
func (WithContextOption) StartedCallback(v func(serviceCtx Context)) ContextOption
StartedCallback 启动运行时回调函数
func (WithContextOption) StoppedCallback ¶
func (WithContextOption) StoppedCallback(v func(serviceCtx Context)) ContextOption
StoppedCallback 完全停止运行时回调函数
func (WithContextOption) StoppingCallback ¶
func (WithContextOption) StoppingCallback(v func(serviceCtx Context)) ContextOption
StoppingCallback 开始停止运行时回调函数