com.flat502.rox.utils
Class PipelinedBlockingQueue

java.lang.Object
  extended by com.flat502.rox.utils.PipelinedBlockingQueue

public class PipelinedBlockingQueue
extends java.lang.Object

This class provides a pipelined implementation of the core functionality of Java 1.5's BlockingQueue interface.

Elements are enqueued along with the "origin". Pipelining happens within the context of each origin. Simply put, a thread calling take() will never dequeue an item that shares an origin with another item that was dequeued by a second thread that has not returned to the queue.


Constructor Summary
PipelinedBlockingQueue()
           
 
Method Summary
 void add(java.lang.Object element, java.lang.Object origin)
          Adds the specified element to this queue
 java.lang.Object take()
          Retrieves and removes the free element on this queue.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PipelinedBlockingQueue

public PipelinedBlockingQueue()
Method Detail

add

public void add(java.lang.Object element,
                java.lang.Object origin)
Adds the specified element to this queue

Parameters:
element - The element to enqueue
origin - The origin associated with this element.
Throws:
java.lang.NullPointerException - if the specified element is null

take

public java.lang.Object take()
                      throws java.lang.InterruptedException
Retrieves and removes the free element on this queue.

An element is considered free if the origin it is associated with is not shared by another element that was previously dequeued by a thread that has not yet "returned" to this queue

Returns:
the first free element on this queue
Throws:
java.lang.InterruptedException - if interrupted while waiting.