service

package
v0.2.57 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 19, 2024 License: LGPL-2.1 Imports: 16 Imported by: 33

Documentation

Overview

Package service 运行时环境提供的一些接口与函数。

  • 服务上下文(context)
  • 并发实体管理器(EntityMgr)

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrContext   = fmt.Errorf("%w: service-context", exception.ErrCore) // 服务上下文错误
	ErrEntityMgr = fmt.Errorf("%w: entity-mgr", ErrContext)             // 实体管理器错误
)
View Source
var With _Option

Functions

func UnsafeContext deprecated

func UnsafeContext(ctx Context) _UnsafeContext

Deprecated: UnsafeContext 访问服务上下文内部方法

Types

type AsyncRet

type AsyncRet = concurrent.AsyncRet // 异步调用结果

type Caller

type Caller interface {
	// Call 查找实体并异步调用函数,有返回值。不会阻塞当前线程,会返回AsyncRet。
	//
	//	注意:
	//	- 代码片段中的线程安全问题,如临界区访问、线程死锁等。
	//  - 调用过程中的panic信息,均会转换为error返回。
	Call(entityId uid.Id, fun generic.FuncVar1[ec.Entity, any, Ret], va ...any) AsyncRet

	// CallDelegate 查找实体并异步调用委托,有返回值。不会阻塞当前线程,会返回AsyncRet。
	//
	//	注意:
	//	- 代码片段中的线程安全问题,如临界区访问、线程死锁等。
	//  - 调用过程中的panic信息,均会转换为error返回。
	CallDelegate(entityId uid.Id, fun generic.DelegateFuncVar1[ec.Entity, any, Ret], va ...any) AsyncRet

	// CallVoid 查找实体并异步调用函数,无返回值。在运行时中。不会阻塞当前线程,会返回AsyncRet。
	//
	//	注意:
	//	- 代码片段中的线程安全问题,如临界区访问、线程死锁等。
	//  - 调用过程中的panic信息,均会转换为error返回。
	CallVoid(entityId uid.Id, fun generic.ActionVar1[ec.Entity, any], va ...any) AsyncRet

	// CallVoidDelegate 查找实体并异步调用委托,无返回值。在运行时中。不会阻塞当前线程,会返回AsyncRet。
	//
	//	注意:
	//	- 代码片段中的线程安全问题,如临界区访问、线程死锁等。
	//  - 调用过程中的panic信息,均会转换为error返回。
	CallVoidDelegate(entityId uid.Id, fun generic.DelegateActionVar1[ec.Entity, any], va ...any) AsyncRet
}

Caller 异步调用发起者

type ConcurrentContextProvider added in v0.2.32

type ConcurrentContextProvider = concurrent.ConcurrentContextProvider // 多线程安全的上下文提供者

type Context

type Context interface {
	concurrent.Context
	reinterpret.CompositeProvider
	Caller
	plugin.PluginProvider
	pt.EntityPTProvider
	fmt.Stringer

	// GetName 获取名称
	GetName() string
	// GetId 获取服务Id
	GetId() uid.Id
	// GetEntityMgr 获取实体管理器
	GetEntityMgr() EntityMgr
	// contains filtered or unexported methods
}

Context 服务上下文

func Current

func Current(ctxProvider ConcurrentContextProvider) Context

Current 获取服务上下文

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 {
	concurrent.ContextBehavior
	// contains filtered or unexported fields
}

ContextBehavior 服务上下文行为,在需要扩展服务上下文能力时,匿名嵌入至服务上下文结构体中

func (*ContextBehavior) Call

func (ctx *ContextBehavior) Call(entityId uid.Id, fun generic.FuncVar1[ec.Entity, any, Ret], va ...any) AsyncRet

Call 查找实体并异步调用函数,有返回值。不会阻塞当前线程,会返回AsyncRet。

	注意:
	- 代码片段中的线程安全问题,如临界区访问、线程死锁等。
 - 调用过程中的panic信息,均会转换为error返回。

func (*ContextBehavior) CallDelegate

func (ctx *ContextBehavior) CallDelegate(entityId uid.Id, fun generic.DelegateFuncVar1[ec.Entity, any, Ret], va ...any) AsyncRet

CallDelegate 查找实体并异步调用委托,有返回值。不会阻塞当前线程,会返回AsyncRet。

	注意:
	- 代码片段中的线程安全问题,如临界区访问、线程死锁等。
 - 调用过程中的panic信息,均会转换为error返回。

func (*ContextBehavior) CallVoid

func (ctx *ContextBehavior) CallVoid(entityId uid.Id, fun generic.ActionVar1[ec.Entity, any], va ...any) AsyncRet

CallVoid 查找实体并异步调用函数,无返回值。在运行时中。不会阻塞当前线程,会返回AsyncRet。

	注意:
	- 代码片段中的线程安全问题,如临界区访问、线程死锁等。
 - 调用过程中的panic信息,均会转换为error返回。

func (*ContextBehavior) CallVoidDelegate

func (ctx *ContextBehavior) CallVoidDelegate(entityId uid.Id, fun generic.DelegateActionVar1[ec.Entity, any], va ...any) AsyncRet

CallVoidDelegate 查找实体并异步调用委托,无返回值。在运行时中。不会阻塞当前线程,会返回AsyncRet。

	注意:
	- 代码片段中的线程安全问题,如临界区访问、线程死锁等。
 - 调用过程中的panic信息,均会转换为error返回。

func (*ContextBehavior) GetCompositeFaceCache added in v0.2.34

func (ctx *ContextBehavior) GetCompositeFaceCache() iface.Cache

GetCompositeFaceCache 支持重新解释类型

func (*ContextBehavior) GetEntityLib

func (ctx *ContextBehavior) GetEntityLib() pt.EntityLib

GetEntityLib 获取实体原型库

func (*ContextBehavior) GetEntityMgr

func (ctx *ContextBehavior) GetEntityMgr() EntityMgr

GetEntityMgr 获取实体管理器

func (*ContextBehavior) GetId

func (ctx *ContextBehavior) GetId() uid.Id

GetId 获取服务Id

func (*ContextBehavior) GetName

func (ctx *ContextBehavior) GetName() string

GetName 获取名称

func (*ContextBehavior) GetPluginBundle

func (ctx *ContextBehavior) GetPluginBundle() plugin.PluginBundle

GetPluginBundle 获取插件包

func (*ContextBehavior) String

func (ctx *ContextBehavior) String() string

String implements fmt.Stringer

type ContextOptions

type ContextOptions struct {
	CompositeFace  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        // 实体原型库
	PluginBundle   plugin.PluginBundle // 插件包
	RunningHandler RunningHandler      // 运行状态变化处理器
}

ContextOptions 创建服务上下文的所有选项

type EntityMgr

type EntityMgr 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)
}

EntityMgr 实体管理器接口

type Ret

type Ret = concurrent.Ret // 调用结果

type RunningHandler

type RunningHandler = generic.DelegateAction2[Context, RunningState] // 运行状态变化处理器

type RunningState

type RunningState int32

RunningState 运行状态

const (
	RunningState_Birth       RunningState = iota // 出生
	RunningState_Starting                        // 开始启动
	RunningState_Started                         // 已启动
	RunningState_Terminating                     // 开始停止
	RunningState_Terminated                      // 已停止
)

func (RunningState) String

func (i RunningState) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL