public void UpdateServerState(FeedbackLevel workload, int peerCount, ServerState state) { if (!this.IsRegistered) { return; } var contract = new UpdateServerEvent { LoadIndex = (byte)workload, PeerCount = peerCount, State = (int)state }; var eventData = new EventData((byte)ServerEventCode.UpdateServer, contract); this.SendEvent(eventData, new SendParameters()); }
protected virtual void HandleUpdateGameServerEvent(IEventData eventData) { var updateGameServer = new UpdateServerEvent(this.Protocol, eventData); if (updateGameServer.IsValid == false) { string msg = updateGameServer.GetErrorMessage(); log.ErrorFormat("UpdateServer contract error: {0}", msg); return; } var previuosLoadLevel = this.LoadLevel; this.LoadLevel = (FeedbackLevel)updateGameServer.LoadIndex; this.PeerCount = updateGameServer.PeerCount; if ((ServerState)updateGameServer.State != this.State) { if (log.IsDebugEnabled) { log.DebugFormat("GameServer state changed for {0}: old={1}, new={2} ", this.TcpAddress, this.State, (ServerState)updateGameServer.State); } this.State = (ServerState)updateGameServer.State; if (this.State == ServerState.Normal) { if (this.application.LoadBalancer.TryAddServer(this, (int)this.LoadLevel) == false) { log.WarnFormat("Failed to add game server to load balancer: serverId={0}", this.ServerId); } } else if (this.State == ServerState.Offline) { ///this.RemoveGameServerPeerOnMaster(); } else { this.application.LoadBalancer.TryRemoveServer(this); } } else if (previuosLoadLevel != this.LoadLevel) { if (log.IsDebugEnabled) { log.DebugFormat("UpdateGameServer - from LoadLevel {0} to {1}, PeerCount {2}", previuosLoadLevel, this.LoadLevel, this.PeerCount); } if (!this.application.LoadBalancer.TryUpdateServer(this, (int)this.LoadLevel)) { log.WarnFormat("Failed to update game server state for {0}", this.TcpAddress); } } }
protected virtual void HandleUpdateGameServerEvent(IEventData eventData) { var updateGameServer = new UpdateServerEvent(this.Protocol, eventData); if (updateGameServer.IsValid == false) { string msg = updateGameServer.GetErrorMessage(); log.ErrorFormat("UpdateServer contract error: {0}", msg); return; } var previuosLoadLevel = this.LoadLevel; this.LoadLevel = (FeedbackLevel)updateGameServer.LoadIndex; this.PeerCount = updateGameServer.PeerCount; if ((ServerState)updateGameServer.State != this.State) { this.SetServerState((ServerState)updateGameServer.State); } else if (previuosLoadLevel != this.LoadLevel && this.State == ServerState.Normal) { if (log.IsDebugEnabled) { log.DebugFormat("UpdateGameServer - from LoadLevel {0} to {1}, PeerCount {2}", previuosLoadLevel, this.LoadLevel, this.PeerCount); } if (!this.application.LoadBalancer.TryUpdateServer(this, this.LoadLevel)) { log.WarnFormat("Failed to update game server state for {0}", this.TcpAddress); } } }