Documentation
¶
Index ¶
- func NewChildPath(nodeID, actorID, childID interface{}) string
- func NewPath(nodeID, actorID interface{}) string
- type ActorPath
- type Component
- type IActor
- type IActorChild
- type IActorHandler
- type IActorSystem
- type IApplication
- type ICluster
- type IClusterComponent
- type IComponent
- type IComponentLifecycle
- type IConnector
- type IDiscovery
- type IDiscoveryComponent
- type IEventData
- type IMember
- type INetParser
- type INode
- type ISerializer
- type InvokeFunc
- type MemberListener
- type Message
- type OnConnectFunc
- type ProfileJSON
- type SID
- type UID
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewChildPath ¶ added in v1.3.1
func NewChildPath(nodeID, actorID, childID interface{}) string
Types ¶
type ActorPath ¶ added in v1.3.0
func NewActorPath ¶ added in v1.3.0
func ToActorPath ¶ added in v1.3.0
type Component ¶
type Component struct {
// contains filtered or unexported fields
}
Component base component
func (*Component) App ¶ added in v1.3.0
func (p *Component) App() IApplication
func (*Component) OnAfterInit ¶
func (*Component) OnAfterInit()
func (*Component) OnBeforeStop ¶
func (*Component) OnBeforeStop()
func (*Component) Set ¶ added in v1.3.0
func (p *Component) Set(app IApplication)
type IActor ¶ added in v1.3.0
type IActor interface {
App() IApplication
ActorID() string
Path() *ActorPath
Call(targetPath, funcName string, arg any) int32
CallWait(targetPath, funcName string, arg, reply any) int32
CallType(nodeType, actorID, funcName string, arg any) int32
PostRemote(m *Message)
PostLocal(m *Message)
LastAt() int64
Exit()
}
type IActorChild ¶ added in v1.3.0
type IActorChild interface {
Create(id string, handler IActorHandler) (IActor, error) // 创建子Actor
Get(id string) (IActor, bool) // 获取子Actor
Remove(id string) // 称除子Actor
Each(fn func(i IActor)) // 遍历所有子Actor
Call(childID, funcName string, arg any) // 调用当前子actor的函数
CallWait(targetPath, funcName string, arg, reply any) int32 // 调用当前子actor的函数并等待返回
}
type IActorHandler ¶ added in v1.3.0
type IActorHandler interface {
AliasID() string // actorID
OnInit() // 当Actor启动前触发该函数
OnStop() // 当Actor停止前触发该函数
OnLocalReceived(m *Message) (bool, bool) // 当Actor接收local消息时触发该函数
OnRemoteReceived(m *Message) (bool, bool) // 当Actor接收remote消息时执行的函数
OnFindChild(m *Message) (IActor, bool) // 当actor查找子Actor时触发该函数
}
type IActorSystem ¶ added in v1.3.0
type IActorSystem interface {
GetIActor(id string) (IActor, bool)
CreateActor(id string, handler IActorHandler) (IActor, error)
PostRemote(m *Message) bool
PostLocal(m *Message) bool
PostEvent(data IEventData)
Call(source, target, funcName string, arg any) int32
CallWait(source, target, funcName string, arg, reply any) int32
CallType(nodeType, actorID, funcName string, arg any) int32
SetLocalInvoke(invoke InvokeFunc)
SetRemoteInvoke(invoke InvokeFunc)
SetCallTimeout(d time.Duration)
SetArrivalTimeout(t int64)
SetExecutionTimeout(t int64)
}
type IApplication ¶
type IApplication interface {
INode
Running() bool // 是否运行中
DieChan() chan bool // die chan
IsFrontend() bool // 是否为前端节点
Register(components ...IComponent) // 注册组件
Find(name string) IComponent // 根据name获取组件对象
Remove(name string) IComponent // 根据name移除组件对象
All() []IComponent // 获取所有组件列表
OnShutdown(fn ...func()) // 关闭前执行的函数
Startup() // 启动应用实例
Shutdown() // 关闭应用实例
Serializer() ISerializer // 序列化
Discovery() IDiscovery // 发现服务
Cluster() ICluster // 集群服务
ActorSystem() IActorSystem // actor系统
}
type ICluster ¶ added in v1.3.0
type ICluster interface {
Mode() string // cluster implement mode
PublishLocal(nodeID string, msg *Message) error // publish local message
PublishRemote(nodeID string, msg *Message) error // publish remote message
PublishRemoteType(nodeType string, msg *Message) error // publish remote message by node type
RequestRemote(nodeID string, msg *Message, timeout ...time.Duration) ([]byte, int32) // request remote message
}
type IClusterComponent ¶ added in v1.5.0
type IClusterComponent interface {
IComponent
ICluster
}
type IComponent ¶
type IComponent interface {
Name() string
App() IApplication
IComponentLifecycle
}
type IComponentLifecycle ¶ added in v1.3.0
type IComponentLifecycle interface {
Set(app IApplication)
Init()
OnAfterInit()
OnBeforeStop()
OnStop()
}
type IConnector ¶
type IConnector interface {
IComponent
Start() // 启动连接器
Stop() // 停止连接器
OnConnect(fn OnConnectFunc) // 建立新连接时触发的函数
}
IConnector 网络连接器接口
type IDiscovery ¶ added in v1.1.5
type IDiscovery interface {
Mode() string //
Map() map[string]IMember // get member list
ListByType(nodeType string, filterNodeID ...string) []IMember // get member list by node type
Random(nodeType string) (IMember, bool) // random member by node type
GetType(nodeID string) (nodeType string, err error) // get node type by node id
GetMember(nodeID string) (member IMember, found bool) // get member
AddMember(member IMember) // add member
RemoveMember(nodeID string) // remove member
OnAddMember(listener MemberListener) // add member listener
OnRemoveMember(listener MemberListener) // remove member listener
}
IDiscovery discovery service interface
type IDiscoveryComponent ¶ added in v1.5.0
type IDiscoveryComponent interface {
IComponent
IDiscovery
}
type IEventData ¶ added in v1.3.0
type INetParser ¶ added in v1.3.0
type INetParser interface {
Load(application IApplication)
AddConnector(connector IConnector)
Connectors() []IConnector
}
INetParser 前端网络数据包解析器
type INode ¶
type INode interface {
NodeID() string // 节点id(全局唯一)
NodeType() string // 节点类型
Address() string // 对外网络监听地址(前端节点用)
RpcAddress() string // rpc监听地址(未用)
Settings() ProfileJSON // 节点配置参数
Enabled() bool // 是否启用
}
INode 节点信息
type ISerializer ¶
type ISerializer interface {
Marshal(interface{}) ([]byte, error) // 编码
Unmarshal([]byte, interface{}) error // 解码
Name() string // 序列化类型的名称
}
ISerializer 消息序列化
type InvokeFunc ¶ added in v1.3.0
type InvokeFunc func(app IApplication, fi *creflect.FuncInfo, m *Message)
type MemberListener ¶ added in v1.1.5
type MemberListener func(member IMember) // member add/remove listener
type Message ¶ added in v1.3.0
type Message struct {
BuildTime int64 // message build time(ms)
Source string // source actor path
Target string // target actor path (node.actor or node.actor.child)
FuncName string // target function name
Args interface{} // payload: same-node=decoded object, cross-node=[]byte (pending decode)
// --- Local only (client->Actor, set by parser) ---
Session *cproto.Session // client session
// --- Remote only (Actor->Actor, set by System.Call/CallWait/CallType) ---
ReqID string // NATS request ID (cross-node request-reply)
Reply string // NATS reply subject (non-empty if from cross-node)
ChanResult chan interface{} // same-node CallWait sync channel
// contains filtered or unexported fields
}
Message is the in-process message carrier for the Actor system. For cross-process transfer, use Marshal/Unmarshal which internally uses ClusterPacket proto.
Field groups:
Common: BuildTime, Source, Target, FuncName, Args Local (client->Actor, set by parser): Session Remote (Actor->Actor, set by System.Call/CallWait/CallType): ReqID, Reply, ChanResult
func GetMessage ¶ added in v1.3.0
func GetMessage() *Message
func (*Message) AddRef ¶ added in v1.5.2
func (p *Message) AddRef()
AddRef increments the reference count. Each call to PostLocal/PostRemote adds a reference that will be released by the receiving actor's Recycle.
func (*Message) Clone ¶ added in v1.5.2
Clone creates a shallow copy for child Actor forwarding. Session, Args and ChanResult are intentionally shared.
func (*Message) Marshal ¶ added in v1.5.2
Marshal serializes Message for cross-process transfer via NATS. Internally uses ClusterPacket proto as the wire format.
func (*Message) TargetPath ¶ added in v1.3.0
type OnConnectFunc ¶ added in v1.3.0
OnConnectFunc 建立连接时监听的函数
type ProfileJSON ¶ added in v1.3.0
type ProfileJSON interface {
jsoniter.Any
GetConfig(path ...interface{}) ProfileJSON
GetString(path interface{}, defaultVal ...string) string
GetBool(path interface{}, defaultVal ...bool) bool
GetInt(path interface{}, defaultVal ...int) int
GetInt32(path interface{}, defaultVal ...int32) int32
GetInt64(path interface{}, defaultVal ...int64) int64
GetDuration(path interface{}, defaultVal ...time.Duration) time.Duration
Unmarshal(ptrVal interface{}) error
}
ProfileJSON profile配置文件读取接口