/// <summary> /// Creates a new client /// </summary> private BrokerManagementServiceClient CreateClient() { BrokerManagementServiceClient client = new BrokerManagementServiceClient( BindingHelper.HardCodedBrokerManagementServiceBinding, new EndpointAddress(SoaHelper.GetBrokerManagementServiceAddress(this.brokerProcess.Id))); client.InnerChannel.OperationTimeout = operationTimeoutForBrokerManagementService; return(client); }
/// <summary> /// The main entry point for the application. /// </summary> /// <param name="args">indicating arguments</param> private static int Main(string[] args) { var log = new LoggerConfiguration().ReadFrom.AppSettings().Enrich.WithMachineName().CreateLogger(); Log.Logger = log; if (!ParseAndSetBrokerWorkerSettings(args)) { // parsing failed return((int)BrokerShimExitCode.ForceExit); } if (ConfigureLogging) { Trace.TraceInformation("Log configuration for Session Launcher has done successfully."); Log.CloseAndFlush(); return((int)BrokerShimExitCode.ForceExit); } //SingletonRegistry.Initialize(SingletonRegistry.RegistryMode.WindowsNonHA); #if HPCPACK WinServiceHpcContextModule.GetOrAddWinServiceHpcContextFromEnv().GetAADClientAppIdAsync().FireAndForget(); // cache AAD AppId now. #endif // improve http performance for Azure storage queue traffic ServicePointManager.DefaultConnectionLimit = 1000; ServicePointManager.Expect100Continue = false; ServicePointManager.UseNagleAlgorithm = false; int pid = Process.GetCurrentProcess().Id; trace = TraceHelper.RuntimeTrace; AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); ManualResetEvent exitWaitHandle = new ManualResetEvent(false); // ThreadPoolMonitor.StartOnlyInDebug(); try { Uri brokerManagementServiceAddress = new Uri(SoaHelper.GetBrokerManagementServiceAddress(pid)); ServiceHost host; try { BrokerManagementService instance = new BrokerManagementService(exitWaitHandle); trace.LogBrokerWorkerMessage(pid, string.Format("[Main] Try open broker management service at {0}.", brokerManagementServiceAddress.ToString())); host = new ServiceHost(instance, brokerManagementServiceAddress); host.CloseTimeout = TimeSpan.FromSeconds(1); host.AddServiceEndpoint(typeof(IBrokerManagementService), BindingHelper.HardCodedBrokerManagementServiceBinding, String.Empty); host.Open(); trace.LogBrokerWorkerMessage(pid, "[Main] Open broker management service succeeded."); } catch (Exception e) { trace.LogBrokerWorkerUnexpectedlyExit(pid, string.Format("[Main] Failed to open broker management service: {0}", e)); return((int)BrokerShimExitCode.FailedOpenServiceHost); } bool createdNew; EventWaitHandle initializeWaitHandle = new EventWaitHandle(false, EventResetMode.ManualReset, String.Format(Constant.InitializationWaitHandleNameFormat, pid), out createdNew); if (createdNew && !BrokerWorkerSetting.Default.Debug) { trace.LogBrokerWorkerUnexpectedlyExit(pid, "[Main] Initialize wait handle has not been created by the broker launcher."); return((int)BrokerShimExitCode.InitializeWaitHandleNotExist); } if (!initializeWaitHandle.Set()) { trace.LogBrokerWorkerUnexpectedlyExit(pid, "[Main] Failed to set the initialize wait handle."); return((int)BrokerShimExitCode.FailedToSetInitializeWaitHandle); } // Wait for exit exitWaitHandle.WaitOne(); try { // Make sure server is terminated correctly and the client is getting notified // Swallow exception and ignore any failure because we don't want broker to retry host.Close(); } catch (Exception ex1) { trace.LogBrokerWorkerMessage( pid, string.Format(CultureInfo.InvariantCulture, "[Program].Main: Exception {0}", ex1)); trace.LogBrokerWorkerMessage(pid, "[Main] Failed to close the ServiceHost."); try { host.Abort(); } catch (Exception ex) { trace.LogBrokerWorkerMessage( pid, string.Format(CultureInfo.InvariantCulture, "[Program].Main: Exception {0}", ex)); trace.LogBrokerWorkerMessage(pid, "[Main] Failed to abort the ServiceHost."); } } return((int)BrokerShimExitCode.Success); } catch (Exception e) { trace.LogBrokerWorkerUnexpectedlyExit(pid, String.Format("[Main] Exception thrown to ROOT: {0}", e)); throw; } finally { trace.LogBrokerWorkerMessage(pid, "[Main] Process exit."); Log.CloseAndFlush(); } }