cherryFacade

package
v1.3.12 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2023 License: MIT Imports: 10 Imported by: 25

Documentation

Index

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

func NewPath added in v1.3.0

func NewPath(nodeID, actorID interface{}) string

Types

type ActorPath added in v1.3.0

type ActorPath struct {
	NodeID  string
	ActorID string
	ChildID string
}

ActorPath = NodeID . ActorID ActorPath = NodeID . ActorID . ChildID

func NewActorPath added in v1.3.0

func NewActorPath(nodeID, actorID, childID string) *ActorPath

func ToActorPath added in v1.3.0

func ToActorPath(path string) (*ActorPath, error)

func (*ActorPath) IsChild added in v1.3.0

func (p *ActorPath) IsChild() bool

func (*ActorPath) IsParent added in v1.3.0

func (p *ActorPath) IsParent() bool

func (*ActorPath) String added in v1.3.0

func (p *ActorPath) String() string

String

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

func (*Component) Init()

func (*Component) Name

func (*Component) Name() string

func (*Component) OnAfterInit

func (*Component) OnAfterInit()

func (*Component) OnBeforeStop

func (*Component) OnBeforeStop()

func (*Component) OnStop

func (*Component) OnStop()

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 interface{}) int32
	CallWait(targetPath, funcName string, arg interface{}, reply interface{}) 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
}

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 interface{}) int32
	CallWait(source, target, funcName string, arg interface{}, reply interface{}) 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                                     // 发布远程消息
	RequestRemote(nodeId string, packet *cproto.ClusterPacket, timeout ...time.Duration) cproto.Response // 请求远程消息
	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 IEventData interface {
	Name() string    // 事件名
	UniqueId() int64 // 唯一id
}

type IMember added in v1.1.5

type IMember interface {
	GetNodeId() string
	GetNodeType() string
	GetAddress() string
	GetSettings() map[string]string
}

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 IRespond added in v1.3.0

type IRespond interface {
	Respond(data []byte) error
}

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{}      // 请求的参数
	Err          error            // 返回的错误
	ClusterReply IRespond         // 返回消息的接口
	IsCluster    bool             // 是否为集群消息
	ChanResult   chan interface{} //
	// contains filtered or unexported fields
}

func BuildMessage added in v1.3.6

func BuildMessage(source, target, funcName string, arg interface{}) *Message

func GetMessage added in v1.3.0

func GetMessage() *Message

func (*Message) IsReply added in v1.3.0

func (p *Message) IsReply() bool

func (*Message) Recycle added in v1.3.0

func (p *Message) Recycle()

func (*Message) TargetPath added in v1.3.0

func (p *Message) TargetPath() *ActorPath

type OnConnectFunc added in v1.3.0

type OnConnectFunc func(conn net.Conn)

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配置文件读取接口

type SID

type SID = string // session unique id

type UID

type UID = int64 // user unique id

Jump to

Keyboard shortcuts

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