private void SetupBasic(IRootConfig rootConfig, IServerConfig config, ISocketServerFactory socketServerFactory) { if (rootConfig == null) { throw new ArgumentNullException("rootConfig"); } RootConfig = rootConfig; if (config == null) { throw new ArgumentNullException("config"); } if (!string.IsNullOrEmpty(config.Name)) { m_Name = config.Name; } else { m_Name = string.Format("{0}-{1}", this.GetType().Name, Math.Abs(this.GetHashCode())); } Config = config; SetDefaultCulture(rootConfig, config); if (!m_ThreadPoolConfigured) { if (!TheadPoolEx.ResetThreadPool(rootConfig.MaxWorkingThreads >= 0 ? rootConfig.MaxWorkingThreads : new Nullable <int>(), rootConfig.MaxCompletionPortThreads >= 0 ? rootConfig.MaxCompletionPortThreads : new Nullable <int>(), rootConfig.MinWorkingThreads >= 0 ? rootConfig.MinWorkingThreads : new Nullable <int>(), rootConfig.MinCompletionPortThreads >= 0 ? rootConfig.MinCompletionPortThreads : new Nullable <int>())) { throw new Exception("Failed to configure thread pool!"); } m_ThreadPoolConfigured = true; } if (socketServerFactory == null) { var socketServerFactoryType = Type.GetType("SuperSocket.SocketEngine.SocketServerFactory, SuperSocket.SocketEngine", true); socketServerFactory = (ISocketServerFactory)Activator.CreateInstance(socketServerFactoryType); } m_SocketServerFactory = socketServerFactory; //Read text encoding from the configuration if (!string.IsNullOrEmpty(config.TextEncoding)) { TextEncoding = Encoding.GetEncoding(config.TextEncoding); } else { TextEncoding = new ASCIIEncoding(); } }
/// <summary> /// Initializes a new instance of the <see cref="DefaultBootstrap"/> class. /// </summary> /// <param name="rootConfig">The root config.</param> /// <param name="appServers">The app servers.</param> /// <param name="logFactory">The log factory.</param> public DefaultBootstrap(IRootConfig rootConfig, IEnumerable<IWorkItem> appServers, ILogFactory logFactory) { if (rootConfig == null) throw new ArgumentNullException("rootConfig"); if (appServers == null) throw new ArgumentNullException("appServers"); if(!appServers.Any()) throw new ArgumentException("appServers must have one item at least", "appServers"); if (logFactory == null) throw new ArgumentNullException("logFactory"); m_RootConfig = rootConfig; SetDefaultCulture(rootConfig); m_AppServers = appServers.ToList(); m_GlobalLog = logFactory.GetLog(this.GetType().Name); if (!rootConfig.DisablePerformanceDataCollector) { m_PerfMonitor = new PerformanceMonitor(rootConfig, m_AppServers, logFactory); if (m_GlobalLog.IsDebugEnabled) m_GlobalLog.Debug("The PerformanceMonitor has been initialized!"); } if (m_GlobalLog.IsDebugEnabled) m_GlobalLog.Debug("The Bootstrap has been initialized!"); m_Initialized = true; }
protected override bool Setup(IRootConfig rootConfig, IServerConfig config) { //TODO 读取配置设置isDebug Debug.SetLogger(Logger, true); try { updateInterval = int.Parse(config.Options.Get("UpdateInterval")); SyncDebugSystem.isDebug = bool.Parse(config.Options.Get("IsDebug")); } catch { } Debug.Log("SyncService Setup Mode: " + config.Mode + "\nupdateInterval " + updateInterval + "\nisDebug " + SyncDebugSystem.isDebug); dataBaseService.Init(this, config); m_timerService.Init(this, config); matchService.Init(this, config); loginService.Init(this, config); reConnectService.Init(this, config); selectCharacterService.Init(this, config); settlementService.Init(this, config); m_aiService.Init(this, config); CommandMessageService <CommandComponent> .Init(); UpdateEngine.Init(updateInterval); return(base.Setup(rootConfig, config)); }
/// <summary> /// Initializes a new instance of the <see cref="DefaultBootstrap"/> class. /// </summary> /// <param name="rootConfig">The root config.</param> /// <param name="appServers">The app servers.</param> /// <param name="logFactory">The log factory.</param> public DefaultBootstrap(IRootConfig rootConfig, IEnumerable <IWorkItem> appServers, ILogFactory logFactory) { if (rootConfig == null) { throw new ArgumentNullException("rootConfig"); } if (appServers == null) { throw new ArgumentNullException("appServers"); } if (!appServers.Any()) { throw new ArgumentException("appServers must have one item at least", "appServers"); } if (logFactory == null) { throw new ArgumentNullException("logFactory"); } m_RootConfig = rootConfig; m_AppServers = appServers.ToList(); m_GlobalLog = logFactory.GetLog(this.GetType().Name); if (!rootConfig.DisablePerformanceDataCollector) { m_PerfMonitor = new PerformanceMonitor(rootConfig, m_AppServers, logFactory); } m_Initialized = true; }
/// <summary> /// Initializes a new instance of the <see cref="DefaultBootstrap"/> class. /// </summary> /// <param name="rootConfig">The root config.</param> /// <param name="appServers">The app servers.</param> /// <param name="logFactory">The log factory.</param> public DefaultBootstrap(IRootConfig rootConfig, IEnumerable<IWorkItem> appServers, ILogFactory logFactory) { if (rootConfig == null) throw new ArgumentNullException("rootConfig"); if (appServers == null) throw new ArgumentNullException("appServers"); if(!appServers.Any()) throw new ArgumentException("appServers must have one item at least", "appServers"); if (logFactory == null) throw new ArgumentNullException("logFactory"); m_RootConfig = rootConfig; m_AppServers = appServers.ToList(); m_GlobalLog = logFactory.GetLog(this.GetType().Name); if (!rootConfig.DisablePerformanceDataCollector) { m_PerfMonitor = new PerformanceMonitor(rootConfig, m_AppServers, logFactory); m_PerfMonitor.Collected += new EventHandler<PermformanceDataEventArgs>(m_PerfMonitor_Collected); } m_Initialized = true; }
partial void SetDefaultCulture(IRootConfig rootConfig, IServerConfig config) { var defaultCulture = config.DefaultCulture; //default culture has been set for this server instance if (!string.IsNullOrEmpty(defaultCulture)) { Logger.WarnFormat("The default culture '{0}' cannot be set, because you cannot set default culture for one server instance if the Isolation is None!"); return; } else if (!string.IsNullOrEmpty(rootConfig.DefaultCulture)) { defaultCulture = rootConfig.DefaultCulture; return; } if (string.IsNullOrEmpty(defaultCulture)) { return; } try { CultureInfo.DefaultThreadCurrentCulture = new CultureInfo(defaultCulture); } catch (Exception e) { Logger.Error(string.Format("Failed to set default culture '{0}'.", defaultCulture), e); } }
/// <summary> /// Setups the specified root config. /// </summary> /// <param name="rootConfig">The root config.</param> /// <param name="config">The config.</param> /// <returns></returns> protected override bool Setup(IRootConfig rootConfig, IServerConfig config) { if (!base.Setup(rootConfig, config)) { return(false); } var users = config.GetChildConfig <UserConfigCollection>("users"); if (users == null || users.Count <= 0) { Logger.Error("No user defined"); return(false); } m_UsersDict = new Dictionary <string, UserConfig>(StringComparer.OrdinalIgnoreCase); foreach (var u in users) { m_UsersDict.Add(u.Name, u); } m_ExcludedServers = config.Options .GetValue("excludedServers", string.Empty) .Split(new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries) .ToList().Union(new string[] { this.Name }).Distinct().ToArray(); return(true); }
/// <summary> /// Setups the specified root config, used for programming setup /// </summary> /// <param name="rootConfig">The root config.</param> /// <param name="config">The config.</param> /// <param name="socketServerFactory">The socket server factory.</param> /// <param name="providers">The providers.</param> /// <returns></returns> public virtual bool Setup(IRootConfig rootConfig, IServerConfig config, ISocketServerFactory socketServerFactory, params object[] providers) { SetupBasic(rootConfig, config, socketServerFactory); if (!SetupLogFactory(GetProviderInstance <ILogFactory>(providers))) { return(false); } Logger = CreateLogger(this.Name); if (!SetupMedium(GetProviderInstance <IRequestFilterFactory <TRequestInfo> >(providers), GetProviderInstance <IEnumerable <IConnectionFilter> >(providers), GetProviderInstance <IEnumerable <ICommandLoader> >(providers))) { return(false); } if (!SetupAdvanced(config)) { return(false); } if (!Setup(rootConfig, config)) { return(false); } return(SetupFinal()); }
/// <summary> /// Setups the specified root config, this method used for programming setup /// </summary> /// <param name="rootConfig">The root config.</param> /// <param name="config">The config.</param> /// <param name="socketServerFactory">The socket server factory.</param> /// <param name="requestFilterFactory">The request filter factory.</param> /// <param name="logFactory">The log factory.</param> /// <param name="connectionFilters">The connection filters.</param> /// <param name="commandLoaders">The command loaders.</param> /// <returns></returns> public bool Setup(IRootConfig rootConfig, IServerConfig config, ISocketServerFactory socketServerFactory, IRequestFilterFactory <TRequestInfo> requestFilterFactory = null, ILogFactory logFactory = null, IEnumerable <IConnectionFilter> connectionFilters = null, IEnumerable <ICommandLoader> commandLoaders = null) { SetupBasic(rootConfig, config, socketServerFactory); if (!SetupLogFactory(logFactory)) { return(false); } Logger = CreateLogger(this.Name); if (!SetupMedium(requestFilterFactory, connectionFilters, commandLoaders)) { return(false); } if (!SetupAdvanced(config)) { return(false); } if (!Setup(rootConfig, config)) { return(false); } return(SetupFinal()); }
protected override bool Setup(IRootConfig rootConfig, IServerConfig config) { var childConfig = config.GetChildConfig <ChildConfig>("child"); ChildConfigValue = childConfig.Value; return(true); }
protected override bool Setup(IRootConfig rootConfig, IServerConfig config) { int maxFailedLogInTimes; if (!int.TryParse(config.Options.GetValue("maxFailedLogInTimes", "5"), out maxFailedLogInTimes)) { Logger.ErrorFormat("Invalid configuration attribute 'maxFailedLogInTimes'."); return(false); } ExternalLocalAddress = config.Options.GetValue("externalLocalAddress"); MaxFailedLogInTimes = maxFailedLogInTimes; if (!SetupFtpProvider(rootConfig, config)) { return(false); } if (!SetupResource(config)) { return(false); } return(true); }
/// <summary> /// Setups the specified root config, this method used for programming setup /// </summary> /// <param name="rootConfig">The root config.</param> /// <param name="config">The server config.</param> /// <param name="socketServerFactory">The socket server factory.</param> /// <param name="receiveFilterFactory">The Receive filter factory.</param> /// <param name="logFactory">The log factory.</param> /// <param name="connectionFilters">The connection filters.</param> /// <param name="commandLoaders">The command loaders.</param> /// <returns></returns> public bool Setup(IRootConfig rootConfig, IServerConfig config, ISocketServerFactory socketServerFactory = null, IReceiveFilterFactory <TRequestInfo> receiveFilterFactory = null, ILogFactory logFactory = null, IEnumerable <IConnectionFilter> connectionFilters = null) { TrySetInitializedState(); SetupBasic(rootConfig, config, socketServerFactory); SetupLogFactory(logFactory); Logger = CreateLogger(this.Name); if (!SetupMedium(receiveFilterFactory, connectionFilters)) { return(false); } if (!SetupAdvanced(config)) { return(false); } if (!Setup(rootConfig, config)) { return(false); } if (!SetupFinal()) { return(false); } m_StateCode = ServerStateConst.NotStarted; return(true); }
private void BtnUDPServer_Click(object sender, EventArgs e) { try { SERVER_CONFIG = DefaultServerConfig; ROOT_CONFIG = new RootConfig(); udpApp = new UdpAppServer(app_NewSessionConnected, app_SessionClosed); LogHelper.SetOnLog(new LogHelper.LogEvent((m) => { txtAll.Text = string.Join(" ", m, "\r\n"); txtAll.Select(txtAll.TextLength, 0); txtAll.ScrollToCaret(); })); udpApp.Setup(ROOT_CONFIG, SERVER_CONFIG); if (!udpApp.Start()) { LogHelper.WriteLog(string.Format("UDP {0}:{1}启动失败,请检查权限或端口是否被占用!", SERVER_CONFIG.Ip, SERVER_CONFIG.Port), new Exception("启动失败")); } else { LogHelper.WriteLog(string.Format("UDP {0}:{1}启动 成功!", SERVER_CONFIG.Ip, SERVER_CONFIG.Port)); btnUDPServer.Enabled = false; } } catch (Exception ex) { AppLog.Error("Start App" + ex.ToString()); } }
public override bool Setup(IRootConfig rootConfig, IServerConfig config, ISocketServerFactory socketServerFactory, SocketBase.Protocol.ICustomProtocol <SocketBase.Command.StringCommandInfo> protocol) { if (!base.Setup(rootConfig, config, socketServerFactory, protocol)) { return(false); } var childrenConfig = config.GetChildConfig <ChildConfigCollection>("children"); ChildConfigGlobalValue = childrenConfig.GlobalValue; var sum = 0; var pro = 1; foreach (var c in childrenConfig.OfType <ChildConfig>()) { sum += c.Value; pro *= c.Value; } ChildConfigValueSum = sum; ChildConfigValueMultiplyProduct = pro; var childConfig = config.GetChildConfig <ChildConfig>("child"); ChildConfigValue = childConfig.Value; return(true); }
protected virtual IWorkItem CreateAppServer <T>(IRootConfig rootConfig, IServerConfig serverConfig) where T : IWorkItem, ITestSetup, new() { var appServer = new T(); appServer.Setup(rootConfig, serverConfig); return(appServer); }
/// <summary> /// Initializes a new instance of the <see cref="RootConfig"/> class. /// </summary> /// <param name="rootConfig">The root config.</param> public RootConfig(IRootConfig rootConfig) #if NETSTANDARD2_0 : this() #endif { rootConfig.CopyPropertiesTo(this); this.OptionElements = rootConfig.OptionElements; }
protected override bool Setup(IRootConfig rootConfig, IServerConfig config) { //TODO 读取配置设置isDebug Debug.SetLogger(Logger, true); Debug.Log("SyncService Setup"); return(base.Setup(rootConfig, config)); }
protected override bool Setup(IRootConfig rootConfig, IServerConfig serverConfig) { var sendWelcome = true; bool.TryParse(serverConfig.Options.GetValue("sendWelcome", "true"), out sendWelcome); SendWelcome = sendWelcome; return(true); }
public UdpSocketServerTest() { m_Config = DefaultServerConfig; m_RootConfig = new RootConfig { LoggingMode = LoggingMode.Console }; }
public virtual bool Setup(IRootConfig rootConfig, IServerConfig config, ISocketServerFactory socketServerFactory, ICustomProtocol <TCommandInfo> protocol) { if (rootConfig == null) { throw new ArgumentNullException("rootConfig"); } RootConfig = rootConfig; if (!m_ThreadPoolConfigured) { if (!TheadPoolEx.ResetThreadPool(rootConfig.MaxWorkingThreads >= 0 ? rootConfig.MaxWorkingThreads : new Nullable <int>(), rootConfig.MaxCompletionPortThreads >= 0 ? rootConfig.MaxCompletionPortThreads : new Nullable <int>(), rootConfig.MinWorkingThreads >= 0 ? rootConfig.MinWorkingThreads : new Nullable <int>(), rootConfig.MinCompletionPortThreads >= 0 ? rootConfig.MinCompletionPortThreads : new Nullable <int>())) { return(false); } m_ThreadPoolConfigured = true; } if (config == null) { throw new ArgumentNullException("config"); } Config = config; Name = config.Name; m_LogCommand = config.LogCommand; m_SocketServerFactory = socketServerFactory; SetupLogger(); if (!SetupLocalEndpoint(config)) { Logger.LogError("Invalid config ip/port"); return(false); } if (!SetupProtocol(config, protocol)) { return(false); } if (!SetupCommands(m_CommandDict)) { return(false); } if (!SetupSecurity(config)) { return(false); } return(SetupSocketServer()); }
public GameServer() { m_Config = DefaultServerConfig; m_RootConfig = new RootConfig(); m_Encoding = new System.Text.UTF8Encoding(); server = new MyServer(); server.NewSessionConnected += server_NewSessionConnected; server.SessionClosed += server_SessionClosed; }
/// <summary> /// Setups the specified root config. /// </summary> /// <param name="rootConfig">The root config.</param> /// <param name="config">The config.</param> /// <returns></returns> protected override bool Setup(IRootConfig rootConfig, IServerConfig config) { //Convert.ToByte('\0'), 1); ReceiveFilterFactory = new TerminatorReceiveFilterFactory("\0"); //this.NewRequestReceived += new RequestHandler<PolicySession, BinaryRequestInfo>(PolicyServer_NewRequestReceived); return(true); }
protected override bool Setup(IRootConfig rootConfig, IServerConfig config) { int interval = config.Options.GetValue("MonitorInterval", "1").ToInt32(); TimeSpan intervalTimeSpan = new TimeSpan(0, interval, 0); m_MonitorTimer = new Timer(new TimerCallback(OnMonitorTimerCallback), new object(), intervalTimeSpan, intervalTimeSpan); return(true); }
public UdpSocketServerTest() { m_Config = DefaultServerConfig; m_RootConfig = new RootConfig { LoggingMode = LoggingMode.Console }; m_Encoding = new UTF8Encoding(); }
/// <summary> /// Setups the specified root config. /// </summary> /// <param name="bootstrap">The bootstrap.</param> /// <param name="rootConfig">The SuperSocket root config.</param> /// <param name="config">The socket server instance config.</param> /// <param name="socketServerFactory">The socket server factory.</param> /// <returns></returns> bool IAppServer.Setup(IBootstrap bootstrap, IRootConfig rootConfig, IServerConfig config, ISocketServerFactory socketServerFactory) { if (bootstrap == null) { throw new ArgumentNullException("bootstrap"); } Bootstrap = bootstrap; return(Setup(rootConfig, config, socketServerFactory)); }
/// <summary> /// Initializes with the specified app server. /// </summary> /// <typeparam name="TCommand">The type of the command.</typeparam> /// <param name="rootConfig">The root config.</param> /// <param name="appServer">The app server.</param> /// <returns></returns> public override bool Initialize <TCommand>(IRootConfig rootConfig, IAppServer appServer) { m_RootConfig = rootConfig; m_AppServer = appServer; var genericParameterTypes = typeof(TCommand).GetGenericArguments(); m_DynamicCommandType = typeof(DynamicCommand <,>).MakeGenericType(genericParameterTypes); m_MockupCommandType = typeof(MockupCommand <,>).MakeGenericType(genericParameterTypes); return(true); }
protected override bool Setup(IRootConfig rootConfig, IServerConfig config) { bool result = base.Setup(rootConfig, config); foreach (IConnectionFilter IF in this.ConnectionFilters) { IPFilter = IF as BlackBoard; break; } UserManagement = new UserModule("UserList.txt"); return(result); }
public SocketServerTest() { m_Config = DefaultServerConfig; m_RootConfig = new RootConfig { LoggingMode = LoggingMode.Console, MaxWorkingThreads = 500, MaxCompletionPortThreads = 500, MinWorkingThreads = 5, MinCompletionPortThreads = 5 }; }
public PerformanceMonitor(IRootConfig config, IEnumerable <IManagedApp> appServers, IManagedApp serverManager, ILogFactory logFactory) { m_PerfLog = logFactory.GetLog("Performance"); m_AppServers = appServers.ToArray(); m_ServerManager = serverManager; m_Helper = new ProcessPerformanceCounterHelper(Process.GetCurrentProcess()); m_TimerInterval = config.PerformanceDataCollectInterval * 1000; m_PerformanceTimer = new Timer(OnPerformanceTimerCallback); }
public PerformanceMonitor(IRootConfig config, IEnumerable<IWorkItem> appServers, IWorkItem serverManager, ILogFactory logFactory) { m_PerfLog = logFactory.GetLog("Performance"); m_AppServers = appServers.ToArray(); m_ServerManager = serverManager; m_Helper = new ProcessPerformanceCounterHelper(Process.GetCurrentProcess()); m_TimerInterval = config.PerformanceDataCollectInterval * 1000; m_PerformanceTimer = new Timer(OnPerformanceTimerCallback); }
private void BtnUDPServer_Click(object sender, EventArgs e) { try { t_btn_kill_Click(null, null); //if (PortInUse(int.Parse(VarGlobal.DevicePort))) //{ // AppLog.Error("Start App Port = " + VarGlobal.DevicePort.ToString() + " Fail"); // //LookAndStop(int.Parse(VarGlobal.DevicePort)); // t_btn_kill_Click(null,null); // if (PortInUse(int.Parse(VarGlobal.DevicePort))) // { // AppLog.Error("Second Start App Port = " + VarGlobal.DevicePort.ToString() + " Fail"); // return; // } //} //else //{ //} SERVER_CONFIG = DefaultServerConfig; ROOT_CONFIG = new RootConfig(); udpApp = new UdpAppServer(app_NewSessionConnected, app_SessionClosed); LogHelper.SetOnLog(new LogHelper.LogEvent((m) => { txtAll.Text = string.Join(" ", m, "\r\n"); txtAll.Select(txtAll.TextLength, 0); txtAll.ScrollToCaret(); })); udpApp.Setup(ROOT_CONFIG, SERVER_CONFIG); if (!udpApp.Start()) { LogHelper.WriteLog(string.Format("UDP {0}:{1}启动失败,请检查权限或端口是否被占用!", SERVER_CONFIG.Ip, SERVER_CONFIG.Port), new Exception("启动失败")); } else { LogHelper.WriteLog(string.Format("UDP {0}:{1}启动 成功!", SERVER_CONFIG.Ip, SERVER_CONFIG.Port)); btnUDPServer.Enabled = false; } } catch (Exception ex) { AppLog.Error("Start App" + ex.ToString()); } }
protected override bool Setup(IRootConfig rootConfig, IServerConfig config, ISocketServerFactory socketServerFactory, IRequestFilterFactory <StringRequestInfo> requestFilterFactory) { if (!base.Setup(rootConfig, config, socketServerFactory, requestFilterFactory)) { return(false); } int interval = config.Options.GetValue("MonitorInterval", "1").ToInt32(); TimeSpan intervalTimeSpan = new TimeSpan(0, interval, 0); m_MonitorTimer = new Timer(new TimerCallback(OnMonitorTimerCallback), new object(), intervalTimeSpan, intervalTimeSpan); return(true); }
public SocketServerTest() { m_Config = DefaultServerConfig; m_RootConfig = new RootConfig { MaxWorkingThreads = 500, MaxCompletionPortThreads = 500, MinWorkingThreads = 5, MinCompletionPortThreads = 5, DisablePerformanceDataCollector = true }; m_Encoding = new UTF8Encoding(); }
/// <summary> /// Initializes a new instance of the <see cref="DefaultBootstrap"/> class. /// </summary> /// <param name="rootConfig">The root config.</param> /// <param name="appServers">The app servers.</param> /// <param name="logFactory">The log factory.</param> /// <param name="serviceProvider">A container for service objects.</param> public DefaultBootstrap(IRootConfig rootConfig, IEnumerable <IWorkItem> appServers, ILogFactory logFactory, IServiceProvider serviceProvider) : this(serviceProvider) { if (rootConfig == null) { throw new ArgumentNullException("rootConfig"); } if (appServers == null) { throw new ArgumentNullException("appServers"); } if (!appServers.Any()) { throw new ArgumentException("appServers must have one item at least", "appServers"); } if (logFactory == null) { throw new ArgumentNullException("logFactory"); } m_RootConfig = rootConfig; SetDefaultCulture(rootConfig); m_AppServers = appServers.ToList(); m_GlobalLog = logFactory.GetLog(this.GetType().Name); AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); if (!rootConfig.DisablePerformanceDataCollector) { m_PerfMonitor = new PerformanceMonitor(rootConfig, m_AppServers, null, logFactory); if (m_GlobalLog.IsDebugEnabled) { m_GlobalLog.Debug("The PerformanceMonitor has been initialized!"); } } if (m_GlobalLog.IsDebugEnabled) { m_GlobalLog.Debug("The Bootstrap has been initialized!"); } m_Initialized = true; }
public SocketServerTest() { m_Config = DefaultServerConfig; m_RootConfig = new RootConfig { LoggingMode = LoggingMode.Console, MaxWorkingThreads = 500, MaxCompletionPortThreads = 500, MinWorkingThreads = 5, MinCompletionPortThreads = 5 }; m_Encoding = new UTF8Encoding(); }
protected override bool Setup(IRootConfig rootConfig, IServerConfig config) { RegisterConfigHandler(config, "pushInterval", (value) => { var interval = 0; int.TryParse(value, out interval); if (interval <= 0) interval = 60;// 60 seconds by default m_Interval = interval * 1000; return true; }); return true; }
public PerformanceMonitor(IRootConfig config, IEnumerable<IWorkItem> appServers, ILogFactory logFactory) { m_PerfLog = logFactory.GetLog("Performance"); m_AppServers = appServers.ToArray(); Process process = Process.GetCurrentProcess(); m_CpuCores = Environment.ProcessorCount; var isUnix = Environment.OSVersion.Platform == PlatformID.Unix || Environment.OSVersion.Platform == PlatformID.MacOSX; var instanceName = (isUnix || Platform.IsMono) ? string.Format("{0}/{1}", process.Id, process.ProcessName) : GetPerformanceCounterInstanceName(process); SetupPerformanceCounters(instanceName); m_TimerInterval = config.PerformanceDataCollectInterval * 1000; m_PerformanceTimer = new Timer(OnPerformanceTimerCallback); }
public PerformanceMonitor(IRootConfig config, IEnumerable<IWorkItem> appServers, ILogFactory logFactory) { m_AppServers = appServers.ToArray(); Process process = Process.GetCurrentProcess(); m_CpuCores = Environment.ProcessorCount; var isUnix = Environment.OSVersion.Platform == PlatformID.Unix || Environment.OSVersion.Platform == PlatformID.MacOSX; var instanceName = isUnix ? string.Format("{0}/{1}", process.Id, process.ProcessName) : process.ProcessName; m_CpuUsagePC = new PerformanceCounter("Process", "% Processor Time", instanceName); m_ThreadCountPC = new PerformanceCounter("Process", "Thread Count", instanceName); m_WorkingSetPC = new PerformanceCounter("Process", "Working Set", instanceName); m_PerfLog = logFactory.GetLog("Performance"); m_TimerInterval = config.PerformanceDataCollectInterval * 1000; m_PerformanceTimer = new Timer(OnPerformanceTimerCallback); }
/// <summary> /// Gets the script sources. /// </summary> /// <param name="rootConfig">The root config.</param> /// <param name="appServer">The app server.</param> /// <returns></returns> protected override IEnumerable<IScriptSource> GetScriptSources(IRootConfig rootConfig, IAppServer appServer) { var sources = new List<IScriptSource>(); string commandDir = string.Empty; string serverCommandDir = string.Empty; var commandDirSearchOption = SearchOption.TopDirectoryOnly; if (rootConfig.Isolation == IsolationMode.None) { commandDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Command"); serverCommandDir = Path.Combine(commandDir, appServer.Name); } else { commandDirSearchOption = SearchOption.AllDirectories; commandDir = Path.Combine(Directory.GetParent(AppDomain.CurrentDomain.BaseDirectory).Parent.FullName, "Command"); serverCommandDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Command"); } List<string> commandFiles = new List<string>(); if (Directory.Exists(commandDir)) commandFiles.AddRange(GetCommandFiles(commandDir, commandDirSearchOption)); if (Directory.Exists(serverCommandDir)) commandFiles.AddRange(GetCommandFiles(serverCommandDir, SearchOption.AllDirectories)); if (!commandFiles.Any()) { return sources; } foreach (var file in commandFiles) { sources.Add(new FileScriptSource(file)); } return sources; }
/// <summary> /// Initializes a new instance of the <see cref="DefaultBootstrap"/> class. /// </summary> /// <param name="rootConfig">The root config.</param> /// <param name="appServers">The app servers.</param> /// <param name="loggerFactory">The logger factory.</param> public DefaultBootstrap(IRootConfig rootConfig, IEnumerable<IManagedApp> appServers, ILoggerFactory loggerFactory) { if (rootConfig == null) throw new ArgumentNullException("rootConfig"); if (appServers == null) throw new ArgumentNullException("appServers"); if(!appServers.Any()) throw new ArgumentException("appServers must have one item at least", "appServers"); if (loggerFactory == null) throw new ArgumentNullException("logFactory"); m_RootConfig = rootConfig; SetDefaultCulture(rootConfig); m_AppServers = appServers.ToList(); m_GlobalLog = loggerFactory.GetCurrentClassLogger(); AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); if (!rootConfig.DisablePerformanceDataCollector) { m_PerfMonitor = new PerformanceMonitor(rootConfig, m_AppServers, null, loggerFactory); if (m_GlobalLog.IsDebugEnabled) m_GlobalLog.Debug("The PerformanceMonitor has been initialized!"); } if (m_GlobalLog.IsDebugEnabled) m_GlobalLog.Debug("The Bootstrap has been initialized!"); m_Initialized = true; }
/// <summary> /// Initializes the bootstrap with the configuration, config resolver and log factory. /// </summary> /// <param name="config">The config.</param> /// <param name="serverConfigResolver">The server config resolver.</param> /// <param name="logFactory">The log factory.</param> /// <returns></returns> public virtual bool Initialize(IConfig config, Func<IServerConfig, IServerConfig> serverConfigResolver, ILogFactory logFactory) { if (m_Initialized) throw new Exception("The server had been initialized already, you cannot initialize it again!"); m_Config = config; if (LogFactoryProvider.LogFactory == null) { if (logFactory == null) throw new ArgumentNullException("logFactory"); LogFactoryProvider.Initialize(logFactory); } m_GlobalLog = LogFactoryProvider.GlobalLog; //Initialize services m_ServiceDict = new Dictionary<string, Type>(config.Services.Count(), StringComparer.OrdinalIgnoreCase); foreach (var service in config.Services) { if (service.Disabled) continue; Type serviceType; try { serviceType = Type.GetType(service.Type, true); if (serviceType == null) throw new Exception(string.Format("Failed to get type {0}.", service.Type)); } catch (Exception e) { if (m_GlobalLog.IsErrorEnabled) m_GlobalLog.Error("Failed to initialize service " + service.Name + "!", e); return false; } m_ServiceDict[service.Name] = serviceType; } //Initialize connection filters m_ConnectionFilterDict = new Dictionary<string, IConnectionFilter>(config.ConnectionFilters.Count(), StringComparer.OrdinalIgnoreCase); foreach (var filter in config.ConnectionFilters) { Type filterType; try { filterType = Type.GetType(filter.Type, true); if (filterType == null) throw new Exception(string.Format("Failed to get type {0}.", filter.Type)); } catch (Exception e) { if (m_GlobalLog.IsErrorEnabled) m_GlobalLog.Error("Failed to initialize filter " + filter.Name + "!", e); return false; } IConnectionFilter filterInstance; try { filterInstance = (IConnectionFilter)Activator.CreateInstance(filterType); if (!filterInstance.Initialize(filter.Name, filter.Options)) return false; } catch (Exception e) { if (m_GlobalLog.IsErrorEnabled) m_GlobalLog.Error(string.Format("Failed to initialize filter instance {0}!", filter.Name), e); return false; } m_ConnectionFilterDict[filter.Name] = filterInstance; } m_AppServers = new List<IAppServer>(config.Servers.Count()); //Initialize servers foreach (var serverConfig in config.Servers.OrderBy(s => s.StartupOrder)) { if (string.IsNullOrEmpty(serverConfig.Name)) { if (m_GlobalLog.IsErrorEnabled) m_GlobalLog.Error("The name attribute of server node is required!"); return false; } var appServer = InitializeServer(serverConfigResolver(serverConfig)); if (appServer == null) { if (m_GlobalLog.IsErrorEnabled) m_GlobalLog.Error("Failed to initialize server " + serverConfig.Name + "!"); return false; } m_AppServers.Add(appServer); } m_Initialized = true; return true; }
/// <summary> /// Initializes a new instance of the <see cref="DefaultBootstrap"/> class. /// </summary> /// <param name="rootConfig">The root config.</param> /// <param name="appServers">The app servers.</param> public DefaultBootstrap(IRootConfig rootConfig, IEnumerable<IWorkItem> appServers) : this(rootConfig, appServers, new Log4NetLogFactory()) { }
partial void SetDefaultCulture(IRootConfig rootConfig);
/// <summary> /// Initializes the bootstrap with initialized appserver instances. /// </summary> /// <param name="rootConfig">The root config.</param> /// <param name="servers">The servers.</param> /// <param name="serverConfigs">The server configs.</param> /// <returns></returns> public virtual bool Initialize(IRootConfig rootConfig, IEnumerable<IAppServer> servers, IEnumerable<IServerConfig> serverConfigs) { return Initialize(rootConfig, servers, serverConfigs, new Log4NetLogFactory()); }
/// <summary> /// Initializes the bootstrap with initialized appserver instances. /// </summary> /// <param name="rootConfig">The root config.</param> /// <param name="servers">The servers.</param> /// <param name="serverConfigs">The server configs.</param> /// <param name="logFactory">The log factory.</param> /// <returns></returns> public virtual bool Initialize(IRootConfig rootConfig, IEnumerable<IAppServer> servers, IEnumerable<IServerConfig> serverConfigs, ILogFactory logFactory) { if (rootConfig == null) throw new ArgumentNullException("rootConfig"); if (servers == null) throw new ArgumentNullException("servers"); if (serverConfigs == null) throw new ArgumentNullException("serverConfigs"); if (logFactory == null) throw new ArgumentNullException("logFactory"); if (LogFactoryProvider.LogFactory == null) { if (logFactory == null) throw new ArgumentNullException("logFactory"); LogFactoryProvider.Initialize(logFactory); } m_Config = rootConfig; m_GlobalLog = LogFactoryProvider.GlobalLog; if (!servers.Any()) { m_GlobalLog.Error("There must be one item in servers at least!"); return false; } if (!serverConfigs.Any()) { m_GlobalLog.Error("There must be one item in serverConfigs at least!"); return false; } if (servers.Count() != serverConfigs.Count()) { m_GlobalLog.Error("There must be one item in serverConfigs at least!"); return false; } m_AppServers = new List<IAppServer>(servers.Count()); var config = serverConfigs.GetEnumerator(); foreach (var s in servers) { config.MoveNext(); if (!s.Setup(this, rootConfig, config.Current, SocketServerFactory.Instance)) { if (m_GlobalLog.IsErrorEnabled) m_GlobalLog.Error("Failed to setup server instance!"); return false; } m_AppServers.Add(s); } m_Initialized = true; return true; }
/// <summary> /// Initializes a new instance of the <see cref="DefaultBootstrap"/> class. /// </summary> /// <param name="rootConfig">The root config.</param> /// <param name="appServers">The app servers.</param> public DefaultBootstrap(IRootConfig rootConfig, IEnumerable<IManagedApp> appServers) : this(rootConfig, appServers, GetBootstrapLoggerFactory()) { }
public UdpSocketServerTest() { m_Config = DefaultServerConfig; m_RootConfig = new RootConfig(); m_Encoding = new System.Text.UTF8Encoding(); }
/// <summary> /// Initializes the specified servers. /// </summary> /// <param name="rootConfig">The root config.</param> /// <param name="servers">The passed in AppServers, which have been setup.</param> /// <returns></returns> public static bool Initialize(IRootConfig rootConfig, IEnumerable<IAppServer> servers) { if (rootConfig == null) throw new ArgumentNullException("rootConfig"); var config = new ConfigMockup(); rootConfig.CopyPropertiesTo(config); m_ServerList = new List<IAppServer>(servers.Count()); m_ServerList.AddRange(servers); m_Initialized = true; m_Config = config; return true; }