com.partnersoft.data
Class BlockingQueue

java.lang.Object
  extended by com.partnersoft.data.BlockingQueue

public class BlockingQueue
extends java.lang.Object

This is essentially just a synchronized FIFO queue which blocks input when the queue is full (with a configurable "full" size parameter) and output when the queue is empty. It is useful for exchanging objects between thread which work in some kind of asynchronous pipeline.

Author:
Paul Reavis Copyright 2003 Partner Software, Inc.

Constructor Summary
BlockingQueue()
          Constructs a BlockingQueue of unlimited size.
BlockingQueue(int maximumSize)
          Constructs a BlockingQueue with the requested size.
 
Method Summary
 void add(java.lang.Object someObject)
          Adds an object to the end of the queue.
 void close()
          Closes the queue.
 void closeWhenEmpty()
          Closes the queue after it empties.
 int getCurrentSize()
          Returns the current size.
 java.lang.Object remove()
          Removes an object from the front of the queue.
 void waitUntilEmpty()
          Waits for the queue to empty.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BlockingQueue

public BlockingQueue()
Constructs a BlockingQueue of unlimited size.


BlockingQueue

public BlockingQueue(int maximumSize)
Constructs a BlockingQueue with the requested size. Zero means unlimited.

Method Detail

add

public void add(java.lang.Object someObject)
         throws java.lang.InterruptedException
Adds an object to the end of the queue. Blocks if queue is full, automatically waiting until it has room again. Throws InterruptedException if the queue is closed while it's waiting.

Throws:
java.lang.InterruptedException

remove

public java.lang.Object remove()
                        throws java.lang.InterruptedException
Removes an object from the front of the queue. Blocks if queue is empty, automatically waiting until it has contents again. Throws InterruptedException if the queue is closed while it's waiting.

Throws:
java.lang.InterruptedException

getCurrentSize

public int getCurrentSize()
Returns the current size.


waitUntilEmpty

public void waitUntilEmpty()
                    throws java.lang.InterruptedException
Waits for the queue to empty.

Throws:
java.lang.InterruptedException

closeWhenEmpty

public void closeWhenEmpty()
                    throws java.lang.InterruptedException
Closes the queue after it empties.

Throws:
java.lang.InterruptedException

close

public void close()
Closes the queue. Causes InterruptedException to be thrown by any waiting threads.