Example #1
0
        /// <summary>
        /// Remove oldest message in the cache, remove oldest block too if the block is empty
        /// </summary>
        public void RemoveOldestMessage()
        {
            this.messageBlocks.Last.Value.Remove();
            this.ItemCount--;
            CachedMessageBlock lastCachedMessageBlock = this.messageBlocks.Last.Value;

            // if block is currently empty, but all capacity has been exausted, remove
            if (lastCachedMessageBlock.IsEmpty && !lastCachedMessageBlock.HasCapacity)
            {
                lastCachedMessageBlock.Dispose();
                this.messageBlocks.RemoveLast();
            }
        }
Example #2
0
        private void PerformBlockPurge(IDisposable purgeRequest)
        {
            while (!IsEmpty &&
                   cacheDataAdapter.ShouldPurge(messageBlocks.Last.Value[messageBlocks.Last.Value.OldestMessageIndex], purgeRequest)) // value has the same resource blockId as the one we are purging
            {
                messageBlocks.Last.Value.Remove();
                CachedMessageBlock <TQueueMessage, TCachedMessage> lastCachedMessageBlock = messageBlocks.Last.Value;
                // if block is currently empty, but all capacity has been exausted, remove
                if (lastCachedMessageBlock.IsEmpty && !lastCachedMessageBlock.HasCapacity)
                {
                    lastCachedMessageBlock.Dispose();
                    messageBlocks.RemoveLast();
                }
            }

            purgeRequest.Dispose();
        }
Example #3
0
        /// <summary>
        /// Allocates a message in a block and returns the block the message is in.
        /// </summary>
        /// <param name="queueMessage"></param>
        /// <returns></returns>
        public CachedMessageBlock <TQueueMessage, TCachedMessage> AllocateMessage(TQueueMessage queueMessage)
        {
            if (queueMessage == null)
            {
                throw new ArgumentNullException("queueMessage");
            }

            // allocate new cached message block if needed
            if (cachedMessageBlock == null || !cachedMessageBlock.HasCapacity)
            {
                cachedMessageBlock = cachedMessagePool.Allocate();
            }

            cachedMessageBlock.Add(queueMessage);

            return(cachedMessageBlock);
        }
Example #4
0
        /// <summary>
        /// Allocates a message in a block and returns the block the message is in.
        /// </summary>
        /// <param name="queueMessage"></param>
        /// <param name="dequeueTimeUtc"></param>
        /// <param name="streamPosition"></param>
        /// <returns></returns>
        public CachedMessageBlock <TCachedMessage> AllocateMessage(TQueueMessage queueMessage, DateTime dequeueTimeUtc, out StreamPosition streamPosition)
        {
            streamPosition = default(StreamPosition);
            if (queueMessage == null)
            {
                throw new ArgumentNullException("queueMessage");
            }

            // allocate new cached message block if needed
            if (currentMessageBlock == null || !currentMessageBlock.HasCapacity)
            {
                currentMessageBlock = messagePool.Allocate();
            }

            streamPosition = currentMessageBlock.Add(queueMessage, dequeueTimeUtc, dataAdapter);

            return(currentMessageBlock);
        }
        private StreamPosition Add(TQueueMessage message, DateTime dequeueTimeUtc)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }

            StreamPosition streamPosition;
            // allocate message from pool
            CachedMessageBlock <TCachedMessage> block = pool.AllocateMessage(message, dequeueTimeUtc, out streamPosition);

            // If new block, add message block to linked list
            if (block != messageBlocks.FirstOrDefault())
            {
                messageBlocks.AddFirst(block.Node);
            }
            itemCount++;
            return(streamPosition);
        }
Example #6
0
        public void Add(TQueueMessage message)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }

            PerformPendingPurges();

            // allocate message from pool
            CachedMessageBlock <TCachedMessage> block = pool.AllocateMessage(message);

            // If new block, add message block to linked list
            if (block != messageBlocks.FirstOrDefault())
            {
                messageBlocks.AddFirst(block.Node);
            }

            PerformPendingPurges();
        }
        /// <summary>
        /// Allocates a message in a block and returns the block the message is in.
        /// </summary>
        /// <param name="queueMessage"></param>
        /// <param name="dequeueTimeUtc"></param>
        /// <param name="streamPosition"></param>
        /// <returns></returns>
        public CachedMessageBlock <TCachedMessage> AllocateMessage(TQueueMessage queueMessage, DateTime dequeueTimeUtc, out StreamPosition streamPosition)
        {
            streamPosition = default(StreamPosition);
            if (queueMessage == null)
            {
                throw new ArgumentNullException(nameof(queueMessage));
            }

            CachedMessageBlock <TCachedMessage> returnBlock = currentMessageBlock ?? (currentMessageBlock = messagePool.Allocate());

            streamPosition = returnBlock.Add(queueMessage, dequeueTimeUtc, dataAdapter);

            // blocks at capacity are eligable for purge, so we don't want to be holding on to them.
            if (!currentMessageBlock.HasCapacity)
            {
                currentMessageBlock = messagePool.Allocate();
            }

            return(returnBlock);
        }