PrePush() приватный Метод

private PrePush ( object expectedOwner ) : void
expectedOwner object
Результат void
Пример #1
0
        private PooledStream Create(CreateConnectionDelegate createConnectionCallback)
        {
            PooledStream stream = null;

            try
            {
                stream = createConnectionCallback(this);
                if (stream == null)
                {
                    throw new InternalException();
                }
                if (!stream.CanBePooled)
                {
                    throw new InternalException();
                }
                stream.PrePush(null);
                lock (this.m_ObjectList.SyncRoot)
                {
                    this.m_ObjectList.Add(stream);
                    this.m_TotalObjects = this.m_ObjectList.Count;
                }
            }
            catch (Exception exception)
            {
                stream          = null;
                this.m_ResError = exception;
                this.Abort();
            }
            return(stream);
        }
Пример #2
0
        /// <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);
            }
        }
Пример #3
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);
     }
 }
        /// <summary>
        ///    <para>Creates a new PooledStream, performs checks as well on the new stream</para>
        /// </summary>
        private PooledStream Create(CreateConnectionDelegate createConnectionCallback)
        {
            GlobalLog.Enter("ConnectionPool#" + ValidationHelper.HashString(this) + "::Create");
            PooledStream newObj = null;

            try {
                newObj = createConnectionCallback(this);

                if (null == newObj)
                {
                    throw new InternalException();    // Create succeeded, but null object
                }
                if (!newObj.CanBePooled)
                {
                    throw new InternalException();    // Create succeeded, but non-poolable object
                }
                newObj.PrePush(null);

                lock (m_ObjectList.SyncRoot) {
                    m_ObjectList.Add(newObj);
                    m_TotalObjects = m_ObjectList.Count;
                }

                GlobalLog.Print("Create pooledStream#" + ValidationHelper.HashString(newObj));
            }
            catch (Exception e)  {
                GlobalLog.Print("Pool Exception: " + e.Message);

                newObj = null; // set to null, so we do not return bad new object
                // Failed to create instance
                m_ResError = e;
                Abort();
            }
            catch {
                GlobalLog.Print("Pool Exception: Non-CLS Compliant Exception");

                newObj = null; // set to null, so we do not return bad new object
                // Failed to create instance
                m_ResError = new Exception(SR.GetString(SR.net_nonClsCompliantException));
                Abort();
            }
            GlobalLog.Leave("ConnectionPool#" + ValidationHelper.HashString(this) + "::Create", ValidationHelper.HashString(newObj));
            return(newObj);
        }
        /// <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);
     }
 }