Example #1
0
        internal Connection(OnCommandRecieved commandRecieved, OnServerLost serverLost, Logs logs, PerfStatsCollector perfStatsCollector,ResponseIntegrator rspIntegraotr, string bindIP)
        {
            _commandRecieved = commandRecieved;
            _serverLost = serverLost;
            _logger = logs;
            _responseIntegrator = rspIntegraotr;

            _perfStatsColl = perfStatsCollector;

            SetBindIP(bindIP);
            if (System.Configuration.ConfigurationSettings.AppSettings["EnableNaggling"] != null)
                _nagglingEnabled = Convert.ToBoolean(System.Configuration.ConfigurationSettings.AppSettings["EnableNaggling"]);

            //read the naggling size from app.config and covert it to bytes.
            if (System.Configuration.ConfigurationSettings.AppSettings["NagglingSize"] != null)
                _nagglingSize = 1024 * Convert.ToInt64(System.Configuration.ConfigurationSettings.AppSettings["NagglingSize"]);

            if (System.Configuration.ConfigurationSettings.AppSettings["EnableDualSockets"] != null)
                _supportDualSocket = Convert.ToBoolean(System.Configuration.ConfigurationSettings.AppSettings["EnableDualSockets"]);
        }
Example #2
0
        private void InitializeLogs(bool enable_logs, bool detailed_logs)
        {
            if (enable_logs || detailed_logs)
            {
                Logs localLogger = new Logs();
                localLogger.IsDetailedLogsEnabled = detailed_logs;
                localLogger.IsErrorLogsEnabled = enable_logs;

                int pid = System.Diagnostics.Process.GetCurrentProcess().Id;
                localLogger.NCacheLog = new NCacheLogger();
                localLogger.NCacheLog.Initialize(LoggerNames.ClientLogs, _cacheId);
                if (detailed_logs)
                    localLogger.NCacheLog.SetLevel("all");
                else
                {
                    localLogger.NCacheLog.SetLevel("info");
                }

                localLogger.NCacheLog.Info("Broker.InitializeLogs", "PID :" + pid + " ClientID : " + _cache.ClientID);
                _logger = localLogger;
            }
            else
            {
                if (_logger.NCacheLog != null)
                {
                    _logger.NCacheLog.Flush();
                    _logger.NCacheLog.SetLevel("OFF");
                }
            }
        }
Example #3
0
        /// <summary>
        /// Initialize logging
        /// </summary>
        /// <param name="enable">Enable error logging only</param>
        /// <param name="detailed">Enable detailed logging</param>
        public void InitializeLogging(bool errorOnly, bool detailed)
        {
            try
            {
                if (errorOnly || detailed)
                {
                    Logs localLogger=new Logs();
                    localLogger.NCacheLog = new NCacheLogger();
                    localLogger.NCacheLog.Initialize(LoggerNames.SocketServerLogs);

                    if (detailed)
                    {
                        localLogger.NCacheLog.SetLevel("all");
                        localLogger.IsErrorLogsEnabled = true;
                    }
                    else
                    {
                        localLogger.NCacheLog.SetLevel("info");
                    }
                    localLogger.NCacheLog.Info("SocketServer.Start", "server started successfully");

                    ///Set logging status
                    if (errorOnly)
                        _serverLoggingInfo.SetStatus(LoggingInfo.LoggingType.Error, LoggingInfo.LogsStatus.Enable);
                    if (detailed)
                        _serverLoggingInfo.SetStatus(LoggingInfo.LoggingType.Detailed,
                            (detailed ? LoggingInfo.LogsStatus.Enable : LoggingInfo.LogsStatus.Disable));
                    localLogger.IsDetailedLogsEnabled = detailed;
                    localLogger.IsErrorLogsEnabled = errorOnly;

                    _logger= localLogger;

                }
                else
                {
                    if (_logger.NCacheLog != null)
                    {
                        _logger.NCacheLog.Flush();
                        _logger.NCacheLog.SetLevel("OFF");
                    }
                }
            }
            catch (Exception) { throw; }
        }
Example #4
0
        /// <summary>
        /// Start the socket server and start listening for clients
        /// <param name="port">port at which the server will be listening</param>
        /// </summary>
        /// 
        public void Start(IPAddress bindIP, int port, int sendBuffer, int receiveBuffer, Logs logger, CommandManagerType cmdMgrType)
        {
            _logger = logger;
            _clientSendBufferSize = sendBuffer;
            _clientReceiveBufferSize = receiveBuffer;
            cmdManager = GetCommandManager(cmdMgrType);
            string maxPendingConnections="NCache.MaxPendingConnections";
            string enableServerCounters = "NCache.EnableServerCounters";

            if (!string.IsNullOrEmpty(System.Configuration.ConfigurationSettings.AppSettings["NCacheServer.EnableBadClientDetection"]))
            {
                try
                {
                    _enableBadClientDetection = Convert.ToBoolean(System.Configuration.ConfigurationSettings.AppSettings["NCacheServer.EnableBadClientDetection"]);
                }
                catch (Exception e)
                {
                    throw new Exception("Invalid value specified for NCacheServer.EnableBadClientDetection.");
                }

                if (_enableBadClientDetection)
                {
                    if (!string.IsNullOrEmpty(System.Configuration.ConfigurationSettings.AppSettings["NCacheServer.ClientSocketSendTimeOut"]))
                    {
                        try
                        {
                            _timeOutInterval = Convert.ToInt32(System.Configuration.ConfigurationSettings.AppSettings["NCacheServer.ClientSocketSendTimeOut"]);

                        }
                        catch (Exception e)
                        { throw new Exception("Invalid value specified for NCacheServer.ClientSocketSendTimeOut."); }
                    }

                    if (_timeOutInterval < 5)
                        _timeOutInterval = 5;
                }
            }
            string maxPendingCon = System.Configuration.ConfigurationSettings.AppSettings[maxPendingConnections];
            if (maxPendingCon != null && maxPendingCon != String.Empty)
            {
                try
                {
                    _maxClient = Convert.ToInt32(maxPendingCon);
                }
                catch (Exception e)
                {
                    throw new Exception("Invalid value specified for " + maxPendingConnections + ".");
                }
            }
            string enablePerfCounters = System.Configuration.ConfigurationSettings.AppSettings[enableServerCounters];
            if (enablePerfCounters != null && enablePerfCounters != String.Empty)
            {
                try
                {
                    SocketServer.IsServerCounterEnabled = Convert.ToBoolean(enablePerfCounters);
                }
                catch (Exception e)
                {
                    throw new Exception("Invalid value specified for " + enableServerCounters + ".");
                }
            }

            string maxRspLength = System.Configuration.ConfigurationSettings.AppSettings["NCacheServer.MaxResponseLength"];
            if (maxRspLength != null && maxRspLength != String.Empty)
            {
                try
                {
                    int messageLength = Convert.ToInt32(maxRspLength);

                    if (messageLength > 1)
                        _messageFragmentSize = messageLength * 1024;

                }
                catch (Exception e)
                {
                    throw new Exception("Invalid value specified for NCacheServer.MaxResponseLength.");
                }
            }

            _serverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            if (bindIP == null)
            {
                try
                {
                    String hostName = Dns.GetHostName();
                    IPHostEntry ipEntry = Dns.GetHostByName(hostName);
                    bindIP = ipEntry.AddressList[0];
                }
                catch (Exception e)
                {
                }
            }

            try
            {
                if (bindIP != null)
                    _serverSocket.Bind(new IPEndPoint(bindIP, port));
                else
                {
                    _serverSocket.Bind(new IPEndPoint(IPAddress.Any, port));
                }
            }
            catch (System.Net.Sockets.SocketException se)
            {
                switch (se.ErrorCode)
                {
                    // 10049 --> address not available.
                    case 10049:
                        throw new Exception("The address " + bindIP + " specified for NCacheServer.BindToIP is not valid");
                    default:
                        throw;
                }
            }

            _serverSocket.Listen(_maxClient);
            _serverSocket.BeginAccept(new AsyncCallback(AcceptCallback), _serverSocket);

            _serverIpAddress = ((IPEndPoint)_serverSocket.LocalEndPoint).Address.ToString();
            if (cmdMgrType == CommandManagerType.NCacheClient)
                _serverPort = ((IPEndPoint)_serverSocket.LocalEndPoint).Port;

            _callbacksThread = new Thread(new ThreadStart(this.CallbackThread));
            _callbacksThread.Priority = ThreadPriority.BelowNormal;
            _callbacksThread.Start();

            _eventsThread = new Thread(new ThreadStart(this.SendBulkClientEvents));
            _eventsThread.Name = "ConnectionManager.BulkEventThread";
            _eventsThread.Start();
        }