Class BlockingQueue
java.lang.Object
org.jpos.util.BlockingQueue
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classThrown by queue operations after the queue has been closed. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the queue and wakes all waiting consumers, who will then receiveBlockingQueue.Closed.intReturns the number of consumers currently waiting on this queue.intReturns the difference between queued items and waiting consumers.dequeue()Removes and returns the head of the queue, blocking until an object is available.dequeue(long timeout) Removes and returns the head of the queue, blocking up totimeoutms.voidAppends an object to the tail of the queue and wakes one waiter.getQueue()Returns the underlying list backing this queue.intpending()Returns the number of items currently in the queue.booleanready()Indicates whether the queue is open for new operations.voidInserts an object at the head of the queue and wakes one waiter.voidsetQueue(LinkedList queue) Replaces the underlying list backing this queue.
-
Constructor Details
-
BlockingQueue
public BlockingQueue()Creates an empty, open queue.
-
-
Method Details
-
enqueue
Appends an object to the tail of the queue and wakes one waiter.- Parameters:
o- the object to enqueue- Throws:
BlockingQueue.Closed- if the queue has been closed
-
requeue
Inserts an object at the head of the queue and wakes one waiter.- Parameters:
o- the object to requeue- Throws:
BlockingQueue.Closed- if the queue has been closed
-
dequeue
Removes and returns the head of the queue, blocking until an object is available.- Returns:
- the object at the head of the queue
- Throws:
InterruptedException- if the thread is interrupted while waitingBlockingQueue.Closed- if the queue is closed while waiting
-
dequeue
Removes and returns the head of the queue, blocking up totimeoutms.- Parameters:
timeout- maximum wait in milliseconds;0blocks indefinitely- Returns:
- the object at the head of the queue, or
nullif the wait elapsed - Throws:
InterruptedException- if the thread is interrupted while waitingBlockingQueue.Closed- if the queue is closed while waiting
-
close
Closes the queue and wakes all waiting consumers, who will then receiveBlockingQueue.Closed. -
consumerCount
Returns the number of consumers currently waiting on this queue.- Returns:
- the live consumer count
-
consumerDeficit
Returns the difference between queued items and waiting consumers.- Returns:
- queue size minus consumer count (negative when consumers exceed items)
-
ready
Indicates whether the queue is open for new operations.- Returns:
trueif the queue has not been closed
-
pending
-
getQueue
Returns the underlying list backing this queue.- Returns:
- the internal list (live reference, not a copy)
-
setQueue
Replaces the underlying list backing this queue.- Parameters:
queue- the list to use as the new backing store
-