Package org.apache.qpid.jms.util
Class FifoMessageQueue
- java.lang.Object
-
- org.apache.qpid.jms.util.FifoMessageQueue
-
- All Implemented Interfaces:
MessageQueue
public final class FifoMessageQueue extends java.lang.Object implements MessageQueue
Simple first in / first out Message Queue.
-
-
Field Summary
Fields Modifier and Type Field Description protected static intCLOSEDprotected java.util.concurrent.locks.Conditionconditionprotected java.util.concurrent.locks.ReentrantLocklockprotected java.util.Deque<JmsInboundMessageDispatch>queueprotected static intRUNNINGprotected static java.util.concurrent.atomic.AtomicIntegerFieldUpdater<FifoMessageQueue>STATE_FIELD_UPDATERprotected static intSTOPPED
-
Constructor Summary
Constructors Constructor Description FifoMessageQueue(int prefetchSize)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Clears the Queue of any Messages.voidclose()Closes the Message Queue.JmsInboundMessageDispatchdequeue(long timeout)Used to get an enqueued message.JmsInboundMessageDispatchdequeueNoWait()Used to get an enqueued Message if on exists, otherwise returns null.voidenqueue(JmsInboundMessageDispatch envelope)Adds the given message envelope to the end of the Message queue.voidenqueueFirst(JmsInboundMessageDispatch envelope)Adds the given message envelope to the front of the Message queue.booleanisClosed()booleanisEmpty()booleanisRunning()intsize()Returns the number of Messages currently in the Queue.voidstart()Starts the Message Queue.voidstop()Stops the Message Queue.java.lang.StringtoString()
-
-
-
Field Detail
-
STATE_FIELD_UPDATER
protected static final java.util.concurrent.atomic.AtomicIntegerFieldUpdater<FifoMessageQueue> STATE_FIELD_UPDATER
-
CLOSED
protected static final int CLOSED
- See Also:
- Constant Field Values
-
STOPPED
protected static final int STOPPED
- See Also:
- Constant Field Values
-
RUNNING
protected static final int RUNNING
- See Also:
- Constant Field Values
-
lock
protected final java.util.concurrent.locks.ReentrantLock lock
-
condition
protected final java.util.concurrent.locks.Condition condition
-
queue
protected final java.util.Deque<JmsInboundMessageDispatch> queue
-
-
Method Detail
-
enqueueFirst
public void enqueueFirst(JmsInboundMessageDispatch envelope)
Description copied from interface:MessageQueueAdds the given message envelope to the front of the Message queue.- Specified by:
enqueueFirstin interfaceMessageQueue- Parameters:
envelope- The in-bound Message envelope to enqueue.
-
enqueue
public void enqueue(JmsInboundMessageDispatch envelope)
Description copied from interface:MessageQueueAdds the given message envelope to the end of the Message queue.- Specified by:
enqueuein interfaceMessageQueue- Parameters:
envelope- The in-bound Message envelope to enqueue.
-
dequeue
public JmsInboundMessageDispatch dequeue(long timeout) throws java.lang.InterruptedException
Description copied from interface:MessageQueueUsed to get an enqueued message. The amount of time this method blocks is based on the timeout value. - if timeout==-1 then it blocks until a message is received. - if timeout==0 then it it tries to not block at all, it returns a message if it is available - if timeout > 0 then it blocks up to timeout amount of time. Expired messages will consumed by this method.- Specified by:
dequeuein interfaceMessageQueue- Parameters:
timeout- The amount of time to wait for an entry to be added before returning null.- Returns:
- null if we timeout or if the consumer is closed.
- Throws:
java.lang.InterruptedException- if the wait is interrupted.
-
dequeueNoWait
public final JmsInboundMessageDispatch dequeueNoWait()
Description copied from interface:MessageQueueUsed to get an enqueued Message if on exists, otherwise returns null.- Specified by:
dequeueNoWaitin interfaceMessageQueue- Returns:
- the next Message in the Queue if one exists, otherwise null.
-
start
public final void start()
Description copied from interface:MessageQueueStarts the Message Queue. An non-started Queue will always return null for any of the Queue methods.- Specified by:
startin interfaceMessageQueue
-
stop
public final void stop()
Description copied from interface:MessageQueueStops the Message Queue. Messages cannot be read from the Queue when it is in the stopped state and any waiters will be woken.- Specified by:
stopin interfaceMessageQueue
-
close
public final void close()
Description copied from interface:MessageQueueCloses the Message Queue. No messages can be added or removed from the Queue once it has entered the closed state.- Specified by:
closein interfaceMessageQueue
-
isRunning
public final boolean isRunning()
- Specified by:
isRunningin interfaceMessageQueue- Returns:
- true if the Queue is not in the stopped or closed state.
-
isClosed
public final boolean isClosed()
- Specified by:
isClosedin interfaceMessageQueue- Returns:
- true if the Queue has been closed.
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmptyin interfaceMessageQueue- Returns:
- true if there are no messages in the queue.
-
size
public int size()
Description copied from interface:MessageQueueReturns the number of Messages currently in the Queue. This value is only meaningful at the time of the call as the size of the Queue changes rapidly as Messages arrive and are consumed.- Specified by:
sizein interfaceMessageQueue- Returns:
- the current number of Messages in the Queue.
-
clear
public void clear()
Description copied from interface:MessageQueueClears the Queue of any Messages.- Specified by:
clearin interfaceMessageQueue
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-