public void Init() { var methods = CommandManagerType.GetMethods(); foreach (var method in methods) { var commandAtt = method.GetCustomAttribute <CommandAttribute>(true); if (commandAtt == null) { continue; } var cmd = new Command(this, method, commandAtt); Commands.Add(cmd); } }
/// <summary> /// Starts the socket server.It registers some types with compact Framework, /// enables simple logs as well as DetailedLogs, then it checks Ncache licence information. /// starts connection manager and perfmon counters. /// </summary> /// <param name="bindIP" ></param> /// public void Start(IPAddress bindIP, LoggerNames loggerName, string perfStatColInstanceName, CommandManagerType cmdMgrType, ConnectionManagerType conMgrType) { if (loggerName == null) { _loggerName = LoggerNames.SocketServerLogs; } else { _loggerName = loggerName; } InitializeLogging(); #if JAVA _perfStatsColl = new PerfStatsCollector("TayzGrid Server", _serverPort); #else _perfStatsColl = new PerfStatsCollector(cacheName, _serverPort); #endif _conManager = new ConnectionManager(_perfStatsColl); _conManager.Start(bindIP, _serverPort, _sendBuffer, _recieveBuffer, _logger, cmdMgrType, conMgrType); if (ConnectionManagerType.HostClient == conMgrType) { _hostClientConnectionManager = _conManager; } // We initialize PerfstatsCollector only for SocketServer's instance for client. // Management socket server has just DUMMY stats collector. if (conMgrType == ConnectionManagerType.HostClient) { _perfStatsColl.InitializePerfCounters(); } }
internal ICommandManager GetCommandManager(CommandManagerType cmdMgrType) { ICommandManager cmdMgr; switch (cmdMgrType) { case CommandManagerType.NCacheClient: cmdMgr = new CommandManager(_perfStatsCollector); break; case CommandManagerType.NCacheManagement: cmdMgr = new ManagementCommandManager(); break; default: cmdMgr = new CommandManager(_perfStatsCollector); break; } return cmdMgr; }
/// <summary> /// Starts the socket server.It registers some types with compact Framework, /// enables simple logs as well as DetailedLogs, then it checks Ncache licence information. /// starts connection manager and perfmon counters. /// </summary> /// <param name="bindIP" ></param> /// public void Start(IPAddress bindIP, LoggerNames loggerName, string perfStatColInstanceName, CommandManagerType cmdMgrType) { if (loggerName == null) _loggerName = LoggerNames.SocketServerLogs; else _loggerName = loggerName; InitializeLogging(); _perfStatsColl = new PerfStatsCollector("NCache Server", _serverPort); _conManager = new ConnectionManager(_perfStatsColl); _conManager.Start(bindIP, _serverPort, _sendBuffer, _recieveBuffer, _logger, cmdMgrType); //We initialize PerfstatsCollector only for SocketServer's instance for client. //Management socket server has just DUMMY stats collector. if(cmdMgrType == CommandManagerType.NCacheClient) _perfStatsColl.InitializePerfCounters(); }
/// <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(); }