Example #1
0
        private void UpdateSubchannelState(Subchannel subchannel, SubchannelState state)
        {
            var index = FindSubchannel(_addressSubchannels, subchannel);

            if (index == null)
            {
                SubchannelsLoadBalancerLog.IgnoredSubchannelStateChange(_logger, subchannel.Id);
                return;
            }

            SubchannelsLoadBalancerLog.ProcessingSubchannelStateChanged(_logger, subchannel.Id, state.State, state.Status);

            UpdateBalancingState(state.Status);

            if (state.State == ConnectivityState.TransientFailure || state.State == ConnectivityState.Idle)
            {
                SubchannelsLoadBalancerLog.RefreshingResolverForSubchannel(_logger, subchannel.Id, state.State);
                Controller.RefreshResolver();
            }
            if (state.State == ConnectivityState.Idle)
            {
                SubchannelsLoadBalancerLog.RequestingConnectionForSubchannel(_logger, subchannel.Id, state.State);
                subchannel.RequestConnection();
            }
        }
Example #2
0
        internal void RaiseStateChanged(ConnectivityState state, Status status)
        {
            SubchannelLog.SubchannelStateChanged(_logger, Id, state, status);

            if (_stateChangedRegistrations.Count > 0)
            {
                var subchannelState = new SubchannelState(state, status);
                foreach (var registration in _stateChangedRegistrations)
                {
                    registration.Invoke(subchannelState);
                }
            }
        }
        private void UpdateSubchannelState(Subchannel subchannel, SubchannelState state)
        {
            if (_subchannel != subchannel)
            {
                PickFirstBalancerLog.IgnoredSubchannelStateChange(_logger, subchannel.Id);
                return;
            }

            PickFirstBalancerLog.ProcessingSubchannelStateChanged(_logger, subchannel.Id, state.State, state.Status);

            switch (state.State)
            {
            case ConnectivityState.Ready:
                UpdateChannelState(state.State, new PickFirstPicker(_subchannel));
                break;

            case ConnectivityState.Idle:
                _controller.RefreshResolver();

                // Pick first load balancer waits until a request is made before establishing a connection.
                // Return picker that will request a connection on pick.
                UpdateChannelState(state.State, new RequestConnectionPicker(_subchannel));
                break;

            case ConnectivityState.Connecting:
                UpdateChannelState(state.State, EmptyPicker.Instance);
                break;

            case ConnectivityState.TransientFailure:
                UpdateChannelState(state.State, new ErrorPicker(state.Status));
                break;

            case ConnectivityState.Shutdown:
                UpdateChannelState(state.State, EmptyPicker.Instance);
                _subchannel = null;
                break;
            }
        }
Example #4
0
 public void Invoke(SubchannelState state)
 {
     _callback(state);
 }