private HttpWorkerRequest DequeueRequest(bool localOnly)
        {
            HttpWorkerRequest wr = null;

            while (_count > 0)
            {
                lock (this) {
                    if (_localQueue.Count > 0)
                    {
                        wr = (HttpWorkerRequest)_localQueue.Dequeue();
                        _count--;
                    }
                    else if (!localOnly && _externQueue.Count > 0)
                    {
                        wr = (HttpWorkerRequest)_externQueue.Dequeue();
                        _count--;
                    }
                }

                if (wr == null)
                {
                    break;
                }
                else
                {
                    PerfCounters.DecrementGlobalCounter(GlobalPerfCounter.REQUESTS_QUEUED);
                    PerfCounters.DecrementCounter(AppPerfCounter.REQUESTS_IN_APPLICATION_QUEUE);
                    if (EtwTrace.IsTraceEnabled(EtwTraceLevel.Information, EtwTraceFlags.Infrastructure))
                    {
                        EtwTrace.Trace(EtwTraceType.ETW_TYPE_REQ_DEQUEUED, wr);
                    }

                    if (!CheckClientConnected(wr))
                    {
                        HttpRuntime.RejectRequestNow(wr, true);
                        wr = null;

                        PerfCounters.IncrementGlobalCounter(GlobalPerfCounter.REQUESTS_DISCONNECTED);
                        PerfCounters.IncrementCounter(AppPerfCounter.APP_REQUEST_DISCONNECTED);
                    }
                    else
                    {
                        break;
                    }
                }
            }

            return(wr);
        }
 private void QueueRequest(HttpWorkerRequest wr, bool isLocal)
 {
     lock (this)
     {
         if (isLocal)
         {
             this._localQueue.Enqueue(wr);
         }
         else
         {
             this._externQueue.Enqueue(wr);
         }
         this._count++;
     }
     PerfCounters.IncrementGlobalCounter(GlobalPerfCounter.REQUESTS_QUEUED);
     PerfCounters.IncrementCounter(AppPerfCounter.REQUESTS_IN_APPLICATION_QUEUE);
     if (EtwTrace.IsTraceEnabled(4, 1))
     {
         EtwTrace.Trace(EtwTraceType.ETW_TYPE_REQ_QUEUED, wr);
     }
 }
        private HttpWorkerRequest DequeueRequest(bool localOnly)
        {
            HttpWorkerRequest workerRequest = null;

            while (this._count > 0)
            {
                lock (this)
                {
                    if (this._localQueue.Count > 0)
                    {
                        workerRequest = (HttpWorkerRequest)this._localQueue.Dequeue();
                        this._count--;
                    }
                    else if (!localOnly && (this._externQueue.Count > 0))
                    {
                        workerRequest = (HttpWorkerRequest)this._externQueue.Dequeue();
                        this._count--;
                    }
                }
                if (workerRequest == null)
                {
                    return(workerRequest);
                }
                PerfCounters.DecrementGlobalCounter(GlobalPerfCounter.REQUESTS_QUEUED);
                PerfCounters.DecrementCounter(AppPerfCounter.REQUESTS_IN_APPLICATION_QUEUE);
                if (EtwTrace.IsTraceEnabled(4, 1))
                {
                    EtwTrace.Trace(EtwTraceType.ETW_TYPE_REQ_DEQUEUED, workerRequest);
                }
                if (this.CheckClientConnected(workerRequest))
                {
                    return(workerRequest);
                }
                HttpRuntime.RejectRequestNow(workerRequest, true);
                workerRequest = null;
                PerfCounters.IncrementGlobalCounter(GlobalPerfCounter.REQUESTS_DISCONNECTED);
                PerfCounters.IncrementCounter(AppPerfCounter.APP_REQUEST_DISCONNECTED);
            }
            return(workerRequest);
        }
        private void QueueRequest(HttpWorkerRequest wr, bool isLocal)
        {
            lock (this) {
                if (isLocal)
                {
                    _localQueue.Enqueue(wr);
                }
                else
                {
                    _externQueue.Enqueue(wr);
                }

                _count++;
            }

            PerfCounters.IncrementGlobalCounter(GlobalPerfCounter.REQUESTS_QUEUED);
            PerfCounters.IncrementCounter(AppPerfCounter.REQUESTS_IN_APPLICATION_QUEUE);
            if (EtwTrace.IsTraceEnabled(EtwTraceLevel.Information, EtwTraceFlags.Infrastructure))
            {
                EtwTrace.Trace(EtwTraceType.ETW_TYPE_REQ_QUEUED, wr);
            }
        }
Exemple #5
0
        internal object GetPartition(IPartitionResolver partitionResolver, string id)
        {
            if (EtwTrace.IsTraceEnabled(EtwTraceLevel.Verbose, EtwTraceFlags.Infrastructure))
            {
                EtwTrace.Trace(EtwTraceType.ETW_TYPE_SESSIONSTATE_PARTITION_START, HttpContext.Current.WorkerRequest, partitionResolver.GetType().FullName, id);
            }

            string         partitionString = null;
            string         errorMessage    = null;
            IPartitionInfo partitionInfo   = null;

            try {
                try {
                    partitionString = partitionResolver.ResolvePartition(id);

                    if (partitionString == null)
                    {
                        throw new HttpException(
                                  SR.GetString(SR.Bad_partition_resolver_connection_string, partitionResolver.GetType().FullName));
                    }
                }
                catch (Exception e) {
                    errorMessage = e.Message;
                    throw;
                }

                try {
                    _lock.AcquireReaderLock(-1);
                    partitionInfo = (IPartitionInfo)_partitions[partitionString];
                    if (partitionInfo != null)
                    {
                        Debug.Trace("PartitionManager", "id=" + id + "; partitionString=" + partitionString);
                        return(partitionInfo);
                    }
                }
                finally {
                    if (_lock.IsReaderLockHeld)
                    {
                        _lock.ReleaseReaderLock();
                    }
                }

                // Not found.  Has to add it.
                try {
                    _lock.AcquireWriterLock(-1);
                    // One more time
                    partitionInfo = (IPartitionInfo)_partitions[partitionString];
                    if (partitionInfo == null)
                    {
                        partitionInfo = _createCallback(partitionString);

                        Debug.Trace("PartitionManager", "Add a new partition; id=" + id + "; partitionString=" + partitionString);
                        _partitions.Add(partitionString, partitionInfo);
                    }

                    Debug.Trace("PartitionManager", "id=" + id + "; partitionString=" + partitionString);
                    return(partitionInfo);
                }
                finally {
                    if (_lock.IsWriterLockHeld)
                    {
                        _lock.ReleaseWriterLock();
                    }
                }
            }
            finally {
                if (EtwTrace.IsTraceEnabled(EtwTraceLevel.Verbose, EtwTraceFlags.Infrastructure))
                {
                    string msg = errorMessage;
                    if (msg == null)
                    {
                        if (partitionInfo != null)
                        {
                            msg = partitionInfo.GetTracingPartitionString();
                        }
                        else
                        {
                            msg = String.Empty;
                        }
                    }
                    EtwTrace.Trace(EtwTraceType.ETW_TYPE_SESSIONSTATE_PARTITION_END, HttpContext.Current.WorkerRequest, msg);
                }
            }
        }
Exemple #6
0
        internal object GetPartition(IPartitionResolver partitionResolver, string id)
        {
            object obj2;

            if (EtwTrace.IsTraceEnabled(5, 1))
            {
                EtwTrace.Trace(EtwTraceType.ETW_TYPE_SESSIONSTATE_PARTITION_START, HttpContext.Current.WorkerRequest, partitionResolver.GetType().FullName, id);
            }
            string         connectionString = null;
            string         message          = null;
            IPartitionInfo info             = null;

            try
            {
                try
                {
                    connectionString = partitionResolver.ResolvePartition(id);
                    if (connectionString == null)
                    {
                        throw new HttpException(System.Web.SR.GetString("Bad_partition_resolver_connection_string", new object[] { partitionResolver.GetType().FullName }));
                    }
                }
                catch (Exception exception)
                {
                    message = exception.Message;
                    throw;
                }
                try
                {
                    this._lock.AcquireReaderLock(-1);
                    info = (IPartitionInfo)this._partitions[connectionString];
                    if (info != null)
                    {
                        return(info);
                    }
                }
                finally
                {
                    if (this._lock.IsReaderLockHeld)
                    {
                        this._lock.ReleaseReaderLock();
                    }
                }
                try
                {
                    this._lock.AcquireWriterLock(-1);
                    info = (IPartitionInfo)this._partitions[connectionString];
                    if (info == null)
                    {
                        info = this._createCallback(connectionString);
                        this._partitions.Add(connectionString, info);
                    }
                    return(info);
                }
                finally
                {
                    if (this._lock.IsWriterLockHeld)
                    {
                        this._lock.ReleaseWriterLock();
                    }
                }
            }
            finally
            {
                if (EtwTrace.IsTraceEnabled(5, 1))
                {
                    string tracingPartitionString = message;
                    if (tracingPartitionString == null)
                    {
                        if (info != null)
                        {
                            tracingPartitionString = info.GetTracingPartitionString();
                        }
                        else
                        {
                            tracingPartitionString = string.Empty;
                        }
                    }
                    EtwTrace.Trace(EtwTraceType.ETW_TYPE_SESSIONSTATE_PARTITION_END, HttpContext.Current.WorkerRequest, tracingPartitionString);
                }
            }
            return(obj2);
        }