cherryFacade

package
v1.1.30 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2022 License: MIT Imports: 6 Imported by: 59

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AppContext

type AppContext struct {
	IApplication
}

AppContext 继承自IApplication实现默认的方法

func (*AppContext) App

func (b *AppContext) App() IApplication

func (*AppContext) Set

func (b *AppContext) Set(app IApplication)

type Component

type Component struct {
	AppContext
}

Component base component

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

type EventFn

type EventFn func(e IEvent)

EventFn 事件注册函数

type EventInfo added in v1.1.30

type EventInfo struct {
	QueueHash QueueHashFn
	List      []EventFn
}

EventInfo 事件注册信息

type FrontendId

type FrontendId = string // 前端节点id

type IAppContext

type IAppContext interface {
	Set(app IApplication)
	App() IApplication
}

IAppContext App上下文

type IApplication

type IApplication interface {
	INode
	ISerializer
	IPacketCodec
	Running() bool                    // 是否运行中
	DieChan() chan bool               // die chan
	IsFrontend() bool                 // 是否为前端节点
	Find(name string) IComponent      // 根据name获取组件对象
	Remove(name string) IComponent    // 根据name移除组件对象
	All() []IComponent                // 获取所有组件列表
	OnShutdown(fn ...func())          // 关闭前执行的函数
	Startup(components ...IComponent) // 启动应用实例
	Shutdown()                        // 关闭应用实例
}

type IComponent

type IComponent interface {
	IAppContext
	Name() string
	Init()
	OnAfterInit()
	OnBeforeStop()
	OnStop()
}

type IConnector

type IConnector interface {
	IComponent
	OnStart()
	OnStop()
	OnConnectListener(listener ...OnConnectListener)
	IsSetListener() bool
	GetConnChan() chan INetConn
}

IConnector 网络连接器接口

type IDiscovery added in v1.1.5

type IDiscovery interface {
	Name() string                                                 // 发现服务名称
	Init(app IApplication)                                        // 初始化函数
	List() []IMember                                              // 获取成员列表
	ListByType(nodeType string, filterNodeId ...string) []IMember // 根据节点类型获取列表
	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)                       // 移除成员监听函数
	OnStop()                                                      // 停止当前发现服务
}

IDiscovery 节点发现接口

type IEvent

type IEvent interface {
	Name() string    // 事件名称
	UniqueId() int64 // 事件唯一id
}

IEvent 事件接口

type IExecutor

type IExecutor interface {
	QueueHash(queueNum int) int // get hash index by queue num
	SetIndex(index int)         // set queue index
	Invoke()                    // invoke method
}

IExecutor 执行者

type IHandler

type IHandler interface {
	IAppContext                                        // 应用实例上线文
	Name() string                                      // handler名称(用于消息路由)
	SetName(name string)                               // 设置handler名称
	OnPreInit()                                        // 预初始化方法(对象实例化前)
	OnInit()                                           // 初始方法(PreInit之后)
	OnAfterInit()                                      // 最后的初始化方法(Init之后)
	OnStop()                                           // 停止handler运行
	Events() map[string]*EventInfo                     // 已注册的事件列表
	Event(name string) (*EventInfo, bool)              // 根据事件名获取事件列表
	LocalHandlers() map[string]*MethodInfo             // 已注册的本地handler列表(网络消息的逻辑处理函数)
	LocalHandler(funcName string) (*MethodInfo, bool)  // 根据handler名称获取本地handler
	RemoteHandlers() map[string]*MethodInfo            // 已注册的远程handler列表(内部rpc调用的逻辑处理函数)
	RemoteHandler(funcName string) (*MethodInfo, bool) // 根据handler名称获取远程handler
}

IHandler 消息处理句柄接口,用于包装消息处理逻辑

type IMember added in v1.1.5

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

type INetConn

type INetConn interface {
	net.Conn
	GetNextMessage() (b []byte, err error)
}

type INetwork

type INetwork interface {
	SendRaw(bytes []byte)                                                        // write raw data to client
	RPC(nodeId string, route string, req proto.Message, rsp proto.Message) int32 // 调用remote rpc
	Response(mid uint, val interface{}, isError ...bool)                         // 回复消息到客户端
	Push(route string, val interface{})                                          // 推送消息对客户端
	Kick(reason interface{})                                                     // 踢下线
	RemoteAddr() string                                                          // 连接者的地址信息
	Close()                                                                      // 关闭接口
}

INetwork 网络处理接口

type INode

type INode interface {
	NodeId() string       // 节点id(全局唯一)
	NodeType() string     // 节点类型
	Address() string      // 对外网络监听地址
	RpcAddress() string   // rpc监听地址
	Settings() JsonConfig // 节点配置参数
	Enabled() bool        // 是否启用
}

INode 节点信息

type IPacket

type IPacket interface {
	Type() byte
	Len() int
	Data() []byte
	SetData([]byte)
}

type IPacketCodec

type IPacketCodec interface {
	PacketDecode(data []byte) ([]IPacket, error)
	PacketEncode(typ byte, data []byte) ([]byte, error)
}

type ISerializer

type ISerializer interface {
	Marshal(interface{}) ([]byte, error) // 编码
	Unmarshal([]byte, interface{}) error // 解码
	Name() string                        // 序列化类型的名称
}

ISerializer 消息序列化

type JsonConfig added in v1.1.29

type JsonConfig interface {
	jsoniter.Any
	GetConfig(path ...interface{}) JsonConfig
	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
	GetJsonObject(path interface{}, ptrVal interface{}) error
}

type MemberListener added in v1.1.5

type MemberListener func(member IMember) // MemberListener 成员增、删监听函数

type MethodInfo added in v1.1.30

type MethodInfo struct {
	QueueHash QueueHashFn
	Type      reflect.Type
	Value     reflect.Value
	InArgs    []reflect.Type
	OutArgs   []reflect.Type
	IsRaw     bool
}

MethodInfo 函数反射信息

type OnConnectListener

type OnConnectListener func(conn INetConn)

OnConnectListener 建立连接时监听的函数

type QueueHashFn added in v1.1.30

type QueueHashFn func(e IExecutor, queueNum int) int

QueueHashFn 根据该函数确定IExecutor执行的queue索引

type RPCClient added in v1.1.17

type RPCClient interface {
	Publish(subject string, val interface{}) error                                                            //发布消息给目标节点
	PublishPush(frontendId FrontendId, push *cproto.Push) error                                               //发布推送给前端节点
	PublishKick(nodeId string, kick *cproto.Kick) error                                                       //发布踢人给前端节点
	PublishLocal(nodeId string, request *cproto.Request) error                                                //发布本地消息
	PublishRemote(nodeId string, request *cproto.Request) error                                               //发布远程消息
	RequestRemote(nodeId string, request *cproto.Request, timeout ...time.Duration) (*cproto.Response, error) //请求远程消息
	OnStop()
}

type RPCServer added in v1.1.17

type RPCServer interface {
	OnStop()
}

type SID

type SID = string // session unique id

type UID

type UID = int64 // 用户唯一id user unique id

Jump to

Keyboard shortcuts

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