MCPcopy
hub / github.com/aceld/zinx / StartHeartBeatWithOption

Method StartHeartBeatWithOption

znet/server.go:564–589  ·  view source on GitHub ↗

StartHeartBeatWithOption starts the heartbeat detection with the given configuration. interval is the time interval for sending heartbeat messages. option is the configuration for heartbeat detection. 启动心跳检测 (option 心跳检测的配置)

(interval time.Duration, option *ziface.HeartBeatOption)

Source from the content-addressed store, hash-verified

562// 启动心跳检测
563// (option 心跳检测的配置)
564func (s *Server) StartHeartBeatWithOption(interval time.Duration, option *ziface.HeartBeatOption) {
565 checker := NewHeartbeatChecker(interval)
566
567 // Configure the heartbeat checker with the provided options
568 if option != nil {
569 checker.SetHeartbeatMsgFunc(option.MakeMsg)
570 checker.SetOnRemoteNotAlive(option.OnRemoteNotAlive)
571 //检测当前路由模式
572 if s.RouterSlicesMode {
573 checker.BindRouterSlices(option.HeartBeatMsgID, option.RouterSlices...)
574 } else {
575 checker.BindRouter(option.HeartBeatMsgID, option.Router)
576 }
577 }
578
579 // Add the heartbeat checker's router to the server's router (添加心跳检测的路由)
580 //检测当前路由模式
581 if s.RouterSlicesMode {
582 s.AddRouterSlices(checker.MsgID(), checker.RouterSlices()...)
583 } else {
584 s.AddRouter(checker.MsgID(), checker.Router())
585 }
586
587 // Bind the server with the heartbeat checker (server绑定心跳检测器)
588 s.hc = checker
589}
590
591func (s *Server) GetHeartBeat() ziface.IHeartbeatChecker {
592 return s.hc

Callers 1

mainFunction · 0.95

Calls 10

SetHeartbeatMsgFuncMethod · 0.95
SetOnRemoteNotAliveMethod · 0.95
BindRouterSlicesMethod · 0.95
BindRouterMethod · 0.95
AddRouterSlicesMethod · 0.95
MsgIDMethod · 0.95
RouterSlicesMethod · 0.95
AddRouterMethod · 0.95
RouterMethod · 0.95
NewHeartbeatCheckerFunction · 0.85

Tested by

no test coverage detected