/// <summary> /// Fires when the windows service starts. /// </summary> /// <param name="args">The arguments passed, if any.</param> protected override void OnStart(string[] args) { _logger.Info("Cache Host is starting", "Cache Host is starting"); // Configure the thread pool's minimum threads ThreadPool.SetMinThreads(128, 128); _logger.Info("Cache Host is starting", "Verifying settings"); try { // Instantiate the cache host engine _cacheHostEngine = new CacheHostEngine(CacheHostConfigurationSection.Settings); } catch (Exception ex) { // The inner exception has the actual details of the configuration error if (ex.InnerException != null && ex.InnerException.Message != null && ex.InnerException.Message.StartsWith("The value for the property", StringComparison.OrdinalIgnoreCase)) { ex = ex.InnerException; } // Log the error _logger.Error("Cache Host failed to start", ex.Message); // Stop the service Stop(); } _logger.Info("Cache Host is starting", "Settings verified successfully"); _cacheHostEngine.Start(); }
/// <summary> /// Fires when the windows service starts. /// </summary> /// <param name="args">The arguments passed, if any.</param> protected override void OnStart(string[] args) { _logger.Info("Cache Host is starting", "Cache Host is starting"); // Configure the thread pool's minimum threads ThreadPool.SetMinThreads(128, 128); _logger.Info("Cache Host is starting", "Verifying settings"); try { // Gather settings var configuration = CacheHostConfigurationSection.Settings; var port = configuration.Port; var physicalMemoryLimitPercentage = configuration.CacheMemoryLimitPercentage; var maximumConnections = configuration.MaximumConnections; // Configure the performance counter data manager var performanceDataManager = new PerformanceCounterPerformanceDataManager(port); // Determine the MemCache to use IMemCache memCache; var memoryCache = new MemCache(physicalMemoryLimitPercentage, performanceDataManager); if (configuration.StorageProvider == typeof(GZipMemCache)) { memCache = new GZipMemCache(memoryCache); } else { memCache = memoryCache; } // Instantiate the cache host engine _cacheHostEngine = new CacheHostEngine(memCache, _logger, port, physicalMemoryLimitPercentage, maximumConnections); } catch (Exception ex) { // The inner exception has the actual details of the configuration error if (ex.InnerException != null && ex.InnerException.Message != null && ex.InnerException.Message.StartsWith("The value for the property", StringComparison.OrdinalIgnoreCase)) { ex = ex.InnerException; } // Log the error _logger.Error("Cache Host failed to start", ex.Message); // Stop the service Stop(); } _logger.Info("Cache Host is starting", "Settings verified successfully"); _cacheHostEngine.Start(); }
static bool ConfigureCacheHostEngine() { // Gather settings CacheHostConfigurationSection configuration = null; try { configuration = CacheHostConfigurationSection.Settings; } catch (TypeInitializationException ex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("ERROR: cacheHostSettings configuration is incorrect"); Console.WriteLine("ERROR: " + ex.GetBaseException().Message); Console.WriteLine(); Console.Write("Press any key to exit..."); Console.ReadKey(); return(false); } if (configuration == null) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("ERROR: cacheHostSettings configuration block is missing"); Console.WriteLine("ERROR: Please verify that cacheHostSettings exists in config file"); Console.WriteLine(); Console.Write("Press any key to exit..."); Console.ReadKey(); return(false); } // Instantiate the cache host engine _cacheHostEngine = new CacheHostEngine(configuration); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("SETTINGS: Listening on port " + configuration.Port); Console.WriteLine("SETTINGS: Max Connections " + configuration.MaximumConnections); Console.WriteLine("SETTINGS: Message Buffer Size " + configuration.MessageBufferSize + " BYTES"); Console.WriteLine("SETTINGS: Communication Timeout " + configuration.CommunicationTimeoutSeconds + " SECONDS"); Console.WriteLine("SETTINGS: Max Message Size " + configuration.MaximumMessageSizeKB + " KB"); Console.WriteLine("SETTINGS: Memory Limit " + configuration.CacheMemoryLimitPercentage + "%"); Console.WriteLine("SETTINGS: Compress Data " + configuration.CompressData.ToString().ToUpperInvariant()); Console.WriteLine(); Console.ForegroundColor = ConsoleColor.Cyan; return(true); }
static bool ConfigureCacheHostEngine() { // Gather settings CacheHostConfigurationSection configuration = null; try { configuration = CacheHostConfigurationSection.Settings; } catch (TypeInitializationException ex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("ERROR: cacheHostSettings configuration is incorrect"); Console.WriteLine("ERROR: " + ex.GetBaseException().Message); Console.WriteLine(); Console.Write("Press any key to exit..."); Console.ReadKey(); return false; } if (configuration == null) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("ERROR: cacheHostSettings configuration block is missing"); Console.WriteLine("ERROR: Please verify that cacheHostSettings exists in config file"); Console.WriteLine(); Console.Write("Press any key to exit..."); Console.ReadKey(); return false; } // Instantiate the cache host engine _cacheHostEngine = new CacheHostEngine(configuration); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("SETTINGS: Listening on port " + configuration.Port); Console.WriteLine("SETTINGS: Max Connections " + configuration.MaximumConnections); Console.WriteLine("SETTINGS: Message Buffer Size " + configuration.MessageBufferSize + " BYTES"); Console.WriteLine("SETTINGS: Communication Timeout " + configuration.CommunicationTimeoutSeconds + " SECONDS"); Console.WriteLine("SETTINGS: Max Message Size " + configuration.MaximumMessageSizeKB + " KB"); Console.WriteLine("SETTINGS: Memory Limit " + configuration.CacheMemoryLimitPercentage + "%"); Console.WriteLine("SETTINGS: Compress Data " + configuration.CompressData.ToString().ToUpperInvariant()); Console.WriteLine(); Console.ForegroundColor = ConsoleColor.Cyan; return true; }