Ejemplo n.º 1
0
        /// <summary>
        /// Closes an AMQP object asynchronously.
        /// </summary>
        /// <param name="amqpObject">The object to close.</param>
        /// <param name="timeout">The timeout in seconds.</param>
        /// <returns></returns>
        public static Task CloseAsync(this AmqpObject amqpObject, int timeout = 60000)
        {
            TaskCompletionSource <object> tcs = new TaskCompletionSource <object>();

            try
            {
                amqpObject.Closed += (o, e) =>
                {
                    if (e != null)
                    {
                        tcs.SetException(new AmqpException(e));
                    }
                    else
                    {
                        tcs.SetResult(null);
                    }
                };

                amqpObject.Close(0);
            }
            catch (Exception exception)
            {
                tcs.SetException(exception);
            }

            return(tcs.Task);
        }
Ejemplo n.º 2
0
 private void Sender_Closed(AmqpObject sender, Amqp.Framing.Error error)
 {
     if (!_closing)
     {
         var senderLink = (SenderLink) sender;
         var key =
             _senders.ToArray().Where(pair => pair.Value == senderLink).Select(pair => pair.Key).FirstOrDefault();
         if (key != null)
         {
             SenderLink returnedLink;
             _senders.TryRemove(key, out returnedLink);
         }
     }
 }
Ejemplo n.º 3
0
        void OnControllerClosed(AmqpObject obj, Error error)
        {
            var controller = (Controller)obj;
            bool removed;
            lock (this.SyncRoot)
            {
                removed = this.controllers.Remove(controller.Session.Connection);
            }

            if (removed)
            {
                controller.Session.Close(0);
            }
        }
Ejemplo n.º 4
0
 void OnLinkClosed(AmqpObject sender, Error error)
 {
     Console.WriteLine("A client has disconnected.");
     this.timer.Dispose();
 }
        /// <summary>
        /// Event handler that fires when an AMQP connection is closed.
        /// </summary>
        /// <param name="sender">
        /// The AMQP connection that is propogating the closed event.
        /// </param>
        /// <param name="error">
        /// The AMQP <see cref="Error"/> event that caused the connection to close (if one exists). 
        /// </param>
        private void OnClosedConnection(AmqpObject sender, Error error)
        {
            m_Logger.Debug("Connection detected as being closed.");

            Disconnect();
            if (m_OnClosedConnection != null)
            {
                m_OnClosedConnection(this, EventArgs.Empty);
            }
        }