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

EnqueueFirst() public method

public EnqueueFirst ( MessageDispatch dispatch ) : void
dispatch MessageDispatch
return void
        public void EnqueueFirst(MessageDispatch dispatch)
        {
            lock(this.mutex)
            {
                GetList(dispatch).AddFirst(dispatch);
                this.size++;
                Monitor.Pulse(this.mutex);
            }
        }

Usage Example

        public void TestPeek()
        {
            SimplePriorityMessageDispatchChannel channel = new SimplePriorityMessageDispatchChannel();
            MessageDispatch dispatch1 = new MessageDispatch();
            MessageDispatch dispatch2 = new MessageDispatch();

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

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

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

            Assert.IsTrue( channel.Empty == true );
            Assert.IsTrue( channel.Count == 0 );

            channel.EnqueueFirst( dispatch1 );

            Assert.IsTrue( channel.Empty == false );
            Assert.IsTrue( channel.Count == 1 );

            channel.EnqueueFirst( dispatch2 );

            Assert.IsTrue( channel.Empty == false );
            Assert.IsTrue( channel.Count == 2 );

            Assert.IsTrue( channel.Peek() == null );

            channel.Start();

            Assert.IsTrue( channel.Peek() == dispatch1 );
            Assert.IsTrue( channel.DequeueNoWait() == dispatch1 );
            Assert.IsTrue( channel.Peek() == dispatch2 );
            Assert.IsTrue( channel.DequeueNoWait() == dispatch2 );
        }
All Usage Examples Of Apache.NMS.ActiveMQ.Util.SimplePriorityMessageDispatchChannel::EnqueueFirst