Example #1
0
        private Task TryAcquireCallThrottleAsync(RequestContext request)
        {
            ServiceThrottle throttle = _throttle;

            if ((throttle != null) && (throttle.IsActive))
            {
                return(throttle.AcquireCallAsync());
            }

            return(Task.CompletedTask);
        }
Example #2
0
        private Task TryAcquireThrottleAsync(RequestContext request, bool acquireInstanceContextThrottle)
        {
            ServiceThrottle throttle = _throttle;

            if ((throttle != null) && (throttle.IsActive))
            {
                return(throttle.AcquireInstanceContextAndDynamicAsync(this, acquireInstanceContextThrottle));
            }

            return(Task.CompletedTask);
        }
Example #3
0
        internal ChannelHandler(MessageVersion messageVersion, IChannelBinder binder, ServiceThrottle throttle,
                                ServiceDispatcher serviceDispatcher, bool wasChannelThrottled, SessionIdleManager idleManager)
        {
            ChannelDispatcher channelDispatcher = serviceDispatcher.ChannelDispatcher;

            _serviceDispatcher   = serviceDispatcher;
            _messageVersion      = messageVersion;
            _isManualAddressing  = channelDispatcher.ManualAddressing;
            _binder              = binder;
            _throttle            = throttle;
            _wasChannelThrottled = wasChannelThrottled;
            _host         = channelDispatcher.Host;
            _duplexBinder = binder as DuplexChannelBinder;
            _hasSession   = binder.HasSession;
            _isConcurrent = ConcurrencyBehavior.IsConcurrent(channelDispatcher, _hasSession);

            // TODO: Work out if MultipleReceiveBinder is necessary
            //if (channelDispatcher.MaxPendingReceives > 1)
            //{
            //    // We need to preserve order if the ChannelHandler is not concurrent.
            //    this.binder = new MultipleReceiveBinder(
            //        this.binder,
            //        channelDispatcher.MaxPendingReceives,
            //        !this.isConcurrent);
            //}

            if (channelDispatcher.BufferedReceiveEnabled)
            {
                _binder = new BufferedReceiveBinder(_binder);
            }

            _idleManager = idleManager;

            if (_binder.HasSession)
            {
                _sessionOpenNotification = _binder.Channel.GetProperty <SessionOpenNotification>();
                _needToCreateSessionOpenNotificationMessage = _sessionOpenNotification != null && _sessionOpenNotification.IsEnabled;
            }

            //_requestInfo = new RequestInfo(this);

            // TODO: Wire up lifetime management in place of listener state
            //if (this.listener.State == CommunicationState.Opened)
            //{
            _serviceDispatcher.ChannelDispatcher.Channels.IncrementActivityCount();
            _incrementedActivityCountInConstructor = true;
            //}
        }
Example #4
0
        private async Task HandleReceiveCompleteAsync(RequestContext request)
        {
            // TODO: Add support for needToCreateSessionOpenNotificationMessage, probably in constructor
            try
            {
                if (_channel != null)
                {
                    _channel.HandleReceiveComplete(request);
                }
                else
                {
                    if (request == null && _hasSession)
                    {
                        bool close;
                        lock (ThisLock)
                        {
                            close          = !_doneReceiving;
                            _doneReceiving = true;
                        }

                        if (close)
                        {
                            await CloseBinderAsync();

                            if (_idleManager != null)
                            {
                                _idleManager.CancelTimer();
                            }

                            ServiceThrottle throttle = _throttle;
                            if (throttle != null)
                            {
                                throttle.DeactivateChannel();
                            }
                        }
                    }
                }
            }
            finally
            {
                if ((request == null) && _incrementedActivityCountInConstructor)
                {
                    _serviceDispatcher.ChannelDispatcher.Channels.DecrementActivityCount();
                }
            }
        }
Example #5
0
        private async Task HandleReceiveCompleteAsync(RequestContext request)
        {
            try
            {
                if (_channel != null)
                {
                    _channel.HandleReceiveComplete(request);
                }
                else
                {
                    if (request == null && _hasSession)
                    {
                        bool close;
                        await using (await _thisLock.TakeLockAsync())
                        {
                            close          = !_doneReceiving;
                            _doneReceiving = true;
                        }

                        if (close)
                        {
                            await CloseBinderAsync();

                            if (_idleManager != null)
                            {
                                _idleManager.CancelTimer();
                            }

                            ServiceThrottle throttle = _throttle;
                            if (throttle != null)
                            {
                                throttle.DeactivateChannel();
                            }
                        }
                    }
                }
            }
            finally
            {
                if ((request == null) && _incrementedActivityCountInConstructor)
                {
                    _serviceDispatcher.ChannelDispatcher.Channels.DecrementActivityCount();
                }
            }
        }