Deactivate() private method

private Deactivate ( ) : void
return void
        /// <devdoc>
        ///    <para>
        ///    Attempts to return a PooledStream to the pool.  If canReuse is false, then the
        ///    connection will be destroyed even if it is marked as reusable and a new conneciton will
        ///    be created.  If it is true, then the connection will still be checked to ensure that
        ///    it can be pooled and will be cleaned up if it can not for another reason.
        ///    </para>
        /// </devdoc>
        internal void PutConnection(PooledStream pooledStream, object owningObject, int creationTimeout, bool canReuse)
        {
            GlobalLog.Print("ConnectionPool#" + ValidationHelper.HashString(this) + "::PutConnection");
            if (pooledStream == null)
            {
                throw new ArgumentNullException("pooledStream");
            }

            pooledStream.PrePush(owningObject);

            if (m_State != State.ShuttingDown)
            {
                pooledStream.Deactivate();

                // cancel our error status, if we have no new requests waiting anymore
                if (m_WaitCount == 0)
                {
                    CancelErrorCallback();
                }

                if (canReuse && pooledStream.CanBePooled)
                {
                    PutNew(pooledStream);
                }
                else
                {
                    try {
                        Destroy(pooledStream);
                    } finally { // Make sure to release the mutex even under error conditions.
                        // Make sure we recreate a new pooled stream, if there are requests for a stream
                        // at this point
                        if (m_WaitCount > 0)
                        {
                            if (!CreationMutex.WaitOne(creationTimeout, false))
                            {
                                Abort();
                            }
                            else
                            {
                                try {
                                    pooledStream = UserCreateRequest();
                                    if (null != pooledStream)
                                    {
                                        PutNew(pooledStream);
                                    }
                                } finally {
                                    CreationMutex.ReleaseMutex();
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                // If we're shutting down, we destroy the object.
                Destroy(pooledStream);
            }
        }
Beispiel #2
0
 internal void PutConnection(PooledStream pooledStream, object owningObject, int creationTimeout, bool canReuse)
 {
     if (pooledStream == null)
     {
         throw new ArgumentNullException("pooledStream");
     }
     pooledStream.PrePush(owningObject);
     if (this.m_State != State.ShuttingDown)
     {
         pooledStream.Deactivate();
         if (this.m_WaitCount == 0)
         {
             this.CancelErrorCallback();
         }
         if (canReuse && pooledStream.CanBePooled)
         {
             this.PutNew(pooledStream);
         }
         else
         {
             this.Destroy(pooledStream);
             if (this.m_WaitCount > 0)
             {
                 if (!this.CreationMutex.WaitOne(creationTimeout, false))
                 {
                     this.Abort();
                 }
                 else
                 {
                     try
                     {
                         pooledStream = this.UserCreateRequest();
                         if (pooledStream != null)
                         {
                             this.PutNew(pooledStream);
                         }
                     }
                     finally
                     {
                         this.CreationMutex.ReleaseMutex();
                     }
                 }
             }
         }
     }
     else
     {
         this.Destroy(pooledStream);
     }
 }
        /// <devdoc>
        ///    <para>Attempts to return a PooledStream to the pool</para>
        /// </devdoc>
        internal void PutConnection(PooledStream pooledStream, object owningObject, int creationTimeout) {
            GlobalLog.Print("ConnectionPool#" + ValidationHelper.HashString(this) + "::PutConnection");
            if (pooledStream == null) {
                throw new ArgumentNullException("pooledStream");
            }

            pooledStream.PrePush(owningObject);

            if (m_State != State.ShuttingDown) {
                pooledStream.Deactivate();

                // cancel our error status, if we have no new requests waiting anymore
                if (m_WaitCount == 0) {
                    CancelErrorCallback();
                }

                if (pooledStream.CanBePooled) {
                    PutNew(pooledStream);
                }
                else {
                    Destroy(pooledStream);

                    // Make sure we recreate a new pooled stream, if there are requests for a stream
                    // at this point
                    if (m_WaitCount > 0) {
                        if (!CreationMutex.WaitOne(creationTimeout, false)) {
                            Abort();
                        } else {
                            try {
                                pooledStream = UserCreateRequest();
                                if (null != pooledStream) {
                                    PutNew(pooledStream);
                                }
                            } finally {
                                CreationMutex.ReleaseMutex();
                            }
                        }
                    }
                }
            }
            else {
                // If we're shutting down, we destroy the object.
                Destroy(pooledStream);
            }
        }
 internal void PutConnection(PooledStream pooledStream, object owningObject, int creationTimeout, bool canReuse)
 {
     if (pooledStream == null)
     {
         throw new ArgumentNullException("pooledStream");
     }
     pooledStream.PrePush(owningObject);
     if (this.m_State != State.ShuttingDown)
     {
         pooledStream.Deactivate();
         if (this.m_WaitCount == 0)
         {
             this.CancelErrorCallback();
         }
         if (canReuse && pooledStream.CanBePooled)
         {
             this.PutNew(pooledStream);
         }
         else
         {
             this.Destroy(pooledStream);
             if (this.m_WaitCount > 0)
             {
                 if (!this.CreationMutex.WaitOne(creationTimeout, false))
                 {
                     this.Abort();
                 }
                 else
                 {
                     try
                     {
                         pooledStream = this.UserCreateRequest();
                         if (pooledStream != null)
                         {
                             this.PutNew(pooledStream);
                         }
                     }
                     finally
                     {
                         this.CreationMutex.ReleaseMutex();
                     }
                 }
             }
         }
     }
     else
     {
         this.Destroy(pooledStream);
     }
 }