Package org.apache.qpid.jms.util
Class PriorityMessageQueue
- java.lang.Object
-
- org.apache.qpid.jms.util.PriorityMessageQueue
-
- All Implemented Interfaces:
MessageQueue
public final class PriorityMessageQueue extends java.lang.Object implements MessageQueue
Simple Message Priority ordered Queue. Message envelopes are stored in the Queue based on their priority value, except whereenqueueFirst(org.apache.qpid.jms.message.JmsInboundMessageDispatch)
is used.
-
-
Field Summary
Fields Modifier and Type Field Description protected static int
CLOSED
protected java.lang.Object
lock
protected static int
RUNNING
protected static java.util.concurrent.atomic.AtomicIntegerFieldUpdater<PriorityMessageQueue>
STATE_FIELD_UPDATER
protected static int
STOPPED
-
Constructor Summary
Constructors Constructor Description PriorityMessageQueue()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Clears the Queue of any Messages.void
close()
Closes the Message Queue.JmsInboundMessageDispatch
dequeue(long timeout)
Used to get an enqueued message.JmsInboundMessageDispatch
dequeueNoWait()
Used to get an enqueued Message if on exists, otherwise returns null.void
enqueue(JmsInboundMessageDispatch envelope)
Adds the given message envelope to the end of the Message queue.void
enqueueFirst(JmsInboundMessageDispatch envelope)
Adds the given message envelope to the front of the Message queue.boolean
isClosed()
boolean
isEmpty()
boolean
isRunning()
int
size()
Returns the number of Messages currently in the Queue.void
start()
Starts the Message Queue.void
stop()
Stops the Message Queue.
-
-
-
Field Detail
-
STATE_FIELD_UPDATER
protected static final java.util.concurrent.atomic.AtomicIntegerFieldUpdater<PriorityMessageQueue> 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.lang.Object lock
-
-
Method Detail
-
enqueue
public void enqueue(JmsInboundMessageDispatch envelope)
Description copied from interface:MessageQueue
Adds the given message envelope to the end of the Message queue.- Specified by:
enqueue
in interfaceMessageQueue
- Parameters:
envelope
- The in-bound Message envelope to enqueue.
-
enqueueFirst
public void enqueueFirst(JmsInboundMessageDispatch envelope)
Description copied from interface:MessageQueue
Adds the given message envelope to the front of the Message queue.- Specified by:
enqueueFirst
in interfaceMessageQueue
- Parameters:
envelope
- The in-bound Message envelope to enqueue.
-
dequeue
public final JmsInboundMessageDispatch dequeue(long timeout) throws java.lang.InterruptedException
Description copied from interface:MessageQueue
Used 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:
dequeue
in 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:MessageQueue
Used to get an enqueued Message if on exists, otherwise returns null.- Specified by:
dequeueNoWait
in interfaceMessageQueue
- Returns:
- the next Message in the Queue if one exists, otherwise null.
-
start
public final void start()
Description copied from interface:MessageQueue
Starts the Message Queue. An non-started Queue will always return null for any of the Queue methods.- Specified by:
start
in interfaceMessageQueue
-
stop
public final void stop()
Description copied from interface:MessageQueue
Stops 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:
stop
in interfaceMessageQueue
-
close
public final void close()
Description copied from interface:MessageQueue
Closes the Message Queue. No messages can be added or removed from the Queue once it has entered the closed state.- Specified by:
close
in interfaceMessageQueue
-
isRunning
public final boolean isRunning()
- Specified by:
isRunning
in interfaceMessageQueue
- Returns:
- true if the Queue is not in the stopped or closed state.
-
isClosed
public final boolean isClosed()
- Specified by:
isClosed
in interfaceMessageQueue
- Returns:
- true if the Queue has been closed.
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmpty
in interfaceMessageQueue
- Returns:
- true if there are no messages in the queue.
-
size
public int size()
Description copied from interface:MessageQueue
Returns 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:
size
in interfaceMessageQueue
- Returns:
- the current number of Messages in the Queue.
-
clear
public void clear()
Description copied from interface:MessageQueue
Clears the Queue of any Messages.- Specified by:
clear
in interfaceMessageQueue
-
-