/// <summary>
        /// Disposes this instance.
        /// </summary>
        public void Dispose()
        {
            if (this.target != null)
            {
                this.outer.ConnectionListener.OnClose(this.target);
                RabbitUtils.CloseConnection(this.target);
            }

            this.target = null;
        }
        /// <summary>Create a new channel, using an internally allocated channel number.</summary>
        /// <param name="transactional">Transactional true if the channel should support transactions.</param>
        /// <returns>A new channel descriptor, or null if none is available.</returns>
        public IModel CreateChannel(bool transactional)
        {
            if (!this.IsOpen())
            {
                lock (this)
                {
                    if (!this.IsOpen())
                    {
                        Logger.Debug("Detected closed connection. Opening a new one before creating Channel.");
                        this.target = this.outer.CreateBareConnection();
                        this.outer.ConnectionListener.OnCreate(this.target);
                    }
                }
            }

            var channel = this.target.CreateChannel(transactional);
            this.outer.ChannelListener.OnCreate(channel, transactional);
            return channel;
        }
        /// <summary>Create a new channel, using an internally allocated channel number.</summary>
        /// <param name="transactional">Transactional true if the channel should support transactions.</param>
        /// <returns>A new channel descriptor, or null if none is available.</returns>
        public IModel CreateChannel(bool transactional)
        {
            if (!this.IsOpen())
            {
                lock (this)
                {
                    if (!this.IsOpen())
                    {
                        Logger.Debug("Detected closed connection. Opening a new one before creating Channel.");
                        this.target = this.outer.CreateBareConnection();
                        this.outer.ConnectionListener.OnCreate(this.target);
                    }
                }
            }

            var channel = this.target.CreateChannel(transactional);

            this.outer.ChannelListener.OnCreate(channel, transactional);
            return(channel);
        }
Ejemplo n.º 4
0
        /// <summary>Actions to perform on create.</summary>
        /// <param name="connection">The connection.</param>
        public void OnCreate(IConnection connection)
        {
            if (!this.initializing.CompareAndSet(false, true))
            {
                // If we are already initializing, we don't need to do it again...
                return;
            }

            try
            {
                /*
                 * ...but it is possible for this to happen twice in the same ConnectionFactory (if more than
                 * one concurrent Connection is allowed). It's idempotent, so no big deal (a bit of network
                 * chatter). In fact it might even be a good thing: exclusive queues only make sense if they are
                 * declared for every connection. If anyone has a problem with it: use auto-startup="false".
                 */
                this.outer.Initialize();
            }
            finally
            {
                this.initializing.CompareAndSet(true, false);
            }
        }
        /// <summary>
        /// Disposes this instance.
        /// </summary>
        public void Dispose()
        {
            if (this.target != null)
            {
                this.outer.ConnectionListener.OnClose(this.target);
                RabbitUtils.CloseConnection(this.target);
            }

            this.target = null;
        }
 /// <summary>Initializes a new instance of the <see cref="SharedConnectionProxy"/> class.</summary>
 /// <param name="target">The target.</param>
 /// <param name="outer">The outer.</param>
 public SharedConnectionProxy(IConnection target, SingleConnectionFactory outer)
 {
     this.target = target;
     this.outer = outer;
 }
Ejemplo n.º 7
0
 /// <summary>Actions to perform on close.</summary>
 /// <param name="connection">The connection.</param>
 public void OnClose(IConnection connection)
 {
 }
 /// <summary>Initializes a new instance of the <see cref="CloseConnectionListener"/> class.</summary>
 /// <param name="connection">The connection.</param>
 /// <param name="latch">The latch.</param>
 public CloseConnectionListener(IConnectionProxy connection, CountdownEvent latch)
 {
     this.connection = connection.GetTargetConnection();
     this.latch = latch;
 }
 /// <summary>Initializes a new instance of the <see cref="CloseConnectionListener"/> class.</summary>
 /// <param name="connection">The connection.</param>
 /// <param name="latch">The latch.</param>
 public CloseConnectionListener(IConnectionProxy connection, CountdownEvent latch)
 {
     this.connection = connection.GetTargetConnection();
     this.latch      = latch;
 }
 /// <summary>Initializes a new instance of the <see cref="SharedConnectionProxy"/> class.</summary>
 /// <param name="target">The target.</param>
 /// <param name="outer">The outer.</param>
 public SharedConnectionProxy(IConnection target, SingleConnectionFactory outer)
 {
     this.target = target;
     this.outer  = outer;
 }
Ejemplo n.º 11
0
 /// <summary>Actions to perform on close.</summary>
 /// <param name="connection">The connection.</param>
 public void OnClose(IConnection connection) { }
Ejemplo n.º 12
0
        /// <summary>Actions to perform on create.</summary>
        /// <param name="connection">The connection.</param>
        public void OnCreate(IConnection connection)
        {
            if (!this.initializing.CompareAndSet(false, true))
            {
                // If we are already initializing, we don't need to do it again...
                return;
            }

            try
            {
                /*
                 * ...but it is possible for this to happen twice in the same ConnectionFactory (if more than
                 * one concurrent Connection is allowed). It's idempotent, so no big deal (a bit of network
                 * chatter). In fact it might even be a good thing: exclusive queues only make sense if they are
                 * declared for every connection. If anyone has a problem with it: use auto-startup="false".
                 */
                this.outer.Initialize();
            }
            finally
            {
                this.initializing.CompareAndSet(true, false);
            }
        }