Apache.NMS.ActiveMQ.Util.SimplePriorityMessageDispatchChannel.RemoveAll C# (CSharp) Method

RemoveAll() public method

public RemoveAll ( ) : MessageDispatch[]
return MessageDispatch[]
        public MessageDispatch[] RemoveAll()
        {
            MessageDispatch[] result;

            lock(mutex)
            {
                result = new MessageDispatch[this.size];
                int copyPos = 0;

                for(int i = MAX_PRIORITY - 1; i >= 0; i--)
                {
                    LinkedList<MessageDispatch> list = channels[i];
                    list.CopyTo(result, copyPos);
                    copyPos += list.Count;
                    size -= list.Count;
                    list.Clear();
                }
            }

            return result;
        }

Usage Example

        public void TestRemoveAll()
        {
            SimplePriorityMessageDispatchChannel channel = new SimplePriorityMessageDispatchChannel();

            MessageDispatch dispatch1 = new MessageDispatch();
            MessageDispatch dispatch2 = new MessageDispatch();
            MessageDispatch dispatch3 = new MessageDispatch();

            Message message1 = new Message();
            Message message2 = new Message();
            Message message3 = new Message();

            message1.Priority = 1;
            message2.Priority = 2;
            message3.Priority = 3;

            dispatch1.Message = message1;
            dispatch2.Message = message2;
            dispatch3.Message = message3;

            channel.Enqueue( dispatch1 );
            channel.Enqueue( dispatch2 );
            channel.Enqueue( dispatch3 );

            channel.Start();
            Assert.IsTrue( channel.Running == true );
            Assert.IsTrue( channel.Empty == false );
            Assert.IsTrue( channel.Count == 3 );
            Assert.IsTrue( channel.RemoveAll().Length == 3 );
            Assert.IsTrue( channel.Count == 0 );
            Assert.IsTrue( channel.Empty == true );
        }