com.lti.utils.synchronization
Class ProducerConsumerQueue<T>

java.lang.Object
  extended by com.lti.utils.synchronization.ProducerConsumerQueue<T>

public class ProducerConsumerQueue<T>
extends java.lang.Object

A synchronized queue where get/put waits if needed.

Author:
Ken Larson

Constructor Summary
ProducerConsumerQueue()
           
ProducerConsumerQueue(int sizeLimit)
           
 
Method Summary
 T get()
           
 T get(long timeout, T returnOnTimeout)
           
 boolean isEmpty()
           
 boolean isFull()
           
 void put(T value)
           
 boolean put(T value, long timeout)
           
 int size()
           
 int sizeLimit()
           
 void waitUntilEmpty()
           
 void waitUntilNotEmpty()
           
 boolean waitUntilNotEmpty(long timeout)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ProducerConsumerQueue

public ProducerConsumerQueue()

ProducerConsumerQueue

public ProducerConsumerQueue(int sizeLimit)
Method Detail

size

public int size()

sizeLimit

public int sizeLimit()

isFull

public boolean isFull()

isEmpty

public boolean isEmpty()

waitUntilNotEmpty

public void waitUntilNotEmpty()
                       throws java.lang.InterruptedException
Throws:
java.lang.InterruptedException

waitUntilEmpty

public void waitUntilEmpty()
                    throws java.lang.InterruptedException
Throws:
java.lang.InterruptedException

waitUntilNotEmpty

public boolean waitUntilNotEmpty(long timeout)
                          throws java.lang.InterruptedException
Returns:
true if success, false if timeout.
Throws:
java.lang.InterruptedException

get

public T get()
      throws java.lang.InterruptedException
Throws:
java.lang.InterruptedException

get

public T get(long timeout,
             T returnOnTimeout)
      throws java.lang.InterruptedException
Returns:
returnOnTimeout if timeout.
Throws:
java.lang.InterruptedException

put

public void put(T value)
         throws java.lang.InterruptedException
Throws:
java.lang.InterruptedException

put

public boolean put(T value,
                   long timeout)
            throws java.lang.InterruptedException
Returns:
false if timeout, true otherwise
Throws:
java.lang.InterruptedException