public static void StartNewManager(out string friendlyname) { NumberOfManagersToStart++; var portNumber = Settings.Default.ManagerEndpointPortNumberStart + (NumberOfManagersToStart - 1); var allowedDowntimeSeconds = Settings.Default.AllowedDowntimeSeconds; Uri uri; var copiedManagerConfigurationFile = CopyManagerConfigurationFile(ManagerConfigurationFile, NumberOfManagersToStart, portNumber, allowedDowntimeSeconds, out uri); CopiedManagerConfigurationFiles.Add(uri, copiedManagerConfigurationFile); var appDomainManagerTask = new AppDomainManagerTask(_buildMode, DirectoryManagerAssemblyLocationFullPath, copiedManagerConfigurationFile, Settings.Default.ManagerAssemblyName); AppDomainManagerTasks.AddOrUpdate(appDomainManagerTask.GetAppDomainUniqueId(), appDomainManagerTask, (s, task) => appDomainManagerTask); RoundRobin.AddHost(uri); Logger.DebugWithLineNumber("Start: AppDomainManagerTask.StartTask"); appDomainManagerTask.StartTask(new CancellationTokenSource()); Logger.DebugWithLineNumber("Finished: AppDomainManagerTask.StartTask"); friendlyname = appDomainManagerTask.GetAppDomainUniqueId(); }
public static void Main(string[] args) { CurrentDomainConfigurationFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile; XmlConfigurator.ConfigureAndWatch(new FileInfo(CurrentDomainConfigurationFile)); Logger.DebugWithLineNumber("Start."); SetConsoleCtrlHandler(ConsoleCtrlCheck, true); //--------------------------------------------------------- // Number of managers and number of nodes to start up. //--------------------------------------------------------- NumberOfManagersToStart = Settings.Default.NumberOfManagersToStart; NumberOfNodesToStart = Settings.Default.NumberOfNodesToStart; //--------------------------------------------------------- // Use load balancer if only one mananager is used. //--------------------------------------------------------- UseLoadBalancerIfJustOneManager = Settings.Default.UseLoadBalancerIfJustOneManager; if (args.Any()) { Logger.DebugWithLineNumber("Has command arguments."); foreach (var s in args) { var values = s.Split('='); // Managers. if (values[0].Equals(ManagersCommandArgument, StringComparison.InvariantCultureIgnoreCase)) { NumberOfManagersToStart = Convert.ToInt32(values[1]); } // Nodes. if (values[0].Equals(NodesCommandArgument, StringComparison.InvariantCultureIgnoreCase)) { NumberOfNodesToStart = Convert.ToInt32(values[1]); } // Use load balancer. if (values[0].Equals(UseLoadBalancerIfJustOneManagerArgument, StringComparison.InvariantCultureIgnoreCase)) { UseLoadBalancerIfJustOneManager = Convert.ToBoolean(values[1]); } } } Logger.InfoWithLineNumber(NumberOfManagersToStart + " number of managers will be started."); Logger.InfoWithLineNumber(NumberOfNodesToStart + " number of nodes will be started."); Logger.DebugWithLineNumber("AppDomain.CurrentDomain.DomainUnload"); AppDomain.CurrentDomain.DomainUnload += CurrentDomainOnDomainUnload; Logger.DebugWithLineNumber("AppDomain.CurrentDomain.UnhandledException"); AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; DirectoryManagerAssemblyLocationFullPath = new DirectoryInfo(Path.Combine(Settings.Default.ManagerAssemblyLocationFullPath, _buildMode)); DirectoryManagerConfigurationFileFullPath = new DirectoryInfo(Path.Combine(Settings.Default.ManagerConfigurationFileFullPath, _buildMode)); Logger.DebugWithLineNumber("DirectoryManagerConfigurationFileFullPath : " + DirectoryManagerConfigurationFileFullPath.FullName); ManagerConfigurationFile = new FileInfo(Path.Combine(DirectoryManagerConfigurationFileFullPath.FullName, Settings.Default.ManagerConfigurationFileName)); Logger.DebugWithLineNumber("ManagerConfigurationFile : " + ManagerConfigurationFile.FullName); CopiedManagerConfigurationFiles = new Dictionary <Uri, FileInfo>(); var allowedDowntimeSeconds = Settings.Default.AllowedDowntimeSeconds; if (NumberOfManagersToStart == 1 && !UseLoadBalancerIfJustOneManager) { var configuration = new Configuration(Settings.Default.ManagerLocationUri); Uri address = configuration.BaseAddress; Uri uri; var copiedManagerConfigurationFile = CopyManagerConfigurationFile(ManagerConfigurationFile, 1, address.ToString(), allowedDowntimeSeconds, out uri); CopiedManagerConfigurationFiles.Add(uri, copiedManagerConfigurationFile); } else { for (var i = 0; i < NumberOfManagersToStart; i++) { var portNumber = Settings.Default.ManagerEndpointPortNumberStart + i; Uri uri; var copiedManagerConfigurationFile = CopyManagerConfigurationFile(ManagerConfigurationFile, i + 1, portNumber, allowedDowntimeSeconds, out uri); CopiedManagerConfigurationFiles.Add(uri, copiedManagerConfigurationFile); } } Logger.DebugWithLineNumber("Created " + CopiedManagerConfigurationFiles.Count + " manager configuration files."); DirectoryNodeConfigurationFileFullPath = new DirectoryInfo(Path.Combine(Settings.Default.NodeConfigurationFileFullPath, _buildMode)); Logger.DebugWithLineNumber("DirectoryNodeConfigurationFileFullPath : " + DirectoryNodeConfigurationFileFullPath.FullName); NodeConfigurationFile = new FileInfo(Path.Combine(DirectoryNodeConfigurationFileFullPath.FullName, Settings.Default.NodeConfigurationFileName)); Logger.DebugWithLineNumber("NodeConfigurationFile : " + NodeConfigurationFile.FullName); NodeconfigurationFiles = new Dictionary <string, FileInfo>(); PortStartNumber = Settings.Default.NodeEndpointPortNumberStart; if (NumberOfNodesToStart > 0) { for (var i = 1; i <= NumberOfNodesToStart; i++) { Logger.DebugWithLineNumber("Start creating node configuration file for node id : " + i); var nodeConfig = CreateNodeConfigurationFile(i); Logger.DebugWithLineNumber("Finished creating node configuration file for node : ( id, config file ) : ( " + i + ", " + nodeConfig.FullName + " )"); } } //------------------------------------------------------- // App domain manager tasks. //------------------------------------------------------- Logger.DebugWithLineNumber("AppDomainManagerTasks"); AppDomainManagerTasks = new ConcurrentDictionary <string, AppDomainManagerTask>(); Parallel.ForEach(CopiedManagerConfigurationFiles.Values, copiedManagerConfigurationFile => { var appDomainManagerTask = new AppDomainManagerTask(_buildMode, DirectoryManagerAssemblyLocationFullPath, copiedManagerConfigurationFile, Settings.Default.ManagerAssemblyName); Logger.DebugWithLineNumber("Start: AppDomainManagerTask.StartTask"); appDomainManagerTask.StartTask(new CancellationTokenSource()); AppDomainManagerTasks.AddOrUpdate(copiedManagerConfigurationFile.Name, appDomainManagerTask, (s, task) => appDomainManagerTask); }); Logger.DebugWithLineNumber("Finished: AppDomainManagerTask.StartTask"); //------------------------------------------------------- //------------------------------------------------------- DirectoryNodeAssemblyLocationFullPath = new DirectoryInfo(Path.Combine(Settings.Default.NodeAssemblyLocationFullPath, _buildMode)); Logger.DebugWithLineNumber("DirectoryNodeAssemblyLocationFullPath : " + DirectoryNodeAssemblyLocationFullPath.FullName); AppDomainNodeTasks = new ConcurrentDictionary <string, AppDomainNodeTask>(); Parallel.ForEach(NodeconfigurationFiles, pair => { Logger.DebugWithLineNumber("AppDomainNodeTask"); var appDomainNodeTask = new AppDomainNodeTask(_buildMode, DirectoryNodeAssemblyLocationFullPath, pair.Value, Settings.Default.NodeAssemblyName); Logger.DebugWithLineNumber("Start : AppDomainNodeTask.StartTask"); appDomainNodeTask.StartTask(new CancellationTokenSource()); Logger.DebugWithLineNumber("Finished : AppDomainNodeTask.StartTask"); AppDomainNodeTasks.AddOrUpdate(pair.Value.Name, appDomainNodeTask, (s, task) => appDomainNodeTask); }); if (NumberOfManagersToStart > 1 || UseLoadBalancerIfJustOneManager) { Task.Factory.StartNew(() => StartLoadBalancerProxy(CopiedManagerConfigurationFiles.Keys)); } StartSelfHosting(); }