Apache.NMS.ActiveMQ.Connection.Close C# (CSharp) Method

Close() public method

public Close ( ) : void
return void
        public void Close()
        {
            if(!this.closed.Value && !transportFailed.Value)
            {
                this.Stop();
            }

            lock(myLock)
            {
                if(this.closed.Value)
                {
                    return;
                }

                try
                {
                    Tracer.Info("Connection.Close(): Closing Connection Now.");
                    this.closing.Value = true;

                    lock(sessions.SyncRoot)
                    {
                        foreach(Session session in sessions)
                        {
                            session.Shutdown();
                        }
                    }
                    sessions.Clear();

                    // Connected is true only when we've successfully sent our ConnectionInfo
                    // to the broker, so if we haven't announced ourselves there's no need to
                    // inform the broker of a remove, and if the transport is failed, why bother.
                    if(connected.Value && !transportFailed.Value)
                    {
                        DisposeOf(ConnectionId);
                        ShutdownInfo shutdowninfo = new ShutdownInfo();
                        transport.Oneway(shutdowninfo);
                    }

                    executor.Shutdown();

                    Tracer.Info("Connection: Disposing of the Transport.");
                    transport.Dispose();
                }
                catch(Exception ex)
                {
                    Tracer.ErrorFormat("Error during connection close: {0}", ex);
                }
                finally
                {
                    if(executor != null)
                    {
                        executor.Shutdown();
                    }

                    this.transport = null;
                    this.closed.Value = true;
                    this.connected.Value = false;
                    this.closing.Value = false;
                }
            }
        }