public static void close() { try { if (_nchost != null) { if (_nchost.HostServer != null) { _nchost.HostServer.Dispose(); } } if (_socketServer != null) { _socketServer.Stop(); } if (_managementSocketServer != null) { _managementSocketServer.Stop(); } if (_nchost != null) { _nchost.StopHosting(); _nchost = null; } CacheServer.ReleaseServiceObject(); AppUtil.LogEvent(_applicationName, "Cache [ " + cacheName + " ] separate process is stopped successfully.", EventLogEntryType.Information, EventCategories.Information, EventID.GeneralInformation); } catch (Exception ex) { AppUtil.LogEvent(_applicationName, "Cache [ " + cacheName + " ] Error: " + ex.ToString(), EventLogEntryType.Error, EventCategories.Error, EventID.GeneralError); } }
public static void StartCacheHost() { cacheName = cacheName.ToLower(); string _clientServerIp = string.Empty; IPAddress clusterIp = null; IPAddress clientServerIp = null; try { AssemblyResolveEventHandler.CacheName = cacheName; AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(Alachisoft.NCache.Common.Util.AssemblyResolveEventHandler.DeployAssemblyHandler); int sendBuffer = SocketServer.SocketServer.DEFAULT_SOCK_BUFFER_SIZE; int receiveBuffer = SocketServer.SocketServer.DEFAULT_SOCK_BUFFER_SIZE; if (ServiceConfiguration.SendBufferSize > 0) { sendBuffer = ServiceConfiguration.SendBufferSize; } if (ServiceConfiguration.ReceiveBufferSize > 0) { receiveBuffer = ServiceConfiguration.ReceiveBufferSize; } _nchost = new Alachisoft.NCache.Management.CacheHost(); _socketServer = new SocketServer.SocketServer(ServiceConfiguration.Port, sendBuffer, receiveBuffer); _nchost.HostServer.Renderer = _socketServer; #if !NETCORE && !NETCOREAPP2_0 try { string serviceEXE1 = Path.Combine(AppUtil.InstallDir, "bin"); string serviceEXE2 = Path.Combine(serviceEXE1, "service"); string serviceEXE3 = Path.Combine(serviceEXE2, "Alachisoft.NCache.Service.exe"); Configuration config = ConfigurationManager.OpenExeConfiguration(serviceEXE3); } catch (Exception ex) { return; } #else try { string serviceEXE1 = Path.Combine(AppUtil.InstallDir, "bin"); string serviceEXE2 = Path.Combine(serviceEXE1, "service"); string serviceEXE3 = Path.Combine(serviceEXE2, "Alachisoft.NCache.Daemon.dll"); Configuration config = ConfigurationManager.OpenExeConfiguration(serviceEXE3); } catch (Exception ex) { return; } #endif try { clusterIp = ServiceConfiguration.BindToIP; } catch (Exception) { ErrorCode = 5; throw new Exception("Invalid BindToClusterIP address specified."); } try { clientServerIp = ServiceConfiguration.BindToIP; } catch (Exception) { ErrorCode = 6; throw new Exception("Invalid BindToClientServerIP address specified"); } try { if (!Helper.isPortFree(managementPort, clusterIp)) { ErrorCode = 8; throw new Exception("Management listener can not be started. The port might already be in use"); } } catch (Exception ex) { if (ex.ToString().Contains("Specified argument was out of the range of valid values")) { ErrorCode = 10; throw new Exception("The port is outside the range of valid values for Management."); } else { throw; } } _socketServer.CacheName = cacheName; CacheProvider.Provider = _nchost.HostServer; _managementSocketServer = new SocketServer.SocketServer(managementPort, sendBuffer, receiveBuffer); _managementSocketServer.Start(clusterIp, Common.Logger.LoggerNames.CacheManagementSocketServer, "NManagement", CommandManagerType.NCacheHostManagement, ConnectionManagerType.Management); _socketServer.Start(clientServerIp, Common.Logger.LoggerNames.SocketServerLogs, "Cache Host", CommandManagerType.NCacheClient, ConnectionManagerType.HostClient); CacheServer.SocketServerPort = managementPort; CacheServer.ConnectionManager = SocketServer.SocketServer.HostClientConnectionManager; _nchost.HostServer.SynchronizeClientConfig(); _nchost.HostServer.ClusterIP = clusterIp.ToString(); _nchost.HostServer.Renderer.ManagementIPAddress = clusterIp.ToString(); OnCacheStopped cacheStoppedDelegate = new OnCacheStopped(onCacheStopped); _nchost.HostServer.RegisterCacheStopCallback(cacheStoppedDelegate); //for debugging purposes, comment this line _nchost.HostServer.InitiateCacheHostStopThread(); AppUtil.LogEvent(_applicationName, "Cache [ " + cacheName + " ] separate process is started successfully.", EventLogEntryType.Information, EventCategories.Information, EventID.GeneralInformation); } catch (Exception e) { throwError(e.ToString(), false); } try { // Start the watcher to check if service configuration file gets changed. // For hot applicable FileSystemWatcher configWatcher = new FileSystemWatcher(); string path = Path.Combine(AppUtil.InstallDir, "bin"); configWatcher.Path = Path.Combine(path, "service"); configWatcher.Filter = "*.config"; configWatcher.NotifyFilter = NotifyFilters.LastWrite; configWatcher.Changed += ServiceConfigChanged; configWatcher.EnableRaisingEvents = true; } catch (Exception) { } }