server

package
v0.0.0-...-6785f5e Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2025 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const ReportIntervalSecondDefault int64 = 30 // etcd-上报时间间隔 秒
View Source
const (
	ServerInfoTimeOutSec int64 = 60 // 信息-打印 超时时间 秒
)
View Source
const StatusRunning = 0 // 服务状态:运行中
View Source
const StatusStopping = 1 // 服务状态:关闭中

Variables

View Source
var GBusChannelQuitCheck = make(chan struct{}, 1)

总线-channel-退出检查

View Source
var GServerStatus uint32

Functions

func IsServerStopping

func IsServerStopping() bool

IsServerStopping 服务是否关闭中

func SetServerStopping

func SetServerStopping()

SetServerStopping 设置为关闭中

Types

type IServer

type IServer interface {
	Start(ctx context.Context, opts ...*ServerOptions) (err error) // 启动服务
	PreStop() (err error)                                          // 服务关闭前的处理 - 关闭资源前
	Stop() (err error)                                             // 停止服务 - 关闭 bus 之后
}

type Server

type Server struct {
	ConfigMgr xconfig.Mgr
	ConfigSub *xconfig.Sub

	GroupID        uint32 // 组ID
	Name           string // 名称
	ID             uint32 // ID
	ExecutablePath string // 执行程序路径 // 程序所在路径(如为link,则为link所在的路径)
	AvailableLoad  uint32 // 可用负载

	Log     xlog.ILog
	TimeMgr *xtime.Mgr
	Timer   xtimer.ITimer

	Etcd    xetcd.IEtcd
	EtcdKey string // etcd key

	BusChannel          chan interface{} // 总线
	BusChannelWaitGroup sync.WaitGroup   // 总线等待

	QuitChan chan struct{} // 退出信号, 用于关闭服务

	TCPServer *xnettcp.Server
	KCPServer *xnetkcp.Server

	ServerObject IServer // 服务实例
	// contains filtered or unexported fields
}

func NewServer

func NewServer(args []string) *Server

NewServer 创建服务 args: [进程名称, 组ID, 服务名, 服务ID]

func (*Server) Handle

func (p *Server) Handle() error

Handle todo [重要] issue 在处理 event 时候, 向 eventChan 中插入 事件,注意超出eventChan的上限会阻塞. 目前有超时机制来防止阻塞.

func (*Server) PreStop

func (p *Server) PreStop() error

func (*Server) Start

func (p *Server) Start(ctx context.Context, opts ...*ServerOptions) (err error)

func (*Server) Stop

func (p *Server) Stop() (err error)

type ServerOptions

type ServerOptions struct {
	TCPHandler      xnetcommon.IHandler
	KCPHandler      xnetcommon.IHandler
	LogCallbackFunc xlog.CallBackFunc
	ETCDCallbackFun xetcd.CallbackFun
}

ServerOptions contains options to configure a Server instance. Each option can be set through setter functions. See documentation for each setter function for an explanation of the option.

func NewServerOptions

func NewServerOptions() *ServerOptions

NewServerOptions 新的ServerOptions

func (*ServerOptions) WithETCDCallbackFun

func (p *ServerOptions) WithETCDCallbackFun(callbackFun xetcd.CallbackFun) *ServerOptions

func (*ServerOptions) WithKCPHandler

func (p *ServerOptions) WithKCPHandler(handler xnetcommon.IHandler) *ServerOptions

func (*ServerOptions) WithLogCallbackFunc

func (p *ServerOptions) WithLogCallbackFunc(callbackFunc xlog.CallBackFunc) *ServerOptions

func (*ServerOptions) WithTCPHandler

func (p *ServerOptions) WithTCPHandler(handler xnetcommon.IHandler) *ServerOptions

Jump to

Keyboard shortcuts

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