net.sf.beanlib.util.concurrent
Class ConcurrentLinkedBoundedBlockingQueue<E>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractQueue<E>
          extended by net.sf.beanlib.util.concurrent.ConcurrentLinkedBlockingQueue<E>
              extended by net.sf.beanlib.util.concurrent.ConcurrentLinkedBoundedBlockingQueue<E>
Type Parameters:
E - the type of elements held in this collection
All Implemented Interfaces:
Serializable, Iterable<E>, Collection<E>, BlockingQueue<E>, Queue<E>

public class ConcurrentLinkedBoundedBlockingQueue<E>
extends ConcurrentLinkedBlockingQueue<E>

An bounded concurrent blocking queue implemented upon ConcurrentLinkedQueue.

Note there is currently no such class in Java 6.

Author:
Hanson Char
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class net.sf.beanlib.util.concurrent.ConcurrentLinkedBlockingQueue
ConcurrentLinkedBlockingQueue.ThreadMarker
 
Field Summary
private  AtomicInteger capacity
           
private  ConcurrentLinkedQueue<ConcurrentLinkedBlockingQueue.ThreadMarker> putparkq
           
private static long serialVersionUID
           
 
Constructor Summary
ConcurrentLinkedBoundedBlockingQueue(Collection<? extends E> c)
           
ConcurrentLinkedBoundedBlockingQueue(int capacity)
           
 
Method Summary
 int drainTo(Collection<? super E> c)
           
 int drainTo(Collection<? super E> c, int maxElements)
           
 boolean offer(E e)
           
 boolean offer(E e, long timeout, TimeUnit unit)
           
 E poll()
           
 E poll(long timeout, TimeUnit unit)
          Retrieves and removes the head of this queue, waiting up to the specified wait time if necessary for an element to become available.
 void put(E e)
           
 int remainingCapacity()
           
 E take()
          Retrieves and removes the head of this queue, waiting if necessary until an element becomes available.
private  boolean tryDecrementCapacity()
           
private  void unparkIfAny()
           
 
Methods inherited from class net.sf.beanlib.util.concurrent.ConcurrentLinkedBlockingQueue
iterator, peek, size
 
Methods inherited from class java.util.AbstractQueue
add, addAll, clear, element, remove
 
Methods inherited from class java.util.AbstractCollection
contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.concurrent.BlockingQueue
add
 
Methods inherited from interface java.util.Queue
element, remove
 
Methods inherited from interface java.util.Collection
addAll, clear, contains, containsAll, equals, hashCode, isEmpty, remove, removeAll, retainAll, toArray, toArray
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

capacity

private final AtomicInteger capacity

putparkq

private final ConcurrentLinkedQueue<ConcurrentLinkedBlockingQueue.ThreadMarker> putparkq
Constructor Detail

ConcurrentLinkedBoundedBlockingQueue

public ConcurrentLinkedBoundedBlockingQueue(int capacity)

ConcurrentLinkedBoundedBlockingQueue

public ConcurrentLinkedBoundedBlockingQueue(Collection<? extends E> c)
Method Detail

offer

public boolean offer(E e)
Specified by:
offer in interface BlockingQueue<E>
Specified by:
offer in interface Queue<E>
Overrides:
offer in class ConcurrentLinkedBlockingQueue<E>

tryDecrementCapacity

private boolean tryDecrementCapacity()

poll

public E poll()
Specified by:
poll in interface Queue<E>
Overrides:
poll in class ConcurrentLinkedBlockingQueue<E>

take

public E take()
       throws InterruptedException
Retrieves and removes the head of this queue, waiting if necessary until an element becomes available.

Specified by:
take in interface BlockingQueue<E>
Overrides:
take in class ConcurrentLinkedBlockingQueue<E>
Returns:
the head of this queue
Throws:
InterruptedException - if interrupted while waiting

unparkIfAny

private void unparkIfAny()

poll

public E poll(long timeout,
              TimeUnit unit)
       throws InterruptedException
Retrieves and removes the head of this queue, waiting up to the specified wait time if necessary for an element to become available.

Specified by:
poll in interface BlockingQueue<E>
Overrides:
poll in class ConcurrentLinkedBlockingQueue<E>
Parameters:
timeout - how long to wait before giving up, in units of unit. A negative timeout is treated the same as to wait forever.
unit - a TimeUnit determining how to interpret the timeout parameter
Returns:
the head of this queue, or null if the specified waiting time elapses before an element is available
Throws:
InterruptedException - if interrupted while waiting

put

public void put(E e)
         throws InterruptedException
Specified by:
put in interface BlockingQueue<E>
Overrides:
put in class ConcurrentLinkedBlockingQueue<E>
Throws:
InterruptedException

offer

public boolean offer(E e,
                     long timeout,
                     TimeUnit unit)
              throws InterruptedException
Specified by:
offer in interface BlockingQueue<E>
Overrides:
offer in class ConcurrentLinkedBlockingQueue<E>
Throws:
InterruptedException

remainingCapacity

public int remainingCapacity()
Specified by:
remainingCapacity in interface BlockingQueue<E>
Overrides:
remainingCapacity in class ConcurrentLinkedBlockingQueue<E>

drainTo

public int drainTo(Collection<? super E> c)
Specified by:
drainTo in interface BlockingQueue<E>
Overrides:
drainTo in class ConcurrentLinkedBlockingQueue<E>

drainTo

public int drainTo(Collection<? super E> c,
                   int maxElements)
Specified by:
drainTo in interface BlockingQueue<E>
Overrides:
drainTo in class ConcurrentLinkedBlockingQueue<E>