internal void ConsumeServices(IServiceProvider services) { try { this.ServiceProvider = services; var connectionLostHandlers = this.ServiceProvider.GetServices <ConnectionToClusterLostHandler>(); foreach (var handler in connectionLostHandlers) { this.ClusterConnectionLost += handler; } var gatewayCountChangedHandlers = this.ServiceProvider.GetServices <GatewayCountChangedHandler>(); foreach (var handler in gatewayCountChangedHandlers) { this.GatewayCountChanged += handler; } this.InternalGrainFactory = this.ServiceProvider.GetRequiredService <IInternalGrainFactory>(); this.messageFactory = this.ServiceProvider.GetService <MessageFactory>(); var serializationManager = this.ServiceProvider.GetRequiredService <SerializationManager>(); this.localObjects = new InvokableObjectManager( services.GetRequiredService <ClientGrainContext>(), this, serializationManager, this.messagingTrace, this.loggerFactory.CreateLogger <ClientGrainContext>()); var timerLogger = this.loggerFactory.CreateLogger <SafeTimer>(); var minTicks = Math.Min(this.clientMessagingOptions.ResponseTimeout.Ticks, TimeSpan.FromSeconds(1).Ticks); var period = TimeSpan.FromTicks(minTicks); this.callbackTimer = new SafeTimer(timerLogger, this.OnCallbackExpiryTick, null, period, period); this.GrainReferenceRuntime = this.ServiceProvider.GetRequiredService <IGrainReferenceRuntime>(); BufferPool.InitGlobalBufferPool(this.clientMessagingOptions); this.clientProviderRuntime = this.ServiceProvider.GetRequiredService <ClientProviderRuntime>(); this.localAddress = this.clientMessagingOptions.LocalAddress ?? ConfigUtilities.GetLocalIPAddress(this.clientMessagingOptions.PreferredFamily, this.clientMessagingOptions.NetworkInterfaceName); // Client init / sign-on message logger.Info(ErrorCode.ClientInitializing, string.Format( "{0} Initializing OutsideRuntimeClient on {1} at {2} Client Id = {3} {0}", BARS, Dns.GetHostName(), localAddress, clientId)); string startMsg = string.Format("{0} Starting OutsideRuntimeClient with runtime Version='{1}' in AppDomain={2}", BARS, RuntimeVersion.Current, PrintAppDomainDetails()); logger.Info(ErrorCode.ClientStarting, startMsg); if (TestOnlyThrowExceptionDuringInit) { throw new InvalidOperationException("TestOnlyThrowExceptionDuringInit"); } var statisticsLevel = statisticsOptions.Value.CollectionLevel; if (statisticsLevel.CollectThreadTimeTrackingStats()) { incomingMessagesThreadTimeTracking = new ThreadTrackingStatistic("ClientReceiver", this.loggerFactory, this.statisticsOptions, this.schedulerStageStatistics); } } catch (Exception exc) { if (logger != null) { logger.Error(ErrorCode.Runtime_Error_100319, "OutsideRuntimeClient constructor failed.", exc); } ConstructorReset(); throw; } }
internal void ConsumeServices(IServiceProvider services) { this.ServiceProvider = services; var connectionLostHandlers = this.ServiceProvider.GetServices <ConnectionToClusterLostHandler>(); foreach (var handler in connectionLostHandlers) { this.ClusterConnectionLost += handler; } var clientInvokeCallbacks = this.ServiceProvider.GetServices <ClientInvokeCallback>(); foreach (var handler in clientInvokeCallbacks) { this.ClientInvokeCallback += handler; } this.InternalGrainFactory = this.ServiceProvider.GetRequiredService <IInternalGrainFactory>(); this.ClientStatistics = this.ServiceProvider.GetRequiredService <ClientStatisticsManager>(); this.serializationManager = this.ServiceProvider.GetRequiredService <SerializationManager>(); this.messageFactory = this.ServiceProvider.GetService <MessageFactory>(); this.GrainReferenceRuntime = this.ServiceProvider.GetRequiredService <IGrainReferenceRuntime>(); var statisticsOptions = this.ServiceProvider.GetRequiredService <IOptions <ClientStatisticsOptions> >().Value; StatisticsCollector.Initialize(statisticsOptions.CollectionLevel); BufferPool.InitGlobalBufferPool(this.clientMessagingOptions); try { AppDomain.CurrentDomain.DomainUnload += CurrentDomain_DomainUnload; clientProviderRuntime = this.ServiceProvider.GetRequiredService <ClientProviderRuntime>(); responseTimeout = Debugger.IsAttached ? Constants.DEFAULT_RESPONSE_TIMEOUT : this.clientMessagingOptions.ResponseTimeout; this.localAddress = ConfigUtilities.GetLocalIPAddress(this.clientMessagingOptions.PreferredFamily, this.clientMessagingOptions.NetworkInterfaceName); // Client init / sign-on message logger.Info(ErrorCode.ClientInitializing, string.Format( "{0} Initializing OutsideRuntimeClient on {1} at {2} Client Id = {3} {0}", BARS, Dns.GetHostName(), localAddress, handshakeClientId)); string startMsg = string.Format("{0} Starting OutsideRuntimeClient with runtime Version='{1}' in AppDomain={2}", BARS, RuntimeVersion.Current, PrintAppDomainDetails()); logger.Info(ErrorCode.ClientStarting, startMsg); if (TestOnlyThrowExceptionDuringInit) { throw new InvalidOperationException("TestOnlyThrowExceptionDuringInit"); } this.gatewayListProvider = this.ServiceProvider.GetRequiredService <IGatewayListProvider>(); if (StatisticsCollector.CollectThreadTimeTrackingStats) { incomingMessagesThreadTimeTracking = new ThreadTrackingStatistic("ClientReceiver", this.loggerFactory); } } catch (Exception exc) { if (logger != null) { logger.Error(ErrorCode.Runtime_Error_100319, "OutsideRuntimeClient constructor failed.", exc); } ConstructorReset(); throw; } }