RejectRequestNowSinceServerIsBusy() private method

private RejectRequestNowSinceServerIsBusy ( ) : void
return void
Example #1
0
        // reject all requests
        internal void Drain()
        {
            _draining = true;
            // wait for all work items to finish
            while (_workItemCount > 0)
            {
                Thread.Sleep(100);
            }

            // is queue empty?
            if (_count == 0)
            {
                return;
            }

            for (;;)
            {
                SocketHandler sh = DequeueRequest(false);
                if (sh == null)
                {
                    break;
                }
                sh.RejectRequestNowSinceServerIsBusy();
            }
        }
Example #2
0
        } // ProcessNextRequest

        // method called when data arrives for incoming requests
        internal SocketHandler GetRequestToExecute(SocketHandler sh)
        {
            int workerThreads, ioThreads;

            ThreadPool.GetAvailableThreads(out workerThreads, out ioThreads);
            int freeThreads = (ioThreads > workerThreads) ? workerThreads : ioThreads;

            // fast path when there are threads available and nothing queued
            if (freeThreads >= _minExternFreeThreads && _count == 0)
            {
                return(sh);
            }

            bool isLocal = IsLocal(sh);

            // fast path when there are threads for local requests available and nothing queued
            if (isLocal && freeThreads >= _minLocalFreeThreads && _count == 0)
            {
                return(sh);
            }

            // reject if queue limit exceeded
            if (_count >= _queueLimit)
            {
                sh.RejectRequestNowSinceServerIsBusy();
                return(null);
            }

            // can't execute the current request on the current thread -- need to queue
            QueueRequest(sh, isLocal);

            // maybe can execute a request previously queued
            if (freeThreads >= _minExternFreeThreads)
            {
                sh = DequeueRequest(false); // enough threads to process even external requests
            }
            else if (freeThreads >= _minLocalFreeThreads)
            {
                sh = DequeueRequest(true);  // enough threads to process only local requests
            }
            else
            {
                sh = null;
            }

            if (sh == null)                 // not enough threads -> do nothing on this thread
            {
                ScheduleMoreWorkIfNeeded(); // try to schedule to worker thread
            }

            return(sh);
        }
Example #3
0
        internal SocketHandler GetRequestToExecute(SocketHandler sh)
        {
            int num;
            int num2;

            ThreadPool.GetAvailableThreads(out num, out num2);
            int num3 = (num2 > num) ? num : num2;

            if ((num3 < this._minExternFreeThreads) || (this._count != 0))
            {
                bool isLocal = IsLocal(sh);
                if ((isLocal && (num3 >= this._minLocalFreeThreads)) && (this._count == 0))
                {
                    return(sh);
                }
                if (this._count >= this._queueLimit)
                {
                    sh.RejectRequestNowSinceServerIsBusy();
                    return(null);
                }
                this.QueueRequest(sh, isLocal);
                if (num3 >= this._minExternFreeThreads)
                {
                    sh = this.DequeueRequest(false);
                }
                else if (num3 >= this._minLocalFreeThreads)
                {
                    sh = this.DequeueRequest(true);
                }
                else
                {
                    sh = null;
                }
                if (sh == null)
                {
                    this.ScheduleMoreWorkIfNeeded();
                }
            }
            return(sh);
        }
 internal SocketHandler GetRequestToExecute(SocketHandler sh)
 {
     int num;
     int num2;
     ThreadPool.GetAvailableThreads(out num, out num2);
     int num3 = (num2 > num) ? num : num2;
     if ((num3 < this._minExternFreeThreads) || (this._count != 0))
     {
         bool isLocal = IsLocal(sh);
         if ((isLocal && (num3 >= this._minLocalFreeThreads)) && (this._count == 0))
         {
             return sh;
         }
         if (this._count >= this._queueLimit)
         {
             sh.RejectRequestNowSinceServerIsBusy();
             return null;
         }
         this.QueueRequest(sh, isLocal);
         if (num3 >= this._minExternFreeThreads)
         {
             sh = this.DequeueRequest(false);
         }
         else if (num3 >= this._minLocalFreeThreads)
         {
             sh = this.DequeueRequest(true);
         }
         else
         {
             sh = null;
         }
         if (sh == null)
         {
             this.ScheduleMoreWorkIfNeeded();
         }
     }
     return sh;
 }
Example #5
0
        } // ProcessNextRequest
        

        // method called when data arrives for incoming requests
        internal SocketHandler GetRequestToExecute(SocketHandler sh) {
            int workerThreads, ioThreads;
            ThreadPool.GetAvailableThreads(out workerThreads, out ioThreads);
            int freeThreads = (ioThreads > workerThreads) ? workerThreads : ioThreads;

            // fast path when there are threads available and nothing queued
            if (freeThreads >= _minExternFreeThreads && _count == 0)
                return sh;

            bool isLocal = IsLocal(sh);

            // fast path when there are threads for local requests available and nothing queued
            if (isLocal && freeThreads >= _minLocalFreeThreads && _count == 0)
                return sh;

            // reject if queue limit exceeded
            if (_count >= _queueLimit) {
                sh.RejectRequestNowSinceServerIsBusy();
                return null;
            }

            // can't execute the current request on the current thread -- need to queue
            QueueRequest(sh, isLocal);

            // maybe can execute a request previously queued
            if (freeThreads >= _minExternFreeThreads) {
                sh = DequeueRequest(false); // enough threads to process even external requests
            }
            else if (freeThreads >= _minLocalFreeThreads) {
                sh = DequeueRequest(true);  // enough threads to process only local requests
            }
            else{
                sh = null;
            }

            if (sh == null){                  // not enough threads -> do nothing on this thread
                ScheduleMoreWorkIfNeeded(); // try to schedule to worker thread
            }

            return sh;
        }