예제 #1
0
        public async Task DisableMethodsAsync(TimeSpan timeout)
        {
            Logging.Enter(this, timeout, nameof(DisableMethodsAsync));

            Debug.Assert(_methodSendingLink != null);
            Debug.Assert(_methodReceivingLink != null);

            bool enteredSemaphore = await _methodLinkSemaphore.WaitAsync(timeout).ConfigureAwait(false);

            if (!enteredSemaphore)
            {
                throw new TimeoutException("Failed to enter the semaphore required for ensuring that AMQP method sender and receiver links are closed.");
            }

            try
            {
                ICollection <Task> tasks = new List <Task>();
                if (_methodReceivingLink != null)
                {
                    tasks.Add(_methodReceivingLink.CloseAsync(timeout));
                }

                if (_methodSendingLink != null)
                {
                    tasks.Add(_methodSendingLink.CloseAsync(timeout));
                }

                if (tasks.Count > 0)
                {
                    await Task.WhenAll(tasks).ConfigureAwait(false);

                    _methodReceivingLink = null;
                    _methodSendingLink   = null;
                }
            }
            finally
            {
                Logging.Exit(this, timeout, nameof(DisableMethodsAsync));
                _methodLinkSemaphore.Release();
            }
        }
예제 #2
0
        public async Task DisableMessageReceivingLinkAsync(CancellationToken cancellationToken)
        {
            if (Logging.IsEnabled)
            {
                Logging.Enter(this, nameof(DisableMessageReceivingLinkAsync));
            }

            Debug.Assert(_messageReceivingLink != null);

            try
            {
                await _messageReceivingLinkSemaphore.WaitAsync(cancellationToken).ConfigureAwait(false);
            }
            catch (OperationCanceledException)
            {
                throw new TimeoutException("Failed to enter the semaphore required for ensuring that AMQP message receiver links are closed.");
            }

            // This event handler is in place for network drop cases and will try to close the session that this
            // link belongs to, but that isn't necessary when the client is deliberately closing just the link.
            if (_eventReceiverLinkDisconnected != null)
            {
                _messageReceivingLink.Closed -= _eventReceiverLinkDisconnected;
            }

            try
            {
                await _messageReceivingLink.CloseAsync(cancellationToken).ConfigureAwait(false);
            }
            finally
            {
                _messageReceivingLinkSemaphore.Release();
                if (Logging.IsEnabled)
                {
                    Logging.Exit(this, nameof(DisableMessageReceivingLinkAsync));
                }
            }
        }
예제 #3
0
        public async Task DisableMessageReceivingLinkAsync(TimeSpan timeout)
        {
            Logging.Enter(this, timeout, nameof(DisableMessageReceivingLinkAsync));

            Debug.Assert(_messageReceivingLink != null);

            bool enteredSemaphore = await _messageReceivingLinkSemaphore.WaitAsync(timeout).ConfigureAwait(false);

            if (!enteredSemaphore)
            {
                throw new TimeoutException("Failed to enter the semaphore required for ensuring that AMQP message receiver links are closed.");
            }

            try
            {
                await _messageReceivingLink.CloseAsync(timeout).ConfigureAwait(false);
            }
            finally
            {
                _messageReceivingLinkSemaphore.Release();
                Logging.Exit(this, timeout, nameof(DisableMessageReceivingLinkAsync));
            }
        }
예제 #4
0
        public async Task DisableMethodsAsync(CancellationToken cancellationToken)
        {
            if (Logging.IsEnabled)
            {
                Logging.Enter(this, nameof(DisableMethodsAsync));
            }

            Debug.Assert(_methodSendingLink != null);
            Debug.Assert(_methodReceivingLink != null);

            try
            {
                await _methodLinkSemaphore.WaitAsync(cancellationToken).ConfigureAwait(false);
            }
            catch (OperationCanceledException)
            {
                throw new TimeoutException("Failed to enter the semaphore required for ensuring that AMQP method sender and receiver links are closed.");
            }

            // These event handlers are in place for network drop cases and will try to close the session that this
            // link belongs to, but that isn't necessary when the client is deliberately closing just the link.
            if (_methodReceiverLinkDisconnected != null)
            {
                _methodReceivingLink.Closed -= _methodReceiverLinkDisconnected;
            }

            if (_methodSenderLinkDisconnected != null)
            {
                _methodSendingLink.Closed -= _methodSenderLinkDisconnected;
            }

            try
            {
                ICollection <Task> tasks = new List <Task>(2);
                if (_methodReceivingLink != null)
                {
                    tasks.Add(_methodReceivingLink.CloseAsync(cancellationToken));
                }

                if (_methodSendingLink != null)
                {
                    tasks.Add(_methodSendingLink.CloseAsync(cancellationToken));
                }

                if (tasks.Count > 0)
                {
                    await Task.WhenAll(tasks).ConfigureAwait(false);

                    _methodReceivingLink = null;
                    _methodSendingLink   = null;
                }
            }
            finally
            {
                if (Logging.IsEnabled)
                {
                    Logging.Exit(this, nameof(DisableMethodsAsync));
                }
                _methodLinkSemaphore.Release();
            }
        }