public virtual void Enqueue(QueueMessage message) { if (message == null) { return; } lock (lockObj) { rearIndex = (rearIndex + 1) % this.Messages.Length; if (rearIndex == this.allowedMessageSize) { return; } Messages[rearIndex] = message; if (QueueIsFull()) { QueueMessage[] temp = new QueueMessage[rearIndex + 2]; Array.Copy(Messages, 0, temp, 0, temp.Length - 1); Messages = temp; } CurrentOffset = rearIndex; message.SetQueueId(this.QueueId); // recorde queueId in queue message message.SetOffset(this.CurrentOffset); //recode queue current offset } }
public virtual QueueMessage Dequeue() { lock (lockObj) { if (QueueIsEmpty()) { return(null); } QueueMessage[] temp = new QueueMessage[rearIndex + 1]; QueueMessage message = Messages[frontIndex]; Array.Copy(Messages, frontIndex + 1, temp, frontIndex, rearIndex); Messages = temp; this.rearIndex -= 1; CurrentOffset = frontIndex; message.SetOffset(this.CurrentOffset);//recode queue current offset return(message); } }