cactor

package
v1.0.20 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MailName = "mail"
)

Variables

View Source
var (
	ErrForbiddenCreateChildActor = cerror.Errorf("Forbidden create child actor")
	ErrActorIDIsNil              = cerror.Error("actorID is nil.")
)
View Source
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) ActorID

func (p *Actor) ActorID() string

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) Event

func (p *Actor) Event() IEvent

Event returns this Actor's event subscription API.

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) LastAt

func (p *Actor) LastAt() int64

LastAt second

func (*Actor) Methods added in v1.0.20

func (p *Actor) Methods() IMailBox

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) Path

func (p *Actor) Path() *cfacade.ActorPath

func (*Actor) PathString

func (p *Actor) PathString() string

func (*Actor) PostEvent

func (p *Actor) PostEvent(data cfacade.IEventData)

PostEvent publishes event data through the owning Actor system.

func (*Actor) State

func (p *Actor) State() State

State returns the current lifecycle state.

func (*Actor) System

func (p *Actor) System() *System

System returns the Actor system that owns this Actor.

func (*Actor) Timer

func (p *Actor) Timer() ITimer

Timer returns this Actor's timer scheduler.

type Base

type Base struct {
	*Actor
}

Base provides the runtime Actor handle and default lifecycle hooks for embedding in business Actor handlers.

func (*Base) AliasID

func (p *Base) AliasID() string

func (*Base) NewChildPath

func (p *Base) NewChildPath(actorID, childID any) string

NewChildPath builds a child path under another parent on the current node.

func (*Base) NewMyChildPath

func (p *Base) NewMyChildPath(childID any) string

NewMyChildPath builds a path for one of the current Actor's children.

func (*Base) NewNodePath

func (p *Base) NewNodePath(actorID any) string

NewNodePath builds a top-level Actor path on the current node.

func (*Base) NewPath

func (p *Base) NewPath(nodeID, actorID any) string

NewPath builds a top-level Actor path for an explicit node.

func (*Base) OnFindChild

func (*Base) OnFindChild(_ *cfacade.Message) (cfacade.IActor, bool)

OnFindChild 寻找子Actor时触发该函数.开发者可以自定义创建子Actor

func (*Base) OnInit

func (*Base) OnInit()

OnInit Actor初始化前触发该函数

func (*Base) OnStop

func (*Base) OnStop()

OnStop Actor停止前触发该函数

type Component

type Component struct {
	cfacade.Component
	*System
	// contains filtered or unexported fields
}

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) Name

func (c *Component) Name() string

func (*Component) OnAfterInit

func (c *Component) OnAfterInit()

OnAfterInit creates all configured top-level Actors before later components start.

func (*Component) OnStop

func (c *Component) OnStop()

OnStop drains and stops every Actor owned by the system.

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

type ITimerSchedule interface {
	Next(time.Time) time.Time
}

ITimerSchedule calculates the next time for a custom recurring timer.

type State

type State int
var (
	InitState   State = 0
	WorkerState State = 1
	StopState   State = 2
)

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

func (p *System) CreateActor(id string, handler cfacade.IActorHandler) (cfacade.IActor, error)

CreateActor 创建Actor

func (*System) GetActor

func (p *System) GetActor(id string) (*Actor, bool)

GetActor 根据ActorID获取*actor

func (*System) GetActorWithPath

func (p *System) GetActorWithPath(path string) (*Actor, bool)

GetActorWithPath resolves either a top-level or child Actor path on this node.

func (*System) GetChildActor

func (p *System) GetChildActor(actorID, childID string) (*Actor, bool)

GetChildActor resolves a dynamic child below a top-level Actor.

func (*System) GetIActor

func (p *System) GetIActor(id string) (cfacade.IActor, bool)

GetIActor 根据ActorID获取IActor

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) NodeID

func (p *System) NodeID() string

NodeID returns the bound application node ID.

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) PostEvent

func (p *System) PostEvent(data cfacade.IEventData)

PostEvent 提交事件

func (*System) SetApp

func (p *System) SetApp(app cfacade.IApplication)

SetApp binds application routing, codecs, discovery, and cluster services.

func (*System) SetCallTimeout

func (p *System) SetCallTimeout(d time.Duration)

SetCallTimeout sets the default end-to-end deadline when the caller supplies none.

func (*System) SetExecutionTimeout

func (p *System) SetExecutionTimeout(t int64)

SetExecutionTimeout sets the slow-handler warning threshold in milliseconds.

func (*System) Stop

func (p *System) Stop()

Stop asks every top-level Actor to exit and waits for all parent and child loops.

Jump to

Keyboard shortcuts

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