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)
| 562 | // 启动心跳检测 |
| 563 | // (option 心跳检测的配置) |
| 564 | func (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 | |
| 591 | func (s *Server) GetHeartBeat() ziface.IHeartbeatChecker { |
| 592 | return s.hc |
no test coverage detected