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 IComponent
- type IComponentLifecycle
- type IConnector
- type IDiscovery
- 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
ActorPath = NodeID . ActorID ActorPath = NodeID . ActorID . ChildID
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 {
Init() // 初始化
PublishLocal(nodeID string, packet *cproto.ClusterPacket) error // 发布本地消息
PublishRemote(nodeID string, packet *cproto.ClusterPacket) error // 发布远程消息
PublishRemoteType(nodeType string, cpacket *cproto.ClusterPacket) error // 根据节点类型发布远程消息
RequestRemote(nodeID string, packet *cproto.ClusterPacket, timeout ...time.Duration) ([]byte, int32) // 请求远程消息
Stop() // 停止
}
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 {
Load(app IApplication)
Name() string // 发现服务名称
Map() map[string]IMember // 获取成员列表
ListByType(nodeType string, filterNodeID ...string) []IMember // 根据节点类型获取列表
Random(nodeType string) (IMember, bool) // 根据节点类型随机一个
GetType(nodeID string) (nodeType string, err error) // 根据节点id获取类型
GetMember(nodeID string) (member IMember, found bool) // 获取成员
AddMember(member IMember) // 添加成员
RemoveMember(nodeID string) // 移除成员
OnAddMember(listener MemberListener) // 添加成员监听函数
OnRemoveMember(listener MemberListener) // 移除成员监听函数
Stop()
}
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) // MemberListener 成员增、删监听函数
type Message ¶ added in v1.3.0
type Message struct {
BuildTime int64 // message build time(ms)
PostTime int64 // post to actor time(ms)
Source string // 来源actor path
Target string // 目标actor path
FuncName string // 请求调用的函数名
Session *cproto.Session // session of gateway
Args interface{} // 请求的参数
Header nats.Header // nats.Msg Header
Reply string // nats.Msg reply subject
IsCluster bool // 是否为集群消息
ChanResult chan interface{} //
// contains filtered or unexported fields
}
func BuildClusterMessage ¶ added in v1.4.4
func BuildClusterMessage(packet *cproto.ClusterPacket) Message
func GetMessage ¶ added in v1.3.0
func GetMessage() Message
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配置文件读取接口
Click to show internal directories.
Click to hide internal directories.