Package org.web3d.util
Class BlockingQueue
java.lang.Object
org.j3d.util.Queue
org.web3d.util.BlockingQueue
public class BlockingQueue
extends org.j3d.util.Queue
Blocking 'First In First Out' (FIFO) queue. Based on the simple Queue but can be used concurrently by separate threads. If there are not elements in the queue, getNext() will block until it is not empty. Taken from the VLC common code library http://www.vlc.com.au/common/ This software is released under the GNU LGPL
- Version:
- $Revision: 1.7 $
- Author:
- Justin Couch.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add an object to the end of the queue.void
clear()
Clear the queue of items.getNext()
Return the next element from the front of the queue, and remove it from the queue.boolean
hasNext()
Check if queue has more objects.peekNext()
Get the next element from the front of the queue.void
purge()
Remove all elements from queue.int
size()
Return the size of the queue.Methods inherited from class org.j3d.util.Queue
remove
-
Constructor Details
-
BlockingQueue
public BlockingQueue()Constructor. Create a simple queue.
-
-
Method Details
-
add
Add an object to the end of the queue.- Overrides:
add
in classorg.j3d.util.Queue
- Parameters:
o
- Object to add.
-
getNext
Return the next element from the front of the queue, and remove it from the queue. Under normal circumstances this method will always return an object, blocking if it has to until something is available. However, sometimes the queue needs to close so we unblock the queue are return null instead.- Overrides:
getNext
in classorg.j3d.util.Queue
- Returns:
- element at the front of the queue, will block until queue is not empty.
-
peekNext
Get the next element from the front of the queue.- Overrides:
peekNext
in classorg.j3d.util.Queue
- Returns:
- element at the front of the queue, null if empty.
-
hasNext
public boolean hasNext()Check if queue has more objects.- Overrides:
hasNext
in classorg.j3d.util.Queue
- Returns:
- true if queue has more objects.
-
size
public int size()Return the size of the queue.- Overrides:
size
in classorg.j3d.util.Queue
- Returns:
- size of queue.
-
purge
public void purge()Remove all elements from queue. Also unblock those who are waiting for items in the queue. They leave the getNext() method with null. -
clear
public void clear()Clear the queue of items. If there are users of the class that are blocked while waiting for elements in the queue, they remain so.- Overrides:
clear
in classorg.j3d.util.Queue
-