Documentation
¶
Overview ¶
Package service 为服务环境提供的一些接口与函数。
- 服务上下文(context)
- 并发实体管理器(EntityManager)
Index ¶
- Variables
- func UnsafeContext(ctx Context) _UnsafeContextdeprecated
- type Caller
- type Context
- type ContextBehavior
- func (ctx *ContextBehavior) CallAsync(entityId uid.Id, fun generic.FuncVar1[ec.Entity, any, async.Ret], args ...any) async.AsyncRet
- func (ctx *ContextBehavior) CallDelegateAsync(entityId uid.Id, fun generic.DelegateVar1[ec.Entity, any, async.Ret], ...) async.AsyncRet
- func (ctx *ContextBehavior) CallDelegateVoidAsync(entityId uid.Id, fun generic.DelegateVoidVar1[ec.Entity, any], args ...any) async.AsyncRet
- func (ctx *ContextBehavior) CallVoidAsync(entityId uid.Id, fun generic.ActionVar1[ec.Entity, any], args ...any) async.AsyncRet
- func (ctx *ContextBehavior) GetAddInManager() extension.AddInManager
- func (ctx *ContextBehavior) GetEntityLib() pt.EntityLib
- func (ctx *ContextBehavior) GetEntityManager() EntityManager
- func (ctx *ContextBehavior) GetId() uid.Id
- func (ctx *ContextBehavior) GetInstanceFaceCache() iface.Cache
- func (ctx *ContextBehavior) GetName() string
- func (ctx *ContextBehavior) GetReflected() reflect.Value
- func (ctx *ContextBehavior) String() string
- type ContextOptions
- type EntityManager
- type RunningStatus
- type RunningStatusChangedCB
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrContext = fmt.Errorf("%w: service-context", exception.ErrCore) // 服务上下文错误 ErrEntityManager = fmt.Errorf("%w: entity-manager", ErrContext) // 实体管理器错误 )
View Source
var With _Option
Functions ¶
func UnsafeContext
deprecated
func UnsafeContext(ctx Context) _UnsafeContext
Deprecated: UnsafeContext 访问服务上下文内部方法
Types ¶
type Caller ¶
type Caller interface {
// CallAsync 查找实体并异步调用函数,有返回值。不会阻塞当前线程,会返回AsyncRet。
//
// 注意:
// - 代码片段中的线程安全问题,如临界区访问、线程死锁等。
// - 调用过程中的panic信息,均会转换为error返回。
CallAsync(entityId uid.Id, fun generic.FuncVar1[ec.Entity, any, async.Ret], args ...any) async.AsyncRet
// CallDelegateAsync 查找实体并异步调用委托,有返回值。不会阻塞当前线程,会返回AsyncRet。
//
// 注意:
// - 代码片段中的线程安全问题,如临界区访问、线程死锁等。
// - 调用过程中的panic信息,均会转换为error返回。
CallDelegateAsync(entityId uid.Id, fun generic.DelegateVar1[ec.Entity, any, async.Ret], args ...any) async.AsyncRet
// CallVoidAsync 查找实体并异步调用函数,无返回值。在运行时中。不会阻塞当前线程,会返回AsyncRet。
//
// 注意:
// - 代码片段中的线程安全问题,如临界区访问、线程死锁等。
// - 调用过程中的panic信息,均会转换为error返回。
CallVoidAsync(entityId uid.Id, fun generic.ActionVar1[ec.Entity, any], args ...any) async.AsyncRet
// CallDelegateVoidAsync 查找实体并异步调用委托,无返回值。在运行时中。不会阻塞当前线程,会返回AsyncRet。
//
// 注意:
// - 代码片段中的线程安全问题,如临界区访问、线程死锁等。
// - 调用过程中的panic信息,均会转换为error返回。
CallDelegateVoidAsync(entityId uid.Id, fun generic.DelegateVoidVar1[ec.Entity, any], args ...any) async.AsyncRet
}
Caller 异步调用发起者
type Context ¶
type Context interface {
ictx.Context
reinterpret.InstanceProvider
extension.AddInProvider
pt.EntityPTProvider
Caller
fmt.Stringer
// GetName 获取名称
GetName() string
// GetId 获取服务Id
GetId() uid.Id
// GetReflected 获取反射值
GetReflected() reflect.Value
// GetEntityManager 获取实体管理器
GetEntityManager() EntityManager
// contains filtered or unexported methods
}
Context 服务上下文
func NewContext ¶
func NewContext(settings ...option.Setting[ContextOptions]) Context
NewContext 创建服务上下文
func UnsafeNewContext
deprecated
func UnsafeNewContext(options ContextOptions) Context
Deprecated: UnsafeNewContext 内部创建服务上下文
type ContextBehavior ¶
type ContextBehavior struct {
ictx.ContextBehavior
// contains filtered or unexported fields
}
ContextBehavior 服务上下文行为,在扩展服务上下文能力时,匿名嵌入至服务上下文结构体中
func (*ContextBehavior) CallAsync ¶ added in v0.3.89
func (ctx *ContextBehavior) CallAsync(entityId uid.Id, fun generic.FuncVar1[ec.Entity, any, async.Ret], args ...any) async.AsyncRet
CallAsync 查找实体并异步调用函数,有返回值。不会阻塞当前线程,会返回AsyncRet。
注意: - 代码片段中的线程安全问题,如临界区访问、线程死锁等。 - 调用过程中的panic信息,均会转换为error返回。
func (*ContextBehavior) CallDelegateAsync ¶ added in v0.3.89
func (ctx *ContextBehavior) CallDelegateAsync(entityId uid.Id, fun generic.DelegateVar1[ec.Entity, any, async.Ret], args ...any) async.AsyncRet
CallDelegateAsync 查找实体并异步调用委托,有返回值。不会阻塞当前线程,会返回AsyncRet。
注意: - 代码片段中的线程安全问题,如临界区访问、线程死锁等。 - 调用过程中的panic信息,均会转换为error返回。
func (*ContextBehavior) CallDelegateVoidAsync ¶ added in v0.3.89
func (ctx *ContextBehavior) CallDelegateVoidAsync(entityId uid.Id, fun generic.DelegateVoidVar1[ec.Entity, any], args ...any) async.AsyncRet
CallDelegateVoidAsync 查找实体并异步调用委托,无返回值。在运行时中。不会阻塞当前线程,会返回AsyncRet。
注意: - 代码片段中的线程安全问题,如临界区访问、线程死锁等。 - 调用过程中的panic信息,均会转换为error返回。
func (*ContextBehavior) CallVoidAsync ¶ added in v0.3.89
func (ctx *ContextBehavior) CallVoidAsync(entityId uid.Id, fun generic.ActionVar1[ec.Entity, any], args ...any) async.AsyncRet
CallVoidAsync 查找实体并异步调用函数,无返回值。在运行时中。不会阻塞当前线程,会返回AsyncRet。
注意: - 代码片段中的线程安全问题,如临界区访问、线程死锁等。 - 调用过程中的panic信息,均会转换为error返回。
func (*ContextBehavior) GetAddInManager ¶ added in v0.3.66
func (ctx *ContextBehavior) GetAddInManager() extension.AddInManager
GetAddInManager 获取插件管理器
func (*ContextBehavior) GetEntityLib ¶
func (ctx *ContextBehavior) GetEntityLib() pt.EntityLib
GetEntityLib 获取实体原型库
func (*ContextBehavior) GetEntityManager ¶ added in v0.3.66
func (ctx *ContextBehavior) GetEntityManager() EntityManager
GetEntityManager 获取实体管理器
func (*ContextBehavior) GetInstanceFaceCache ¶ added in v0.3.34
func (ctx *ContextBehavior) GetInstanceFaceCache() iface.Cache
GetInstanceFaceCache 支持重新解释类型
func (*ContextBehavior) GetReflected ¶ added in v0.2.58
func (ctx *ContextBehavior) GetReflected() reflect.Value
GetReflected 获取反射值
func (*ContextBehavior) String ¶
func (ctx *ContextBehavior) String() string
String implements fmt.Stringer
type ContextOptions ¶
type ContextOptions struct {
InstanceFace iface.Face[Context] // 实例,用于扩展服务上下文能力
Context context.Context // 父Context
AutoRecover bool // 是否开启panic时自动恢复
ReportError chan error // panic时错误写入的error channel
Name string // 服务名称
PersistId uid.Id // 服务持久化Id
EntityLib pt.EntityLib // 实体原型库
AddInManager extension.AddInManager // 插件管理器
RunningStatusChangedCB RunningStatusChangedCB // 运行状态变化回调
}
ContextOptions 创建服务上下文的所有选项
type EntityManager ¶ added in v0.3.66
type EntityManager interface {
// GetContext 获取服务上下文
GetContext() Context
// GetEntity 查询实体
GetEntity(id uid.Id) (ec.ConcurrentEntity, bool)
// GetOrAddEntity 查询或添加实体
GetOrAddEntity(entity ec.ConcurrentEntity) (ec.ConcurrentEntity, bool, error)
// AddEntity 添加实体
AddEntity(entity ec.ConcurrentEntity) error
// GetAndRemoveEntity 查询并删除实体
GetAndRemoveEntity(id uid.Id) (ec.ConcurrentEntity, bool)
// RemoveEntity 删除实体
RemoveEntity(id uid.Id)
}
EntityManager 实体管理器接口
type RunningStatus ¶ added in v0.3.70
type RunningStatus int32
RunningStatus 运行状态
const ( RunningStatus_Birth RunningStatus = iota // 出生 RunningStatus_Starting // 开始启动 RunningStatus_Started // 已启动 RunningStatus_Terminating // 开始停止 RunningStatus_Terminated // 已停止 RunningStatus_ActivatingAddIn // 开始激活插件 RunningStatus_AddInActivated // 插件已激活 RunningStatus_DeactivatingAddIn // 开始去激活插件 RunningStatus_AddInDeactivated // 插件已去激活 RunningStatus_EntityPTDeclared // 实体原型已声明 RunningStatus_EntityPTRedeclared // 实体原型已重声明 RunningStatus_EntityPTUndeclared // 实体原型已取消声明 )
func (RunningStatus) String ¶ added in v0.3.70
func (i RunningStatus) String() string
type RunningStatusChangedCB ¶ added in v0.4.0
type RunningStatusChangedCB = generic.ActionVar2[Context, RunningStatus, any] // 运行状态变化回调
Click to show internal directories.
Click to hide internal directories.