Exemplo n.º 1
0
        private RemoteHostPool CreatePool(
            ServiceDeployment serviceDeployment,
            List <IDisposable> blockLinks,
            ServiceDiscoverySourceBase discoverySource)
        {
            var result = _remoteHostPoolFactory.Create(serviceDeployment, discoverySource, _reachabilityChecker);

            var dispose = result.EndPointsChanged.LinkTo(new ActionBlock <EndPointsResult>(m =>
            {
                if (result == MasterEnvironmentPool || result == OriginatingEnvironmentPool)
                {
                    FireEndPointChange();
                }
            }));

            blockLinks.Add(dispose);

            dispose = result.ReachabilitySource.LinkTo(new ActionBlock <ServiceReachabilityStatus>(x =>
            {
                if (result == _activePool && !_suppressNotifications)
                {
                    _reachabilityChanged.Post(x);
                }
            }));
            blockLinks.Add(dispose);



            return(result);
        }
Exemplo n.º 2
0
        private async Task ReloadRemoteHost(DiscoveryConfig newConfig)
        {
            var newServiceConfig = newConfig.Services[_serviceName];

            lock (_locker)
            {
                if (newServiceConfig.Equals(LastServiceConfig) &&
                    newConfig.EnvironmentFallbackEnabled == LastConfig.EnvironmentFallbackEnabled)
                {
                    return;
                }
            }

            var shouldCreateMasterPool = newConfig.EnvironmentFallbackEnabled &&
                                         newServiceConfig.SupportsFallback &&
                                         _originatingDeployment.Equals(_masterDeployment) == false;

            ServiceDiscoverySourceBase masterSource = null;

            var originatingSource = await GetServiceDiscoverySource(_originatingDeployment, newServiceConfig).ConfigureAwait(false);

            if (shouldCreateMasterPool)
            {
                masterSource = await GetServiceDiscoverySource(_masterDeployment, newServiceConfig).ConfigureAwait(false);
            }

            lock (_locker)
            {
                _suppressNotifications = true;

                LastConfig        = newConfig;
                LastServiceConfig = newServiceConfig;

                RemoveOriginatingPool();
                OriginatingEnvironmentPool = CreatePool(_originatingDeployment, _originatingEnvironmentLinks, originatingSource);

                RemoveMasterPool();

                if (masterSource != null)
                {
                    MasterEnvironmentPool = CreatePool(_masterDeployment, _masterEnvironmentLinks, masterSource);
                }

                _suppressNotifications = false;

                GetRelevantPool();
            }
        }