Documentation
¶
Index ¶
- Constants
- Variables
- type Actor
- func (p *Actor) ActorID() string
- func (p *Actor) App() cfacade.IApplication
- func (p *Actor) Child() cfacade.IActorChild
- func (p *Actor) Event() IEvent
- func (p *Actor) Exit()
- func (p *Actor) Invoke(ctx *cfacade.RequestContext, methodID uint32, payload any) *cfacade.InvokeResult
- func (p *Actor) InvokeChild(ctx *cfacade.RequestContext, childID string, methodID uint32, payload any) *cfacade.InvokeResult
- func (p *Actor) LastAt() int64
- func (p *Actor) Methods() IMailBox
- func (p *Actor) Notify(ctx *cfacade.RequestContext, methodID uint32, payload any) *cfacade.InvokeResult
- func (p *Actor) NotifyChild(ctx *cfacade.RequestContext, childID string, methodID uint32, payload any) *cfacade.InvokeResult
- func (p *Actor) Path() *cfacade.ActorPath
- func (p *Actor) PathString() string
- func (p *Actor) PostEvent(data cfacade.IEventData)
- func (p *Actor) State() State
- func (p *Actor) System() *System
- func (p *Actor) Timer() ITimer
- type Base
- func (p *Base) AliasID() string
- func (p *Base) NewChildPath(actorID, childID any) string
- func (p *Base) NewMyChildPath(childID any) string
- func (p *Base) NewNodePath(actorID any) string
- func (p *Base) NewPath(nodeID, actorID any) string
- func (*Base) OnFindChild(_ *cfacade.Message) (cfacade.IActor, bool)
- func (*Base) OnInit()
- func (*Base) OnStop()
- type Component
- type IActorLoader
- type IEvent
- type IEventFunc
- type IMailBox
- type ITimer
- type ITimerSchedule
- type State
- type System
- func (p *System) CreateActor(id string, handler cfacade.IActorHandler) (cfacade.IActor, error)
- func (p *System) GetActor(id string) (*Actor, bool)
- func (p *System) GetActorWithPath(path string) (*Actor, bool)
- func (p *System) GetChildActor(actorID, childID string) (*Actor, bool)
- func (p *System) GetIActor(id string) (cfacade.IActor, bool)
- func (p *System) Invoke(ctx *cfacade.RequestContext, methodID uint32, payload any) *cfacade.InvokeResult
- func (p *System) InvokeNode(ctx *cfacade.RequestContext, nodeID string, methodID uint32, payload any) *cfacade.InvokeResult
- func (p *System) InvokeTarget(ctx *cfacade.RequestContext, target string, methodID uint32, payload any) *cfacade.InvokeResult
- func (p *System) NodeID() string
- func (p *System) Notify(ctx *cfacade.RequestContext, methodID uint32, payload any) *cfacade.InvokeResult
- func (p *System) NotifyNode(ctx *cfacade.RequestContext, nodeID string, methodID uint32, payload any) *cfacade.InvokeResult
- func (p *System) NotifyTarget(ctx *cfacade.RequestContext, target string, methodID uint32, payload any) *cfacade.InvokeResult
- func (p *System) PostEvent(data cfacade.IEventData)
- func (p *System) SetApp(app cfacade.IApplication)
- func (p *System) SetCallTimeout(d time.Duration)
- func (p *System) SetExecutionTimeout(t int64)
- func (p *System) Stop()
Constants ¶
const (
MailName = "mail"
)
Variables ¶
var ( ErrForbiddenCreateChildActor = cerror.Errorf("Forbidden create child actor") ErrActorIDIsNil = cerror.Error("actorID is nil.") )
var (
Name = "actor_component"
)
Functions ¶
This section is empty.
Types ¶
type Actor ¶
type Actor struct {
// contains filtered or unexported fields
}
Actor owns one handler and serializes its mailbox, event, and timer work on the run goroutine. Child messages are routed through their parent first.
func (*Actor) App ¶
func (p *Actor) App() cfacade.IApplication
func (*Actor) Child ¶
func (p *Actor) Child() cfacade.IActorChild
Child returns the dynamic child manager owned by this Actor.
func (*Actor) Exit ¶
func (p *Actor) Exit()
Exit requests an orderly stop after already queued mailbox and event work drains.
func (*Actor) Invoke ¶ added in v1.0.20
func (p *Actor) Invoke(ctx *cfacade.RequestContext, methodID uint32, payload any) *cfacade.InvokeResult
Invoke calls a top-level Actor method on the current node by MethodID.
func (*Actor) InvokeChild ¶ added in v1.0.20
func (p *Actor) InvokeChild(ctx *cfacade.RequestContext, childID string, methodID uint32, payload any) *cfacade.InvokeResult
InvokeChild delivers a typed request to a child Actor mailbox and waits for the result. Unlike posting a child-path message onto the parent mailbox, this never re-queues on the parent, so it is safe to call from a parent handler.
func (*Actor) Methods ¶ added in v1.0.20
Methods returns the Actor method mailbox. Register publishes MethodIDs used by AGP/HTTP/cluster and same-node Actor Invoke/Notify.
func (*Actor) Notify ¶ added in v1.0.20
func (p *Actor) Notify(ctx *cfacade.RequestContext, methodID uint32, payload any) *cfacade.InvokeResult
Notify sends a one-way message to a top-level Actor on the current node.
func (*Actor) NotifyChild ¶ added in v1.0.20
func (p *Actor) NotifyChild(ctx *cfacade.RequestContext, childID string, methodID uint32, payload any) *cfacade.InvokeResult
NotifyChild delivers a one-way typed message to a child Actor mailbox.
func (*Actor) PathString ¶
func (*Actor) PostEvent ¶
func (p *Actor) PostEvent(data cfacade.IEventData)
PostEvent publishes event data through the owning Actor system.
type Base ¶
type Base struct {
*Actor
}
Base provides the runtime Actor handle and default lifecycle hooks for embedding in business Actor handlers.
func (*Base) NewChildPath ¶
NewChildPath builds a child path under another parent on the current node.
func (*Base) NewMyChildPath ¶
NewMyChildPath builds a path for one of the current Actor's children.
func (*Base) NewNodePath ¶
NewNodePath builds a top-level Actor path on the current node.
func (*Base) OnFindChild ¶
OnFindChild 寻找子Actor时触发该函数.开发者可以自定义创建子Actor
type Component ¶
Component integrates the Actor system into the application lifecycle.
func New ¶
func New() *Component
New creates an empty Actor component; handlers may be queued with Add.
func (*Component) Add ¶
func (c *Component) Add(actors ...cfacade.IActorHandler)
Add queues top-level Actor handlers for creation during OnAfterInit.
func (*Component) Init ¶
func (c *Component) Init()
Init attaches the application services required for routing and codecs.
func (*Component) OnAfterInit ¶
func (c *Component) OnAfterInit()
OnAfterInit creates all configured top-level Actors before later components start.
type IActorLoader ¶
type IActorLoader interface {
// contains filtered or unexported methods
}
IActorLoader is implemented by embeddable handler bases that need the runtime Actor reference before OnInit.
type IEvent ¶
type IEvent interface {
Register(name string, fn IEventFunc, uniqueID ...int64) // 注册事件
Registers(names []string, fn IEventFunc, uniqueID ...int64) // 注册多个事件
Unregister(name string) // 注销事件
}
IEvent manages subscriptions owned by one Actor.
type IEventFunc ¶
type IEventFunc func(cfacade.IEventData) // 接收事件数据时的处理函数
IEventFunc handles one event delivery.
type IMailBox ¶
type IMailBox interface {
// Register installs a handler on this Actor mailbox. Top-level Actor
// methods are published for external routing; child methods stay local.
// Registration failures panic (typically during OnInit).
Register(methodID uint32, handler any)
}
IMailBox exposes method registration during an Actor's OnInit hook.
type ITimer ¶
type ITimer interface {
Add(d time.Duration, fn func(), async ...bool) uint64 // 添加定时器,循环执行
AddOnce(d time.Duration, fn func(), async ...bool) uint64 // 添加定时器,执行一次
AddFixedHour(hour, minute, second int, fn func(), async ...bool) uint64 // 固定x小时x分x秒,循环执行
AddFixedMinute(minute, second int, fn func(), async ...bool) uint64 // 固定x分x秒,循环执行
AddSchedule(s ITimerSchedule, f func(), async ...bool) uint64 // 添加自定义调度
Remove(id uint64) // 移除定时器
RemoveAll() // 移除所有定时器
}
ITimer schedules callbacks owned by one Actor.
type ITimerSchedule ¶
ITimerSchedule calculates the next time for a custom recurring timer.
type System ¶
type System struct {
// contains filtered or unexported fields
}
System Actor系统 It owns top-level Actors and provides the common local/remote routing path.
func NewSystem ¶
func NewSystem() *System
NewSystem creates an unbound Actor system with default call and slow-call limits.
func (*System) CreateActor ¶
CreateActor 创建Actor
func (*System) GetActorWithPath ¶
GetActorWithPath resolves either a top-level or child Actor path on this node.
func (*System) GetChildActor ¶
GetChildActor resolves a dynamic child below a top-level Actor.
func (*System) Invoke ¶ added in v1.0.20
func (p *System) Invoke(ctx *cfacade.RequestContext, methodID uint32, payload any) *cfacade.InvokeResult
Invoke calls the local top-level Actor registered for methodID.
func (*System) InvokeNode ¶ added in v1.0.20
func (p *System) InvokeNode(ctx *cfacade.RequestContext, nodeID string, methodID uint32, payload any) *cfacade.InvokeResult
InvokeNode calls methodID on another node. The destination node resolves the top-level Actor from its method table, so callers do not need an ActorPath.
func (*System) InvokeTarget ¶ added in v1.0.20
func (p *System) InvokeTarget(ctx *cfacade.RequestContext, target string, methodID uint32, payload any) *cfacade.InvokeResult
InvokeTarget calls an explicit ActorPath. It is intended for dynamic child Actors; ordinary top-level calls should use Invoke or InvokeNode.
func (*System) Notify ¶ added in v1.0.20
func (p *System) Notify(ctx *cfacade.RequestContext, methodID uint32, payload any) *cfacade.InvokeResult
Notify sends a one-way message to the local top-level Actor registered for methodID.
func (*System) NotifyNode ¶ added in v1.0.20
func (p *System) NotifyNode(ctx *cfacade.RequestContext, nodeID string, methodID uint32, payload any) *cfacade.InvokeResult
NotifyNode sends methodID to another node without exposing its ActorPath.
func (*System) NotifyTarget ¶ added in v1.0.20
func (p *System) NotifyTarget(ctx *cfacade.RequestContext, target string, methodID uint32, payload any) *cfacade.InvokeResult
NotifyTarget sends to an explicit ActorPath and is primarily used by dynamic child Actors.
func (*System) SetApp ¶
func (p *System) SetApp(app cfacade.IApplication)
SetApp binds application routing, codecs, discovery, and cluster services.
func (*System) SetCallTimeout ¶
SetCallTimeout sets the default end-to-end deadline when the caller supplies none.
func (*System) SetExecutionTimeout ¶
SetExecutionTimeout sets the slow-handler warning threshold in milliseconds.