Пример #1
0
        /// <summary>
        /// Put a single request item into the storage.
        /// </summary>
        /// <param name="request">the single request that need be stored to the persistenc</param>
        /// <param name="putRequestCallback">the callback function that will be called once the async operation finish or exception raise.</param>
        /// <param name="callbackState">the state object for the callback.</param>
        public async Task PutRequestAsync(BrokerQueueItem request, PutRequestCallback putRequestCallback, object callbackState)
        {
            if (this.isClosedField)
            {
                BrokerTracing.TraceWarning("[MemoryPersist] .GetRequestAsync: the queue is closed.");
                return;
            }

            request.PersistAsyncToken.AsyncToken = this.PersistToken;
            this.requestQueueField.Enqueue(request);

            Interlocked.Increment(ref this.allRequestCountField);
            Interlocked.Increment(ref this.requestCountField);

            PutRequestComplete(putRequestCallback, callbackState);
        }
Пример #2
0
        /// <summary>
        /// the putting request complete thread proc
        /// </summary>
        /// <param name="state">the thread pool callback state</param>
        private static void PutRequestComplete(PutRequestCallback callback, object state)
        {
            if (callback == null)
            {
                return;
            }

            try
            {
                callback(null, state);
            }
            catch (Exception e)
            {
                BrokerTracing.TraceError("[MemoryPersist] .PutRequestComplete: callback failed, Exception:{0}.", e.ToString());
            }
        }
Пример #3
0
        /// <summary>
        /// Put the request item objects into the storage.
        /// </summary>
        /// <param name="requests">A list of request objects</param>
        /// <param name="putRequestCallback">the callback function that will be called once the async operation finish or exception raise.</param>
        /// <param name="callbackState">the state object for the callback.</param>
        public async Task PutRequestsAsync(IEnumerable <BrokerQueueItem> requests, PutRequestCallback putRequestCallback, object callbackState)
        {
            if (this.isClosedField)
            {
                BrokerTracing.TraceWarning("[MemoryPersist] .PutRequestsAsync: the queue is closed.");
                return;
            }

            int requestsCount = 0;

            foreach (BrokerQueueItem request in requests)
            {
                request.PersistAsyncToken.AsyncToken = this.PersistToken;
                this.requestQueueField.Enqueue(request);
                requestsCount++;
            }

            Interlocked.Add(ref this.allRequestCountField, requestsCount);
            Interlocked.Add(ref this.requestCountField, requestsCount);

            PutRequestComplete(putRequestCallback, callbackState);
        }