Пример #1
0
        protected const string testDatabaseName = "OrleansMembershipTest";//for relational storage

        protected MembershipTableTestsBase(ConnectionStringFixture fixture, TestEnvironmentFixture environment)
        {
            this.environment = environment;
            LogManager.Initialize(new NodeConfiguration());
            logger       = LogManager.GetLogger(GetType().Name, LoggerType.Application);
            deploymentId = "test-" + Guid.NewGuid();

            logger.Info("DeploymentId={0}", deploymentId);

            fixture.InitializeConnectionStringAccessor(GetConnectionString);

            var globalConfiguration = new GlobalConfiguration
            {
                DeploymentId         = deploymentId,
                AdoInvariant         = GetAdoInvariant(),
                DataConnectionString = fixture.ConnectionString
            };

            membershipTable = CreateMembershipTable(logger);
            membershipTable.InitializeMembershipTable(globalConfiguration, true, logger).WithTimeout(TimeSpan.FromMinutes(1)).Wait();

            var clientConfiguration = new ClientConfiguration
            {
                DeploymentId         = globalConfiguration.DeploymentId,
                AdoInvariant         = globalConfiguration.AdoInvariant,
                DataConnectionString = globalConfiguration.DataConnectionString
            };

            gatewayListProvider = CreateGatewayListProvider(logger);
            gatewayListProvider.InitializeGatewayListProvider(clientConfiguration, logger).WithTimeout(TimeSpan.FromMinutes(1)).Wait();
        }
Пример #2
0
        protected const string testDatabaseName = "OrleansMembershipTest";//for relational storage
        protected MembershipTableTestsBase(ConnectionStringFixture fixture, TestEnvironmentFixture environment, LoggerFilterOptions filters)
        {
            this.environment = environment;
            loggerFactory    = TestingUtils.CreateDefaultLoggerFactory(new NodeConfiguration().TraceFileName, filters);
            logger           = new LoggerWrapper <MembershipTableTestsBase>(loggerFactory);

            deploymentId = "test-" + Guid.NewGuid();

            logger.Info("DeploymentId={0}", deploymentId);

            fixture.InitializeConnectionStringAccessor(GetConnectionString);
            this.connectionString = fixture.ConnectionString;
            globalConfiguration   = new GlobalConfiguration
            {
                DeploymentId         = deploymentId,
                AdoInvariant         = GetAdoInvariant(),
                DataConnectionString = fixture.ConnectionString
            };

            membershipTable = CreateMembershipTable(logger);
            membershipTable.InitializeMembershipTable(true).WithTimeout(TimeSpan.FromMinutes(1)).Wait();

            var clientConfiguration = new ClientConfiguration
            {
                DeploymentId         = globalConfiguration.DeploymentId,
                AdoInvariant         = globalConfiguration.AdoInvariant,
                DataConnectionString = globalConfiguration.DataConnectionString
            };

            gatewayListProvider = CreateGatewayListProvider(logger);
            gatewayListProvider.InitializeGatewayListProvider(clientConfiguration).WithTimeout(TimeSpan.FromMinutes(1)).Wait();
        }
Пример #3
0
 public ProxiedMessageCenter(ClientConfiguration config, IPAddress localAddress, int gen, GrainId clientId, IGatewayListProvider gatewayListProvider)
 {
     lockable = new object();
     MyAddress = SiloAddress.New(new IPEndPoint(localAddress, 0), gen);
     ClientId = clientId;
     Running = false;
     MessagingConfiguration = config;
     GatewayManager = new GatewayManager(config, gatewayListProvider);
     PendingInboundMessages = new RuntimeQueue<Message>();
     gatewayConnections = new Dictionary<Uri, GatewayConnection>();
     numMessages = 0;
     grainBuckets = new WeakReference[config.ClientSenderBuckets];
     logger = TraceLogger.GetLogger("Messaging.ProxiedMessageCenter", TraceLogger.LoggerType.Runtime);
     if (logger.IsVerbose) logger.Verbose("Proxy grain client constructed");
     IntValueStatistic.FindOrCreate(StatisticNames.CLIENT_CONNECTED_GATEWAY_COUNT, () =>
         {
             lock (gatewayConnections)
             {
                 return gatewayConnections.Values.Count(conn => conn.IsLive);
             }
         });
     if (StatisticsCollector.CollectQueueStats)
     {
         queueTracking = new QueueTrackingStatistic("ClientReceiver");
     }
 }
Пример #4
0
        //protected readonly ClientConfiguration clientConfiguration;
        protected MembershipTableTestsBase(/*ConnectionStringFixture fixture, TestEnvironmentFixture environment, */ LoggerFilterOptions filters)
        {
            //this.environment = environment;
            //loggerFactory = TestingUtils.CreateDefaultLoggerFactory($"{this.GetType()}.log", filters);
            //logger = loggerFactory.CreateLogger(this.GetType().FullName);

            this.logger    = NullLogger.Instance;
            this.clusterId = "test-" + Guid.NewGuid();

            this.logger?.Info("ClusterId={clusterId}", this.clusterId);

            //fixture.InitializeConnectionStringAccessor(GetConnectionString);
            //this.connectionString = fixture.ConnectionString;
            this.clusterOptions = Options.Create(new ClusterOptions {
                ClusterId = this.clusterId
            });

            var adoVariant = GetAdoInvariant();

            this.membershipTable = CreateMembershipTable(this.logger);
            this.membershipTable.InitializeMembershipTable(true).WithTimeout(TimeSpan.FromMinutes(10)).Wait();

            //this.clientConfiguration = new ClientConfiguration
            //{
            //    ClusterId = this.clusterId,
            //    AdoInvariant = adoVariant,
            //    //DataConnectionString = fixture.ConnectionString
            //};

            this.gatewayListProvider = CreateGatewayListProvider(this.logger);
            this.gatewayListProvider.InitializeGatewayListProvider().WithTimeout(TimeSpan.FromMinutes(3)).Wait();
        }
Пример #5
0
        protected MembershipTableTestsBase(ConnectionStringFixture fixture, TestEnvironmentFixture environment, LoggerFilterOptions filters)
        {
            this.environment = environment;
            loggerFactory    = TestingUtils.CreateDefaultLoggerFactory($"{this.GetType()}.log", filters);
            logger           = loggerFactory.CreateLogger(this.GetType().FullName);

            this.clusterId = "test-" + Guid.NewGuid();

            logger.Info("ClusterId={0}", this.clusterId);

            fixture.InitializeConnectionStringAccessor(GetConnectionString);
            this.connectionString = fixture.ConnectionString;
            this.siloOptions      = Options.Create(new SiloOptions {
                ClusterId = this.clusterId
            });
            this.clientOptions = Options.Create(new ClusterClientOptions {
                ClusterId = this.clusterId
            });
            var adoVariant = GetAdoInvariant();

            membershipTable = CreateMembershipTable(logger);
            membershipTable.InitializeMembershipTable(true).WithTimeout(TimeSpan.FromMinutes(1)).Wait();

            clientConfiguration = new ClientConfiguration
            {
                ClusterId            = this.clusterId,
                AdoInvariant         = adoVariant,
                DataConnectionString = fixture.ConnectionString
            };

            gatewayListProvider = CreateGatewayListProvider(logger);
            gatewayListProvider.InitializeGatewayListProvider().WithTimeout(TimeSpan.FromMinutes(1)).Wait();
        }
Пример #6
0
        protected MembershipTableTestsBase(ITestOutputHelper output, MultiplexerFixture multiplexerFixture, LoggerFilterOptions filters)
        {
            this.logger    = new XunitLogger <MembershipTableTestsBase>(output);
            this.clusterId = "testC-" + Guid.NewGuid();
            this.serviceId = "testS-" + Guid.NewGuid();

            this.logger.Info("ClusterId={0}", this.clusterId);
            this.logger.Info("ServiceId={0}", this.serviceId);

            this.clusterOptions = Options.Create(new ClusterOptions {
                ClusterId = this.clusterId, ServiceId = this.serviceId
            });

            var redisHost = Environment.GetEnvironmentVariable("REDIS_HOST") ?? "localhost";
            var redisPort = Environment.GetEnvironmentVariable("REDIS_PORT") ?? "6379";

            var options = new RedisClusteringOptions
            {
                ConnectionString = $"{redisHost}:{redisPort}, allowAdmin=true",
                Database         = 0
            };

            this.multiplexerFixture = multiplexerFixture;
            this.multiplexerFixture.Initialize(options);

            this.membershipTable = CreateMembershipTable(this.loggerFactory);
            this.membershipTable.InitializeMembershipTable(true).WithTimeout(TimeSpan.FromMinutes(10)).Wait();

            this.gatewayListProvider = CreateGatewayListProvider(this.membershipTable, this.loggerFactory);
            this.gatewayListProvider.InitializeGatewayListProvider().WithTimeout(TimeSpan.FromMinutes(3)).Wait();
        }
Пример #7
0
        public async Task GatewaySelection_SqlServer()
        {
            string testName = Guid.NewGuid().ToString();// TestContext.TestName;

            Guid serviceId = Guid.NewGuid();

            GlobalConfiguration cfg = new GlobalConfiguration
            {
                ServiceId            = serviceId,
                DeploymentId         = testName,
                DataConnectionString = TestHelper.TestUtils.GetSqlConnectionString()
            };

            var membership = new SqlMembershipTable();
            var logger     = LogManager.GetLogger(membership.GetType().Name);
            await membership.InitializeMembershipTable(cfg, true, logger);

            IMembershipTable membershipTable = membership;

            // Pre-populate gateway table with data
            int count = 1;

            foreach (Uri gateway in gatewayAddressUris)
            {
                output.WriteLine("Adding gataway data for {0}", gateway);

                SiloAddress siloAddress = gateway.ToSiloAddress();
                Assert.IsNotNull(siloAddress, "Unable to get SiloAddress from Uri {0}", gateway);

                MembershipEntry MembershipEntry = new MembershipEntry
                {
                    SiloAddress = siloAddress,
                    HostName    = gateway.Host,
                    Status      = SiloStatus.Active,
                    ProxyPort   = gateway.Port,
                    StartTime   = DateTime.UtcNow
                };

                var tableVersion = new TableVersion(count, Guid.NewGuid().ToString());

                output.WriteLine("Inserting gataway data for {0} with TableVersion={1}", MembershipEntry, tableVersion);

                bool ok = await membershipTable.InsertRow(MembershipEntry, tableVersion);

                count++;
                Assert.IsTrue(ok, "Membership record should have been written OK but were not: {0}", MembershipEntry);

                output.WriteLine("Successfully inserted Membership row {0}", MembershipEntry);
            }

            MembershipTableData data = await membershipTable.ReadAll();

            Assert.IsNotNull(data, "MembershipTableData returned");
            Assert.AreEqual(gatewayAddressUris.Count, data.Members.Count, "Number of gateway records read");

            IGatewayListProvider listProvider = membership;

            Test_GatewaySelection(listProvider);
        }
Пример #8
0
 public GatewayManager(
     IOptions <GatewayOptions> gatewayOptions,
     IGatewayListProvider gatewayListProvider,
     ILoggerFactory loggerFactory,
     ConnectionManager connectionManager)
 {
     this.gatewayOptions      = gatewayOptions.Value;
     this.logger              = loggerFactory.CreateLogger <GatewayManager>();
     this.connectionManager   = connectionManager;
     this.gatewayListProvider = gatewayListProvider;
     this.timerLogger         = loggerFactory.CreateLogger <SafeTimer>();
 }
Пример #9
0
        protected void Test_GatewaySelection(IGatewayListProvider listProvider)
        {
            IList <Uri> gatewayUris = listProvider.GetGateways().GetResult();

            Assert.True(gatewayUris.Count > 0, $"Found some gateways. Data = {Utils.EnumerableToString(gatewayUris)}");

            var gatewayEndpoints = gatewayUris.Select(uri =>
            {
                return(new IPEndPoint(IPAddress.Parse(uri.Host), uri.Port));
            }).ToList();

            var cfg = new ClientConfiguration
            {
                Gateways = gatewayEndpoints
            };
            var gatewayOptions = new GatewayOptions()
            {
                GatewayListRefreshPeriod = cfg.GatewayListRefreshPeriod,
                PreferedGatewayIndex     = cfg.PreferedGatewayIndex
            };
            var gatewayManager = new GatewayManager(gatewayOptions, listProvider, NullLoggerFactory.Instance);

            var counts = new int[4];

            for (int i = 0; i < 2300; i++)
            {
                var ip   = gatewayManager.GetLiveGateway();
                var addr = IPAddress.Parse(ip.Host);
                Assert.Equal(IPAddress.Loopback, addr);  // "Incorrect IP address returned for gateway"
                Assert.True((0 < ip.Port) && (ip.Port < 5), "Incorrect IP port returned for gateway");
                counts[ip.Port - 1]++;
            }

            // The following needed to be changed as the gateway manager now round-robins through the available gateways, rather than
            // selecting randomly based on load numbers.
            //Assert.True((500 < counts[0]) && (counts[0] < 1500), "Gateway selection is incorrectly skewed");
            //Assert.True((500 < counts[1]) && (counts[1] < 1500), "Gateway selection is incorrectly skewed");
            //Assert.True((125 < counts[2]) && (counts[2] < 375), "Gateway selection is incorrectly skewed");
            //Assert.True((25 < counts[3]) && (counts[3] < 75), "Gateway selection is incorrectly skewed");
            //Assert.True((287 < counts[0]) && (counts[0] < 1150), "Gateway selection is incorrectly skewed");
            //Assert.True((287 < counts[1]) && (counts[1] < 1150), "Gateway selection is incorrectly skewed");
            //Assert.True((287 < counts[2]) && (counts[2] < 1150), "Gateway selection is incorrectly skewed");
            //Assert.True((287 < counts[3]) && (counts[3] < 1150), "Gateway selection is incorrectly skewed");

            int low = 2300 / 4;
            int up  = 2300 / 4;

            Assert.True((low <= counts[0]) && (counts[0] <= up), "Gateway selection is incorrectly skewed. " + counts[0]);
            Assert.True((low <= counts[1]) && (counts[1] <= up), "Gateway selection is incorrectly skewed. " + counts[1]);
            Assert.True((low <= counts[2]) && (counts[2] <= up), "Gateway selection is incorrectly skewed. " + counts[2]);
            Assert.True((low <= counts[3]) && (counts[3] <= up), "Gateway selection is incorrectly skewed. " + counts[3]);
        }
Пример #10
0
 public ClientMessageCenter(
     IOptions <GatewayOptions> gatewayOptions,
     IOptions <ClientMessagingOptions> clientMessagingOptions,
     IPAddress localAddress,
     int gen,
     GrainId clientId,
     IGatewayListProvider gatewayListProvider,
     SerializationManager serializationManager,
     IRuntimeClient runtimeClient,
     MessageFactory messageFactory,
     IClusterConnectionStatusListener connectionStatusListener,
     ExecutorService executorService,
     ILoggerFactory loggerFactory,
     IOptions <NetworkingOptions> networkingOptions,
     IOptions <StatisticsOptions> statisticsOptions)
 {
     this.loggerFactory         = loggerFactory;
     this.openConnectionTimeout = networkingOptions.Value.OpenConnectionTimeout;
     this.SerializationManager  = serializationManager;
     this.executorService       = executorService;
     lockable                      = new object();
     MyAddress                     = SiloAddress.New(new IPEndPoint(localAddress, 0), gen);
     ClientId                      = clientId;
     this.RuntimeClient            = runtimeClient;
     this.messageFactory           = messageFactory;
     this.connectionStatusListener = connectionStatusListener;
     Running                = false;
     GatewayManager         = new GatewayManager(gatewayOptions.Value, gatewayListProvider, loggerFactory);
     PendingInboundMessages = new BlockingCollection <Message>();
     gatewayConnections     = new Dictionary <Uri, GatewayConnection>();
     numMessages            = 0;
     grainBuckets           = new WeakReference[clientMessagingOptions.Value.ClientSenderBuckets];
     logger = loggerFactory.CreateLogger <ClientMessageCenter>();
     if (logger.IsEnabled(LogLevel.Debug))
     {
         logger.Debug("Proxy grain client constructed");
     }
     IntValueStatistic.FindOrCreate(
         StatisticNames.CLIENT_CONNECTED_GATEWAY_COUNT,
         () =>
     {
         lock (gatewayConnections)
         {
             return(gatewayConnections.Values.Count(conn => conn.IsLive));
         }
     });
     statisticsLevel = statisticsOptions.Value.CollectionLevel;
     if (statisticsLevel.CollectQueueStats())
     {
         queueTracking = new QueueTrackingStatistic("ClientReceiver", statisticsOptions);
     }
 }
Пример #11
0
        protected MembershipTableTestsBase(ClusterConfiguration clusterConfiguration)
        {
            ConstructorInfo loggerGlobalConfiguration = typeof(Logger).GetConstructors
                                                            (BindingFlags.Instance | BindingFlags.NonPublic)[0];

            //logger = (TraceLogger)loggerGlobalConfiguration.Invoke(new object[] { GetType().Name, TraceLogger.LoggerType.Application });

            //logger = (TraceLogger)loggerGlobalConfiguration.Invoke(new object[] {});

            this.logger = new NoOpTestLogger();

            //LogManager.Initialize(new NodeConfiguration());
            //logger = LogManager.GetLogger(GetType().Name, TraceLogger.LoggerType.Application);

            //logger = new TraceLogger(GetType().Name, TraceLogger.LoggerType.Application);

            //        MethodInfo dynMethod = this.GetType().GetMethod("Draw_" + itemType,
            //BindingFlags.NonPublic | BindingFlags.Instance);
            //        dynMethod.Invoke(this, new object[] { methodParams });

            ConstructorInfo ctorGlobalConfiguration = typeof(GlobalConfiguration).GetConstructors
                                                          (BindingFlags.Instance | BindingFlags.NonPublic)[0];

            GlobalConfiguration globalConfiguration = (GlobalConfiguration)ctorGlobalConfiguration.Invoke(new object[] {});

            globalConfiguration.DeploymentId = globalConfiguration.DeploymentId;
            //globalConfiguration.AdoInvariant = GetAdoInvariant();
            globalConfiguration.DataConnectionString = clusterConfiguration.Globals.DataConnectionString;

            deploymentId = clusterConfiguration.Globals.DeploymentId;

            globalConfiguration.LivenessType            = clusterConfiguration.Globals.LivenessType;
            globalConfiguration.MembershipTableAssembly = clusterConfiguration.Globals.MembershipTableAssembly;
            globalConfiguration.ReminderServiceType     = clusterConfiguration.Globals.ReminderServiceType;
            globalConfiguration.DeploymentId            = clusterConfiguration.Globals.DeploymentId;

            membershipTable = CreateMembershipTable(logger);
            membershipTable.InitializeMembershipTable(globalConfiguration, IsTrue, logger).WithTimeout(TimeSpan.FromMinutes(1)).Wait();

            var clientConfiguration = new ClientConfiguration
            {
                DeploymentId         = globalConfiguration.DeploymentId,
                AdoInvariant         = globalConfiguration.AdoInvariant,
                DataConnectionString = globalConfiguration.DataConnectionString
            };

            gatewayListProvider = CreateGatewayListProvider(logger);
            gatewayListProvider.InitializeGatewayListProvider(clientConfiguration, logger).WithTimeout(TimeSpan.FromMinutes(1)).Wait();
        }
Пример #12
0
 public ProxiedMessageCenter(
     ClientConfiguration config,
     IPAddress localAddress,
     int gen,
     GrainId clientId,
     IGatewayListProvider gatewayListProvider,
     SerializationManager serializationManager,
     IRuntimeClient runtimeClient,
     MessageFactory messageFactory,
     IClusterConnectionStatusListener connectionStatusListener,
     ILoggerFactory loggerFactory,
     IOptions <ClientMessagingOptions> messagingOptions)
 {
     this.loggerFactory         = loggerFactory;
     this.openConnectionTimeout = messagingOptions.Value.OpenConnectionTimeout;
     this.SerializationManager  = serializationManager;
     lockable                      = new object();
     MyAddress                     = SiloAddress.New(new IPEndPoint(localAddress, 0), gen);
     ClientId                      = clientId;
     this.RuntimeClient            = runtimeClient;
     this.messageFactory           = messageFactory;
     this.connectionStatusListener = connectionStatusListener;
     Running                = false;
     GatewayManager         = new GatewayManager(config, gatewayListProvider, loggerFactory);
     PendingInboundMessages = new BlockingCollection <Message>();
     gatewayConnections     = new Dictionary <Uri, GatewayConnection>();
     numMessages            = 0;
     grainBuckets           = new WeakReference[config.ClientSenderBuckets];
     logger = new LoggerWrapper <ProxiedMessageCenter>(loggerFactory);
     if (logger.IsVerbose)
     {
         logger.Verbose("Proxy grain client constructed");
     }
     IntValueStatistic.FindOrCreate(
         StatisticNames.CLIENT_CONNECTED_GATEWAY_COUNT,
         () =>
     {
         lock (gatewayConnections)
         {
             return(gatewayConnections.Values.Count(conn => conn.IsLive));
         }
     });
     if (StatisticsCollector.CollectQueueStats)
     {
         queueTracking = new QueueTrackingStatistic("ClientReceiver");
     }
 }
        protected MembershipTableTestsBase()
        {
            var sp = new ServiceCollection().AddLogging(b => b.AddConsole()).BuildServiceProvider();

            loggerFactory = sp.GetRequiredService <ILoggerFactory>();
            logger        = loggerFactory.CreateLogger(this.GetType().FullName);

            this.clusterId = "test-" + Guid.NewGuid();

            logger?.Info("ClusterId={0}", this.clusterId);

            membershipTable = CreateMembershipTable(logger, accountEndpoint, accountKey);
            membershipTable.InitializeMembershipTable(true).WithTimeout(TimeSpan.FromMinutes(3)).Wait();

            gatewayListProvider = CreateGatewayListProvider(logger, accountEndpoint, accountKey);
            gatewayListProvider.InitializeGatewayListProvider().WithTimeout(TimeSpan.FromMinutes(3)).Wait();
        }
Пример #14
0
 public GatewayManager(
     IOptions <GatewayOptions> gatewayOptions,
     IGatewayListProvider gatewayListProvider,
     ILoggerFactory loggerFactory,
     ConnectionManager connectionManager)
 {
     this.gatewayOptions      = gatewayOptions.Value;
     this.logger              = loggerFactory.CreateLogger <GatewayManager>();
     this.connectionManager   = connectionManager;
     this.gatewayListProvider = gatewayListProvider;
     this.gatewayRefreshTimer = new AsyncTaskSafeTimer(
         loggerFactory.CreateLogger <SafeTimer>(),
         RefreshSnapshotLiveGateways_TimerCallback,
         null,
         this.gatewayOptions.GatewayListRefreshPeriod,
         this.gatewayOptions.GatewayListRefreshPeriod);
 }
Пример #15
0
        public GatewayManager(
            IOptions <GatewayOptions> gatewayOptions,
            IGatewayListProvider gatewayListProvider,
            ILoggerFactory loggerFactory,
            ConnectionManager connectionManager)
        {
            this.gatewayOptions = gatewayOptions.Value;
            knownDead           = new Dictionary <SiloAddress, DateTime>();
            rand                        = new SafeRandom();
            logger                      = loggerFactory.CreateLogger <GatewayManager>();
            this.loggerFactory          = loggerFactory;
            this.connectionManager      = connectionManager;
            lockable                    = new object();
            gatewayRefreshCallInitiated = false;

            ListProvider = gatewayListProvider;

            var knownGateways = ListProvider.GetGateways().GetAwaiter().GetResult();

            if (knownGateways.Count == 0)
            {
                string gatewayProviderType = gatewayListProvider.GetType().FullName;
                string err = $"Could not find any gateway in {gatewayProviderType}. Orleans client cannot initialize.";
                logger.Error(ErrorCode.GatewayManager_NoGateways, err);
                throw new OrleansException(err);
            }

            logger.Info(ErrorCode.GatewayManager_FoundKnownGateways, "Found {0} knownGateways from Gateway listProvider {1}", knownGateways.Count, Utils.EnumerableToString(knownGateways));

            if (ListProvider is IGatewayListObservable)
            {
                ((IGatewayListObservable)ListProvider).SubscribeToGatewayNotificationEvents(this);
            }

            roundRobinCounter = this.gatewayOptions.PreferedGatewayIndex >= 0 ? this.gatewayOptions.PreferedGatewayIndex : rand.Next(knownGateways.Count);

            this.knownGateways = cachedLiveGateways = knownGateways.Select(gw => gw.ToGatewayAddress()).ToList();

            lastRefreshTime     = DateTime.UtcNow;
            gatewayRefreshTimer = new AsyncTaskSafeTimer(
                this.loggerFactory.CreateLogger <SafeTimer>(),
                RefreshSnapshotLiveGateways_TimerCallback,
                null,
                this.gatewayOptions.GatewayListRefreshPeriod,
                this.gatewayOptions.GatewayListRefreshPeriod);
        }
Пример #16
0
        protected MembershipTableTestsBase(/*ConnectionStringFixture fixture, TestEnvironmentFixture environment, */ LoggerFilterOptions filters)
        {
            //this.environment = environment;
            //loggerFactory = TestingUtils.CreateDefaultLoggerFactory($"{this.GetType()}.log", filters);
            //logger = loggerFactory.CreateLogger(this.GetType().FullName);

            this.clusterId = "test-" + Guid.NewGuid();

            logger?.Info("ClusterId={0}", this.clusterId);

            //fixture.InitializeConnectionStringAccessor(GetConnectionString);
            //this.connectionString = fixture.ConnectionString;
            var adoVariant = GetAdoInvariant();

            membershipTable = CreateMembershipTable(logger, accountEndpoint, accountKey);
            membershipTable.InitializeMembershipTable(true).WithTimeout(TimeSpan.FromMinutes(3)).Wait();

            gatewayListProvider = CreateGatewayListProvider(logger, accountEndpoint, accountKey);
            gatewayListProvider.InitializeGatewayListProvider().WithTimeout(TimeSpan.FromMinutes(3)).Wait();
        }
Пример #17
0
        protected MembershipTableTestsBase(LoggerFilterOptions filters)
        {
            loggerFactory = TestingUtils.CreateDefaultLoggerFactory($"{this.GetType()}.log", filters);
            logger        = loggerFactory.CreateLogger(this.GetType().FullName);

            this.clusterId = "test-" + Guid.NewGuid();

            logger.Info("ClusterId={0}", this.clusterId);

            this.clusterOptions = Options.Create(new ClusterOptions {
                ClusterId = this.clusterId
            });

            membershipTable = CreateMembershipTable(logger);
            membershipTable.InitializeMembershipTable(true).Wait();

            this.gatewayOptions = Options.Create(new GatewayOptions());
            gatewayListProvider = CreateGatewayListProvider(logger);
            gatewayListProvider.InitializeGatewayListProvider().Wait();
        }
Пример #18
0
        public GatewayManager(ClientConfiguration cfg, IGatewayListProvider gatewayListProvider, ILoggerFactory loggerFactory)
        {
            config                      = cfg;
            knownDead                   = new Dictionary <Uri, DateTime>();
            rand                        = new SafeRandom();
            logger                      = loggerFactory.CreateLogger <GatewayManager>();
            this.loggerFactory          = loggerFactory;
            lockable                    = new object();
            gatewayRefreshCallInitiated = false;

            ListProvider = gatewayListProvider;

            var knownGateways = ListProvider.GetGateways().GetResult();

            if (knownGateways.Count == 0)
            {
                string gatewayProviderType = gatewayListProvider.GetType().FullName;
                string err = String.Format("Could not find any gateway in {0}. Orleans client cannot initialize.", gatewayProviderType);
                logger.Error(ErrorCode.GatewayManager_NoGateways, err);
                throw new OrleansException(err);
            }

            logger.Info(ErrorCode.GatewayManager_FoundKnownGateways, "Found {0} knownGateways from Gateway listProvider {1}", knownGateways.Count, Utils.EnumerableToString(knownGateways));

            if (ListProvider is IGatewayListObservable)
            {
                ((IGatewayListObservable)ListProvider).SubscribeToGatewayNotificationEvents(this);
            }

            roundRobinCounter = cfg.PreferedGatewayIndex >= 0 ? cfg.PreferedGatewayIndex : rand.Next(knownGateways.Count);

            cachedLiveGateways = knownGateways;

            lastRefreshTime = DateTime.UtcNow;
            if (ListProvider.IsUpdatable)
            {
                gatewayRefreshTimer = new SafeTimer(this.loggerFactory.CreateLogger <SafeTimer>(), RefreshSnapshotLiveGateways_TimerCallback, null, config.GatewayListRefreshPeriod, config.GatewayListRefreshPeriod);
            }
        }
Пример #19
0
        public GatewayManager(ClientConfiguration cfg, IGatewayListProvider gatewayListProvider)
        {
            config = cfg;
            knownDead = new Dictionary<Uri, DateTime>();
            rand = new SafeRandom();
            logger = TraceLogger.GetLogger("Messaging.GatewayManager", TraceLogger.LoggerType.Runtime);
            lockable = new object();
            gatewayRefreshCallInitiated = false;

            ListProvider = gatewayListProvider;

            var knownGateways = ListProvider.GetGateways().GetResult();

            if (knownGateways.Count == 0)
            {
                string gatewayProviderType = gatewayListProvider.GetType().FullName;
                string err = String.Format("Could not find any gateway in {0}. Orleans client cannot initialize.", gatewayProviderType);
                logger.Error(ErrorCode.GatewayManager_NoGateways, err);
                throw new OrleansException(err);
            }

            logger.Info(ErrorCode.GatewayManager_FoundKnownGateways, "Found {0} knownGateways from Gateway listProvider {1}", knownGateways.Count, Utils.EnumerableToString(knownGateways));

            if (ListProvider is IGatewayListObservable)
            {
                ((IGatewayListObservable)ListProvider).SubscribeToGatewayNotificationEvents(this);
            }

            roundRobinCounter = cfg.PreferedGatewayIndex >= 0 ? cfg.PreferedGatewayIndex : rand.Next(knownGateways.Count);

            cachedLiveGateways = knownGateways;

            lastRefreshTime = DateTime.UtcNow;
            if (ListProvider.IsUpdatable)
            {
                gatewayRefreshTimer = new SafeTimer(RefreshSnapshotLiveGateways_TimerCallback, null, config.GatewayListRefreshPeriod, config.GatewayListRefreshPeriod);
            }
        }
Пример #20
0
        internal static async Task <IGatewayListProvider> CreateGatewayListProvider(ClientConfiguration cfg)
        {
            IGatewayListProvider listProvider = null;

            ClientConfiguration.GatewayProviderType gatewayProviderToUse = cfg.GatewayProviderToUse;

            switch (gatewayProviderToUse)
            {
            case ClientConfiguration.GatewayProviderType.AzureTable:
                listProvider = await AzureGatewayListProvider.GetAzureGatewayListProvider(cfg);

                break;

            case ClientConfiguration.GatewayProviderType.SqlServer:
                listProvider = new SqlMembershipTable(cfg);
                break;

            case ClientConfiguration.GatewayProviderType.Config:
                listProvider = new StaticGatewayListProvider(cfg);
                break;
            }
            return(listProvider);
        }
Пример #21
0
 public ProxiedMessageCenter(
     ClientConfiguration config,
     IPAddress localAddress,
     int gen,
     GrainId clientId,
     IGatewayListProvider gatewayListProvider,
     MessageFactory messageFactory)
 {
     lockable               = new object();
     MyAddress              = SiloAddress.New(new IPEndPoint(localAddress, 0), gen);
     ClientId               = clientId;
     this.messageFactory    = messageFactory;
     Running                = false;
     MessagingConfiguration = config;
     GatewayManager         = new GatewayManager(config, gatewayListProvider);
     PendingInboundMessages = new BlockingCollection <Message>();
     gatewayConnections     = new Dictionary <Uri, GatewayConnection>();
     numMessages            = 0;
     grainBuckets           = new WeakReference[config.ClientSenderBuckets];
     logger = LogManager.GetLogger("Messaging.ProxiedMessageCenter", LoggerType.Runtime);
     if (logger.IsVerbose)
     {
         logger.Verbose("Proxy grain client constructed");
     }
     IntValueStatistic.FindOrCreate(StatisticNames.CLIENT_CONNECTED_GATEWAY_COUNT, () =>
     {
         lock (gatewayConnections)
         {
             return(gatewayConnections.Values.Count(conn => conn.IsLive));
         }
     });
     if (StatisticsCollector.CollectQueueStats)
     {
         queueTracking = new QueueTrackingStatistic("ClientReceiver");
     }
 }
Пример #22
0
        internal static async Task <IGatewayListProvider> CreateGatewayListProvider(ClientConfiguration cfg)
        {
            IGatewayListProvider listProvider = null;

            ClientConfiguration.GatewayProviderType gatewayProviderToUse = cfg.GatewayProviderToUse;

            switch (gatewayProviderToUse)
            {
            case ClientConfiguration.GatewayProviderType.AzureTable:
                listProvider = AssemblyLoader.LoadAndCreateInstance <IGatewayListProvider>(Constants.ORLEANS_AZURE_UTILS_DLL, logger);
                break;

            case ClientConfiguration.GatewayProviderType.SqlServer:
                listProvider = AssemblyLoader.LoadAndCreateInstance <IGatewayListProvider>(Constants.ORLEANS_SQL_UTILS_DLL, logger);
                break;

            case ClientConfiguration.GatewayProviderType.Custom:
                listProvider = AssemblyLoader.LoadAndCreateInstance <IGatewayListProvider>(cfg.CustomGatewayProviderAssemblyName, logger);
                break;

            case ClientConfiguration.GatewayProviderType.ZooKeeper:
                listProvider = AssemblyLoader.LoadAndCreateInstance <IGatewayListProvider>(Constants.ORLEANS_ZOOKEEPER_UTILS_DLL, logger);
                break;

            case ClientConfiguration.GatewayProviderType.Config:
                listProvider = new StaticGatewayListProvider();
                break;

            default:
                throw new NotImplementedException(gatewayProviderToUse.ToString());
            }

            await listProvider.InitializeGatewayListProvider(cfg, LogManager.GetLogger(listProvider.GetType().Name));

            return(listProvider);
        }
Пример #23
0
        private void Test_GatewaySelection(IGatewayListProvider listProvider)
        {
            IList<Uri> gatewayUris = listProvider.GetGateways().GetResult();
            Assert.IsTrue(gatewayUris.Count > 0, "Found some gateways. Data = {0}", Utils.EnumerableToString(gatewayUris));

            var gatewayEndpoints = gatewayUris.Select(uri =>
            {
                return new IPEndPoint(IPAddress.Parse(uri.Host), uri.Port);
            }).ToList();

            var cfg = new ClientConfiguration
            {
                Gateways = gatewayEndpoints
            };
            var gatewayManager = new GatewayManager(cfg, listProvider);

            var counts = new int[4];

            for (int i = 0; i < 2300; i++)
            {
                var ip = gatewayManager.GetLiveGateway();
                var addr = IPAddress.Parse(ip.Host);
                Assert.AreEqual(IPAddress.Loopback, addr, "Incorrect IP address returned for gateway");
                Assert.IsTrue((0 < ip.Port) && (ip.Port < 5), "Incorrect IP port returned for gateway");
                counts[ip.Port - 1]++;
            }

            // The following needed to be changed as the gateway manager now round-robins through the available gateways, rather than
            // selecting randomly based on load numbers.
            //Assert.IsTrue((500 < counts[0]) && (counts[0] < 1500), "Gateway selection is incorrectly skewed");
            //Assert.IsTrue((500 < counts[1]) && (counts[1] < 1500), "Gateway selection is incorrectly skewed");
            //Assert.IsTrue((125 < counts[2]) && (counts[2] < 375), "Gateway selection is incorrectly skewed");
            //Assert.IsTrue((25 < counts[3]) && (counts[3] < 75), "Gateway selection is incorrectly skewed");
            //Assert.IsTrue((287 < counts[0]) && (counts[0] < 1150), "Gateway selection is incorrectly skewed");
            //Assert.IsTrue((287 < counts[1]) && (counts[1] < 1150), "Gateway selection is incorrectly skewed");
            //Assert.IsTrue((287 < counts[2]) && (counts[2] < 1150), "Gateway selection is incorrectly skewed");
            //Assert.IsTrue((287 < counts[3]) && (counts[3] < 1150), "Gateway selection is incorrectly skewed");

            int low = 2300 / 4;
            int up = 2300 / 4;
            Assert.IsTrue((low <= counts[0]) && (counts[0] <= up), "Gateway selection is incorrectly skewed. " + counts[0]);
            Assert.IsTrue((low <= counts[1]) && (counts[1] <= up), "Gateway selection is incorrectly skewed. " + counts[1]);
            Assert.IsTrue((low <= counts[2]) && (counts[2] <= up), "Gateway selection is incorrectly skewed. " + counts[2]);
            Assert.IsTrue((low <= counts[3]) && (counts[3] <= up), "Gateway selection is incorrectly skewed. " + counts[3]);
        }
Пример #24
0
 public ProxiedMessageCenter(ClientConfiguration config, IPAddress localAddress, int gen, GrainId clientId, IGatewayListProvider gatewayListProvider)
 {
     lockable  = new object();
     MyAddress = SiloAddress.New(new IPEndPoint(localAddress, 0), gen);
     ClientId  = clientId;
     Running   = false;
     MessagingConfiguration     = config;
     GatewayManager             = new GatewayManager(config, gatewayListProvider);
     PendingInboundMessages     = new RuntimeQueue <Message>();
     registrarGetSystemTarget   = GrainClient.GetStaticMethodThroughReflection("Orleans", "Orleans.Runtime.ClientObserverRegistrarFactory", "GetSystemTarget", null);
     typeManagerGetSystemTarget = GrainClient.GetStaticMethodThroughReflection("Orleans", "Orleans.Runtime.TypeManagerFactory", "GetSystemTarget", null);
     gatewayConnections         = new Dictionary <Uri, GatewayConnection>();
     numMessages            = 0;
     registeredLocalObjects = new HashSet <GrainId>();
     grainBuckets           = new WeakReference[config.ClientSenderBuckets];
     logger = TraceLogger.GetLogger("Messaging.ProxiedMessageCenter", TraceLogger.LoggerType.Runtime);
     if (logger.IsVerbose)
     {
         logger.Verbose("Proxy grain client constructed");
     }
     IntValueStatistic.FindOrCreate(StatisticNames.CLIENT_CONNECTED_GATEWAY_COUNT, () =>
     {
         lock (gatewayConnections)
         {
             return(gatewayConnections.Values.Count(conn => conn.IsLive));
         }
     });
     if (StatisticsCollector.CollectQueueStats)
     {
         queueTracking = new QueueTrackingStatistic("ClientReceiver");
     }
 }
Пример #25
0
        internal void ConsumeServices(IServiceProvider services)
        {
            try
            {
                AppDomain.CurrentDomain.DomainUnload += CurrentDomain_DomainUnload;

                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.messageFactory       = this.ServiceProvider.GetService <MessageFactory>();

                var serializationManager = this.ServiceProvider.GetRequiredService <SerializationManager>();
                this.localObjects = new InvokableObjectManager(
                    this,
                    serializationManager,
                    this.loggerFactory.CreateLogger <InvokableObjectManager>());

                this.sharedCallbackData = new SharedCallbackData(
                    this.TryResendMessage,
                    msg => this.UnregisterCallback(msg.Id),
                    this.loggerFactory.CreateLogger <CallbackData>(),
                    this.clientMessagingOptions,
                    serializationManager,
                    this.appRequestStatistics);
                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 = 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>();

                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;
            }
        }
Пример #26
0
        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.config = this.ServiceProvider.GetRequiredService <ClientConfiguration>();

            var resolvedClientMessagingOptions = this.ServiceProvider.GetRequiredService <IOptions <ClientMessagingOptions> >();

            this.clientMessagingOptions = resolvedClientMessagingOptions.Value;

            this.GrainReferenceRuntime = this.ServiceProvider.GetRequiredService <IGrainReferenceRuntime>();

            this.ServiceProvider.GetService <TelemetryManager>()?.AddFromConfiguration(this.ServiceProvider, config.TelemetryConfiguration);

            var statisticsOptions = this.ServiceProvider.GetRequiredService <IOptions <StatisticsOptions> >();

            StatisticsCollector.Initialize(statisticsOptions.Value.CollectionLevel);

            BufferPool.InitGlobalBufferPool(resolvedClientMessagingOptions);

            try
            {
                AppDomain.CurrentDomain.DomainUnload += CurrentDomain_DomainUnload;

                clientProviderRuntime     = this.ServiceProvider.GetRequiredService <ClientProviderRuntime>();
                statisticsProviderManager = this.ServiceProvider.GetRequiredService <StatisticsProviderManager>();
                var statsProviderName = statisticsProviderManager.LoadProvider(config.ProviderConfigurations)
                                        .WaitForResultWithThrow(initTimeout);
                if (statsProviderName != null)
                {
                    statisticsOptions.Value.ProviderName = statsProviderName;
                }

                responseTimeout   = Debugger.IsAttached ? Constants.DEFAULT_RESPONSE_TIMEOUT : config.ResponseTimeout;
                this.localAddress = ClusterConfiguration.GetLocalIPAddress(config.PreferredFamily, config.NetInterface);

                // Client init / sign-on message
                logger.Info(ErrorCode.ClientInitializing, string.Format(
                                "{0} Initializing OutsideRuntimeClient on {1} at {2} Client Id = {3} {0}",
                                BARS, config.DNSHostName, localAddress, handshakeClientId));
                string startMsg = string.Format("{0} Starting OutsideRuntimeClient with runtime Version='{1}' in AppDomain={2}",
                                                BARS, RuntimeVersion.Current, PrintAppDomainDetails());
                startMsg = string.Format("{0} Config= " + Environment.NewLine + " {1}", startMsg, config);
                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;
            }
        }
Пример #27
0
        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>();

                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;
            }
        }
Пример #28
0
        internal void ConsumeServices(IServiceProvider services)
        {
            this.ServiceProvider = services;

            var connectionLostHandlers = services.GetServices <ConnectionToClusterLostHandler>();

            foreach (var handler in connectionLostHandlers)
            {
                this.ClusterConnectionLost += handler;
            }

            var clientInvokeCallbacks = services.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.config = services.GetRequiredService <ClientConfiguration>();
            this.GrainReferenceRuntime = this.ServiceProvider.GetRequiredService <IGrainReferenceRuntime>();

            if (!LogManager.IsInitialized)
            {
                LogManager.Initialize(config);
            }
            StatisticsCollector.Initialize(config);
            this.assemblyProcessor = this.ServiceProvider.GetRequiredService <AssemblyProcessor>();
            this.assemblyProcessor.Initialize();

            logger         = LogManager.GetLogger("OutsideRuntimeClient", LoggerType.Runtime);
            this.AppLogger = LogManager.GetLogger("Application", LoggerType.Application);

            BufferPool.InitGlobalBufferPool(config);


            try
            {
                LoadAdditionalAssemblies();

                if (!UnobservedExceptionsHandlerClass.TrySetUnobservedExceptionHandler(UnhandledException))
                {
                    logger.Warn(ErrorCode.Runtime_Error_100153, "Unable to set unobserved exception handler because it was already set.");
                }

                AppDomain.CurrentDomain.DomainUnload += CurrentDomain_DomainUnload;

                clientProviderRuntime     = this.ServiceProvider.GetRequiredService <ClientProviderRuntime>();
                statisticsProviderManager = new StatisticsProviderManager("Statistics", clientProviderRuntime);
                var statsProviderName = statisticsProviderManager.LoadProvider(config.ProviderConfigurations)
                                        .WaitForResultWithThrow(initTimeout);
                if (statsProviderName != null)
                {
                    config.StatisticsProviderName = statsProviderName;
                }

                responseTimeout   = Debugger.IsAttached ? Constants.DEFAULT_RESPONSE_TIMEOUT : config.ResponseTimeout;
                this.localAddress = ClusterConfiguration.GetLocalIPAddress(config.PreferredFamily, config.NetInterface);

                // Client init / sign-on message
                logger.Info(ErrorCode.ClientInitializing, string.Format(
                                "{0} Initializing OutsideRuntimeClient on {1} at {2} Client Id = {3} {0}",
                                BARS, config.DNSHostName, localAddress, handshakeClientId));
                string startMsg = string.Format("{0} Starting OutsideRuntimeClient with runtime Version='{1}' in AppDomain={2}",
                                                BARS, RuntimeVersion.Current, PrintAppDomainDetails());
                startMsg = string.Format("{0} Config= " + Environment.NewLine + " {1}", startMsg, config);
                logger.Info(ErrorCode.ClientStarting, startMsg);

                if (TestOnlyThrowExceptionDuringInit)
                {
                    throw new InvalidOperationException("TestOnlyThrowExceptionDuringInit");
                }

                this.gatewayListProvider = this.ServiceProvider.GetRequiredService <IGatewayListProvider>();
                if (StatisticsCollector.CollectThreadTimeTrackingStats)
                {
                    incomingMessagesThreadTimeTracking = new ThreadTrackingStatistic("ClientReceiver");
                }
            }
            catch (Exception exc)
            {
                if (logger != null)
                {
                    logger.Error(ErrorCode.Runtime_Error_100319, "OutsideRuntimeClient constructor failed.", exc);
                }
                ConstructorReset();
                throw;
            }
        }