Xj3D VRML/X3D Code API

org.web3d.util
Class BlockingQueue

java.lang.Object
  extended byorg.web3d.util.Queue
      extended byorg.web3d.util.BlockingQueue

public class BlockingQueue
extends Queue

Blocking 'First In First Out' (FIFO) queue.

Based on the simple Queue but can be used concurrently by seperate 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 softare is released under the GNU LGPL

Version:
$Revision: 1.5 $
Author:
Justin Couch.
See Also:
Queue

Constructor Summary
BlockingQueue()
          Constructor.
 
Method Summary
 void add(java.lang.Object o)
          Add an object to the end of the queue.
 void clear()
          Clear the queue of items.
 java.lang.Object 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.
 java.lang.Object 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.web3d.util.Queue
remove
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BlockingQueue

public BlockingQueue()
Constructor. Create a simple queue.

Method Detail

add

public void add(java.lang.Object o)
Add an object to the end of the queue.

Overrides:
add in class Queue
Parameters:
o - Object to add.

getNext

public java.lang.Object 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 class Queue
Returns:
element at the front of the queue, will block until queue is not empty.

peekNext

public java.lang.Object peekNext()
Get the next element from the front of the queue.

Overrides:
peekNext in class 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 class Queue
Returns:
true if queue has more objects.

size

public int size()
Return the size of the queue.

Overrides:
size in class 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 class Queue

Xj3D VRML/X3D Code API

Copyright © 2001 - 2005 Web3D Consortium