示例#1
0
文件: Producer.cs 项目: forki/Contour
        private void InternalStop(OperationStopReason reason)
        {
            try
            {
                this.logger.Trace($"Stopping producer of [{this.Label}]");
                this.slimLock.EnterWriteLock();

                this.cancellationTokenSource.Cancel(true);
                this.confirmationTracker?.Dispose();

                try
                {
                    this.Channel.Shutdown -= this.OnChannelShutdown;
                    this.Channel?.Dispose();
                }
                catch (Exception)
                {
                    // Any channel/model disposal exceptions are suppressed
                }

                this.Stopped(this, new ProducerStoppedEventArgs(this, reason));
                this.logger.Trace($"Producer of [{this.Label}] stopped successfully");
            }
            finally
            {
                try
                {
                    this.slimLock.ExitWriteLock();
                }
                catch (Exception)
                {
                    // Suppress all errors
                }
            }
        }
示例#2
0
        private void InternalStop(OperationStopReason reason)
        {
            lock (this.syncRoot)
            {
                if (!this.isConsuming)
                {
                    return;
                }

                this.isConsuming = false;
                this.logger.InfoFormat("Stopping consuming on [{0}].", this.endpoint.ListeningSource);

                this.cancellationTokenSource.Cancel(true);

                Task worker;
                while (this.workers.TryTake(out worker))
                {
                    try
                    {
                        worker.Wait();
                        worker.Dispose();
                    }
                    catch (Exception)
                    {
                        // May catch OperationCanceledExceptions here on Task.Wait()
                    }
                }

                RabbitChannel channel;
                while (this.channels.TryTake(out channel))
                {
                    try
                    {
                        channel.Shutdown -= this.OnChannelShutdown;
                        channel.Dispose();
                    }
                    catch (Exception)
                    {
                        // Any channel/model disposal exceptions are suppressed
                    }
                }

                this.ticketTimer.Dispose();
                this.expectations.Values.ForEach(e => e.Cancel());

                this.Stopped(this, new ListenerStoppedEventArgs(this, reason));
                this.logger.Trace("Listener stopped successfully");
            }
        }
示例#3
0
 public ProducerStoppedEventArgs(IProducer producer, OperationStopReason reason)
 {
     this.Producer = producer;
     this.Reason   = reason;
 }
 public ListenerStoppedEventArgs(IListener listener, OperationStopReason reason)
 {
     this.Listener = listener;
     this.Reason   = reason;
 }