コード例 #1
0
        /// <summary>
        /// Updates the summary of the server.
        /// </summary>
        /// <param name="serverStatus">The server status.</param>
        protected virtual void UpdateServerStatus(StatusInfoCollection serverStatus)
        {
            DateTime now = DateTime.Now;

            serverStatus[StatusInfoKeys.IsRunning]        = m_StateCode == ServerStateConst.Running;
            serverStatus[StatusInfoKeys.TotalConnections] = this.SessionCount;

            var totalHandledRequests0 = serverStatus.GetValue <long>(StatusInfoKeys.TotalHandledRequests, 0);

            var totalHandledRequests = this.TotalHandledRequests;

            serverStatus[StatusInfoKeys.RequestHandlingSpeed] = ((totalHandledRequests - totalHandledRequests0) / now.Subtract(serverStatus.CollectedTime).TotalSeconds);
            serverStatus[StatusInfoKeys.TotalHandledRequests] = totalHandledRequests;

            if (State == ServerState.Running)
            {
                var sendingQueuePool = m_SocketServer.SendingQueuePool;
                serverStatus[StatusInfoKeys.AvialableSendingQueueItems] = sendingQueuePool.AvialableItemsCount;
                serverStatus[StatusInfoKeys.TotalSendingQueueItems]     = sendingQueuePool.TotalItemsCount;
            }
            else
            {
                serverStatus[StatusInfoKeys.AvialableSendingQueueItems] = 0;
                serverStatus[StatusInfoKeys.TotalSendingQueueItems]     = 0;
            }

            serverStatus.CollectedTime = now;
        }
コード例 #2
0
        private bool SetupFinal()
        {
            //Check receiveFilterFactory
            if (ReceiveFilterFactory == null)
            {
                ReceiveFilterFactory = CreateDefaultReceiveFilterFactory();

                if (ReceiveFilterFactory == null)
                {
                    if (Logger.IsErrorEnabled)
                    {
                        Logger.Error("receiveFilterFactory is required!");
                    }

                    return(false);
                }
            }

            var plainConfig = Config as ServerConfig;

            if (plainConfig == null)
            {
                //Using plain config model instead of .NET configuration element to improve performance
                plainConfig = new ServerConfig(Config);

                if (string.IsNullOrEmpty(plainConfig.Name))
                {
                    plainConfig.Name = Name;
                }

                Config = plainConfig;
            }

            try
            {
                m_ServerStatus      = new StatusInfoCollection();
                m_ServerStatus.Name = Name;
                m_ServerStatus.Tag  = Name;
                m_ServerStatus[StatusInfoKeys.MaxConnectionNumber] = Config.MaxConnectionNumber;
                m_ServerStatus[StatusInfoKeys.Listeners]           = m_Listeners;
            }
            catch (Exception e)
            {
                if (Logger.IsErrorEnabled)
                {
                    Logger.Error("Failed to create ServerSummary instance!", e);
                }

                return(false);
            }

            return(SetupSocketServer());
        }