コード例 #1
0
        private void ProcessPersistantQueue()
        {
            int numDurableRequestsProcessed = 0;

            if (!DurableQueueRunning || _durableQueuePaused || _persistantQueue.Count == 0 || _connections.Count == 0 ||
                !Available || _durableDrainTimer >= DateTime.Now.Ticks)
            {
                return;
            }

            _durableDrainTimer = DateTime.Now.AddMilliseconds(DurableDrainInterval).Ticks;

            for (LinkedListNode <GSRequest> node = _persistantQueue.First; node != _persistantQueue.Last.Next; node = node.Next)
            {
                GSRequest request = node.Value;

                if (request.RequestExpiresAt >= DateTime.Now.Ticks)
                {
                    numDurableRequestsProcessed++;
                }
            }

            for (LinkedListNode <GSRequest> node = _persistantQueue.First; node != _persistantQueue.Last.Next; node = node.Next)
            {
                GSRequest request = node.Value;

                if (numDurableRequestsProcessed >= DurableConcurrentRequests || _durableDrainTimer < DateTime.Now.Ticks)
                {
                    return;
                }

                if (request.RequestExpiresAt == 0 || request.RequestExpiresAt < DateTime.Now.Ticks)
                {
                    request.WaitForResponseTicks = DateTime.Now.AddMilliseconds(request.GetResponseTimeout()).Ticks;

                    request.DurableAttempts++;

                    request.RequestExpiresAt = DateTime.Now.AddMilliseconds(request.GetResponseTimeout() + ComputeSleepPeriod(request.DurableAttempts)).Ticks;

                    _connections [0].SendImmediate(request);

                    numDurableRequestsProcessed++;
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Send the given request.
        /// </summary>
        public void Send(GSRequest request)
        {
            AddRequestedAction(() => {
                if (request.Durable)
                {
                    SendDurable(request);

                    return;
                }

                lock (_connections) {
                    if (_connections.Count == 0)
                    {
                        NewConnection();
                    }
                }

                request.WaitForResponseTicks = DateTime.Now.AddMilliseconds(request.GetResponseTimeout()).Ticks;

                lock (_sendQueue) {
                    _sendQueue.AddLast(request);
                }
            });
        }