Documentation
¶
Index ¶
- type AppContext
- type Component
- type EventFn
- type EventInfo
- type FrontendId
- type IAppContext
- type IApplication
- type IComponent
- type IConnector
- type IDiscovery
- type IEvent
- type IExecutor
- type IHandler
- type IMember
- type INetConn
- type INetwork
- type INode
- type IPacket
- type IPacketCodec
- type ISerializer
- type JsonConfig
- type MemberListener
- type MethodInfo
- type OnConnectListener
- type QueueHashFn
- type RPCClient
- type RPCServer
- type SID
- type UID
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) OnAfterInit ¶
func (*Component) OnAfterInit()
func (*Component) OnBeforeStop ¶
func (*Component) OnBeforeStop()
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 ¶
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 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 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 IPacketCodec ¶
type ISerializer ¶
type ISerializer interface {
Marshal(interface{}) ([]byte, error) // 编码
Unmarshal([]byte, interface{}) error // 解码
Name() string // 序列化类型的名称
}
ISerializer 消息序列化
type JsonConfig ¶
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 ¶
type MemberListener func(member IMember) // MemberListener 成员增、删监听函数
type MethodInfo ¶
type MethodInfo struct {
QueueHash QueueHashFn
Type reflect.Type
Value reflect.Value
InArgs []reflect.Type
OutArgs []reflect.Type
IsRaw bool
}
MethodInfo 函数反射信息
type QueueHashFn ¶
QueueHashFn 根据该函数确定IExecutor执行的queue索引
type RPCClient ¶
type RPCClient interface {
Publish(subject string, data []byte) 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()
}
Click to show internal directories.
Click to hide internal directories.