/// <inheritdoc />
        public override void UpdateChannelState(ChannelState state)
        {
            if (state.Status.StatusCode != StatusCode.OK)
            {
                ResolverError(state.Status);
                return;
            }
            if (state.Addresses == null || state.Addresses.Count == 0)
            {
                ResolverError(new Status(StatusCode.Unavailable, "Resolver returned no addresses."));
                return;
            }

            if (_subchannel == null)
            {
                try
                {
                    _subchannel = _controller.CreateSubchannel(new SubchannelOptions(state.Addresses));
                    _subchannel.OnStateChanged(s => UpdateSubchannelState(_subchannel, s));
                }
                catch (Exception ex)
                {
                    var picker = new ErrorPicker(new Status(StatusCode.Unavailable, "Error creating subchannel.", ex));
                    _controller.UpdateState(new BalancerState(ConnectivityState.TransientFailure, picker));
                    throw;
                }

                _controller.UpdateState(new BalancerState(ConnectivityState.Idle, EmptyPicker.Instance));
                _subchannel.RequestConnection();
            }
            else
            {
                _subchannel.UpdateAddresses(state.Addresses);
            }
        }
Exemple #2
0
        public Subchannel CreateSubchannel(SubchannelOptions options)
        {
            var subchannel = _controller.CreateSubchannel(options);

            subchannel.OnStateChanged(s => OnSubchannelStateChanged(subchannel, s));
            _subchannels.Add(subchannel);

            NotifySubscribers();

            return(subchannel);
        }
        public Subchannel CreateSubchannel(SubchannelOptions options)
        {
            var subchannel = _controller.CreateSubchannel(options);

            subchannel.OnStateChanged(s => OnSubchannelStateChanged(subchannel, s));
            _subchannels.Add(new ReportedSubchannelState(subchannel, ConnectivityState.Idle));

            NotifySubscribers();

            return(subchannel);
        }