service

package
v0.0.0-...-0012533 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2023 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SrvSetEntities

func SrvSetEntities(v *entity.Entities) optionF

初始化对象管理器

func SrvSetNetSrv

func SrvSetNetSrv(v *sess.NetSrv) optionF

初始化网络服务

func SrvSetTimer

func SrvSetTimer(v *timerwheel.Timer) optionF

初始化定时器

Types

type IDGenerater

type IDGenerater struct {
	// contains filtered or unexported fields
}

IDGenerater 获取唯一的ID号

func NewIDGenerater

func NewIDGenerater(srvID uint64) *IDGenerater

func (*IDGenerater) GenerateID

func (srv *IDGenerater) GenerateID() uint64

type IServiceReal

type IServiceReal interface {
	global.IsrvInst
	entity.IEntities
	sess.INetServer
	timerwheel.ITimer
	serverMgr.IExt

	/* 生命周期 */
	//所有子系统的初始化
	Init() error
	//循环调用
	Loop()
	//循环调用中间
	Looping()
	//循环调用结尾
	Looped()
	//结束服务
	Destroy()

	//监听需要主动连接的服务器逻辑
	WatchServer()
}

后代service接口

type NetSess_Proc

type NetSess_Proc struct {
	Srv  *Service
	Sess sess.INetSess
}

用来处理主动连接别的服务器时候,验证逻辑的部分消息

func (*NetSess_Proc) MsgProc_ClientVerifySucceedRet

func (this *NetSess_Proc) MsgProc_ClientVerifySucceedRet(msg *protomsg.ClientVerifySucceedRet)

连接别的服务器,对方验证过了

func (*NetSess_Proc) MsgProc_SessClosed

func (this *NetSess_Proc) MsgProc_SessClosed(msg *protomsg.SessClosed)

连接关闭的时候,会自己给自己发一个关闭的消息,这个消息还没有protomsg化 然后在service还有netsess还有user中都需要对这个进行处理

type Service

type Service struct {
	entity.DelayCallHost
	*sess.NetSrv
	*entity.Entities
	*timerwheel.Timer

	//每次Tick的时候的当前时间
	NowTime time.Time
	//每个服务器启动的时候自动生成的值
	Token string

	//服务器信息
	Sinfo *global.GlobalConfig
	//etcd
	Etcd *etcd.EtcdAccess
	//服务器信息管理器
	DisMgr *serverMgr.DiscoveryMgr
	// contains filtered or unexported fields
}

服务器基类

func NewService

func NewService(sinfo *global.GlobalConfig, real IServiceReal, opts ...optionF) (result *Service)

func (*Service) Destroy

func (this *Service) Destroy()

结束服务

func (*Service) GetClientSess

func (this *Service) GetClientSess(id uint64) (result *sess.NetSess)

获取会话

func (*Service) GetDirMgr

func (this *Service) GetDirMgr() *serverMgr.DiscoveryMgr

获取服务器负载器

func (*Service) GetEtcd

func (this *Service) GetEtcd() *etcd.EtcdAccess

获取ETCD的实例

func (*Service) GetLoad

func (this *Service) GetLoad() int

获取服务器当前繁忙状态0-100

func (*Service) GetNewDBID

func (this *Service) GetNewDBID() uint64

获取新的DBID

func (*Service) GetNewEID

func (this *Service) GetNewEID() uint64

获取新的EntityID

func (*Service) GetSelfInfo

func (this *Service) GetSelfInfo() serverMgr.IServerInfo

获取自己服务器需要注册的信息

func (*Service) GetThreadGo

func (this *Service) GetThreadGo() *threads.ThreadGo

操作子协程的管理器

func (*Service) HandlerSrvInvalid

func (this *Service) HandlerSrvInvalid(entityID uint64)

HandlerSrvInvalid 处理服务不可用

func (*Service) Init

func (this *Service) Init() (err error)

所有子系统的初始化

func (*Service) IsSrvValid

func (this *Service) IsSrvValid() bool

IsSrvValid 服务是否可用

func (*Service) Loop

func (this *Service) Loop()

循环调用

func (*Service) Looped

func (this *Service) Looped()

循环调用结尾

func (*Service) Looping

func (this *Service) Looping()

循环调用中间

func (*Service) NewInfo

func (this *Service) NewInfo(stype global.ServerTypeEnum) serverMgr.IServerInfo

根据类型生成一个新的IServerInfo对象,用与从etcd读出来后进行填充

func (*Service) PostMsgToClient

func (this *Service) PostMsgToClient(srvid, spid, eid uint64, msg msgdef.IMsg) (err error)

通过目标服务器发消息给客户端

func (*Service) PostMsgToClientBuf

func (this *Service) PostMsgToClientBuf(srvid, spid, eid uint64, data []byte) (err error)

通过目标服务器发消息给客户端

func (*Service) PostMsgToEntity

func (this *Service) PostMsgToEntity(srvid, spid, eid uint64, msg msgdef.IMsg) (err error)

发消息给其他服务器的对象

func (*Service) PostSess

func (this *Service) PostSess(srvid uint64, msg msgdef.IMsg)

发这消息到目标服务器

func (*Service) RangeSess

func (this *Service) RangeSess(f func(sess sess.INetSess) bool)

遍历所有被动连接,返回false就退出遍历

func (*Service) Run

func (this *Service) Run()

//////////////////////////////////////////////////////////// 主协程调用

func (*Service) WatchInfoCallBack

func (this *Service) WatchInfoCallBack(sinfo serverMgr.IServerInfo)

获取到新的服务器信息的时候回调,一般用来判断是否需要连接这个服务器

func (*Service) WatchServer

func (this *Service) WatchServer()

监听需要主动连接的服务器逻辑 做服发现一般有二个目的:

1、主动连接对方服务器;
2、管理用户去对应服务器时候,使用什么负载均衡的逻辑;
默认系统给他们分配的都是随机负载均衡器;
如果你想修改,可以重载这个函数;
同一个stype+groupid的key只能watch一次;
所以上层使用新的负载均衡器Watch之后,这里就不会重新Watch了

type Service_Proc

type Service_Proc struct {
	*Service
}

func (*Service_Proc) MsgProc_EntityMsgRet

func (this *Service_Proc) MsgProc_EntityMsgRet(msg *protomsg.EntityMsgRet)

处理其他服务器要发给客户的消息

func (*Service_Proc) MsgProc_ForwardMsgSrv

func (this *Service_Proc) MsgProc_ForwardMsgSrv(msg *protomsg.ForwardMsgSrv)

处理转发过来的信息

func (*Service_Proc) MsgProc_ForwardRPCSrv

func (this *Service_Proc) MsgProc_ForwardRPCSrv(msg *protomsg.ForwardRPCSrv)

处理转发过来的RPC

func (*Service_Proc) MsgProc_SessClosed

func (this *Service_Proc) MsgProc_SessClosed(msg *protomsg.SessClosed)

处理连接被关的时候的消息,一般只需要输出信息就好

Jump to

Keyboard shortcuts

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