Exemple #1
0
        /// <summary>
        /// Callback to get request
        /// </summary>
        /// <param name="state">indicating the state</param>
        private void WaitCallbackToGetRequestAsync(object state)
        {
            BrokerQueue queue = (BrokerQueue)state;

            queue.GetRequestAsync(this.PrefetchRequestCallback, queue);
        }
Exemple #2
0
        internal void AddBrokerQueue(BrokerQueue queue, IEnumerable <BrokerQueueItem> requests)
        {
            if (queue != null)
            {
                if (requests != null)
                {
                    foreach (BrokerQueueItem request in requests)
                    {
                        if (request != null)
                        {
                            if (request.PersistAsyncToken.AsyncToken == null)
                            {
                                lock (this.requestsAsyncTokenTable)
                                {
                                    if (!this.requestsAsyncTokenTable.ContainsKey(request.PersistId))
                                    {
                                        this.requestsAsyncTokenTable.Add(request.PersistId, new DispatcherAsyncTokenItem());
                                    }
                                    else
                                    {
                                        BrokerTracing.TraceError("[BrokerQueueDispatcher] .AddBrokerQueue: There are duplicate persist id, {0}", request.PersistId);
                                    }
                                }
                            }

                            this.requestCacheQueue.Enqueue(request);
                        }
                    }
                }

                bool containsQueue;
                lock (this.needDispatchQueueClientIdTable)
                {
                    containsQueue = this.needDispatchQueueClientIdTable.ContainsKey(queue.ClientId);
                }

                if (!containsQueue)
                {
                    bool needDispatch = true;
                    try
                    {
                        lock (this.needDispatchQueueClientIdTable)
                        {
                            this.needDispatchQueueClientIdTable.Add(queue.ClientId, null);
                        }
                    }
                    catch (ArgumentException e)
                    {
                        needDispatch = false;

                        // the key already exists in the table.
                        BrokerTracing.TraceInfo("[BrokerQueueDispatcher] .AddBrokerQueue: the broker queue with client id, {0}, already exists, Exception: {1}", queue.ClientId, e);
                    }
                    catch (Exception e)
                    {
                        BrokerTracing.TraceWarning("[BrokerQueueDispatcher] .AddBrokerQueue: add a broker queue with client id, {0}, to the client table raised exception, Exception: {1}", queue.ClientId, e);
                    }

                    if (needDispatch)
                    {
                        if (this.needPrefetch)
                        {
                            queue.GetRequestAsync(this.PrefetchRequestCallback, queue);
                        }
                        else
                        {
                            lock (this.waitBrokerQueuesForPeekRequests)
                            {
                                this.waitBrokerQueuesForPeekRequests.Add(queue);
                            }
                        }
                    }
                }
            }
        }