com.jolbox.bonecp
Class BoundedLinkedTransferQueue<E>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractQueue<E>
          extended by jsr166y.LinkedTransferQueue<E>
              extended by com.jolbox.bonecp.BoundedLinkedTransferQueue<E>
Type Parameters:
E -
All Implemented Interfaces:
Serializable, Iterable<E>, Collection<E>, BlockingQueue<E>, Queue<E>, TransferQueue<E>

public class BoundedLinkedTransferQueue<E>
extends LinkedTransferQueue<E>

A bounded version of linkedTransferQueue.

Author:
wallacew
See Also:
Serialized Form

Constructor Summary
BoundedLinkedTransferQueue(int maxQueueSize)
          Constructor.
 
Method Summary
 boolean offer(E e)
          Inserts the specified element at the tail of this queue.
 E poll()
           
 E poll(long timeout, TimeUnit unit)
           
 void put(E e)
          Inserts the specified element at the tail of this queue.
 int remainingCapacity()
          Returns the number of free slots in this queue.
 int size()
          Returns the number of elements in this queue.
 boolean tryTransfer(E e)
          Transfers the element to a waiting consumer immediately, if possible.
 
Methods inherited from class jsr166y.LinkedTransferQueue
add, drainTo, drainTo, getWaitingConsumerCount, hasWaitingConsumer, isEmpty, iterator, offer, peek, remove, take, transfer, tryTransfer
 
Methods inherited from class java.util.AbstractQueue
addAll, clear, element, remove
 
Methods inherited from class java.util.AbstractCollection
contains, containsAll, 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
contains
 
Methods inherited from interface java.util.Queue
element, remove
 
Methods inherited from interface java.util.Collection
addAll, clear, containsAll, equals, hashCode, removeAll, retainAll, toArray, toArray
 

Constructor Detail

BoundedLinkedTransferQueue

public BoundedLinkedTransferQueue(int maxQueueSize)
Constructor.

Parameters:
maxQueueSize -
Method Detail

size

public int size()
Description copied from class: LinkedTransferQueue
Returns the number of elements in this queue. If this queue contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

Beware that, unlike in most collections, this method is NOT a constant-time operation. Because of the asynchronous nature of these queues, determining the current number of elements requires an O(n) traversal.

Specified by:
size in interface Collection<E>
Overrides:
size in class LinkedTransferQueue<E>
Returns:
the number of elements in this queue

remainingCapacity

public int remainingCapacity()
Returns the number of free slots in this queue.

Specified by:
remainingCapacity in interface BlockingQueue<E>
Overrides:
remainingCapacity in class LinkedTransferQueue<E>
Returns:
number of free slots.

poll

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

poll

public E poll(long timeout,
              TimeUnit unit)
       throws InterruptedException
Specified by:
poll in interface BlockingQueue<E>
Overrides:
poll in class LinkedTransferQueue<E>
Throws:
InterruptedException

tryTransfer

public boolean tryTransfer(E e)
Description copied from class: LinkedTransferQueue
Transfers the element to a waiting consumer immediately, if possible.

More precisely, transfers the specified element immediately if there exists a consumer already waiting to receive it (in LinkedTransferQueue.take() or timed poll), otherwise returning false without enqueuing the element.

Specified by:
tryTransfer in interface TransferQueue<E>
Overrides:
tryTransfer in class LinkedTransferQueue<E>
Parameters:
e - the element to transfer
Returns:
true if the element was transferred, else false

offer

public boolean offer(E e)
Description copied from class: LinkedTransferQueue
Inserts the specified element at the tail of this queue. As the queue is unbounded, this method will never return false.

Specified by:
offer in interface BlockingQueue<E>
Specified by:
offer in interface Queue<E>
Overrides:
offer in class LinkedTransferQueue<E>
Returns:
true (as specified by BlockingQueue.offer)

put

public void put(E e)
Description copied from class: LinkedTransferQueue
Inserts the specified element at the tail of this queue. As the queue is unbounded, this method will never block.

Specified by:
put in interface BlockingQueue<E>
Overrides:
put in class LinkedTransferQueue<E>


Copyright © 2009-2011 JolBox. All Rights Reserved.