E - data type of queued recordspublic class FastBlockingQueue<E>
extends java.util.AbstractCollection<E>
implements java.util.concurrent.BlockingQueue<E>
| Constructor and Description |
|---|
FastBlockingQueue(int capacity)
Create a FastBlockingQueue with the specified maximum queue backlog.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(E e)
Add an element to the queue, throwing an exception if the queue is full and has no
more room.
|
void |
clear()
Remove everything from the queue.
|
boolean |
contains(java.lang.Object o)
Check if this queue contains the specified object (or at least an instance that matches by
equals()).
|
int |
drainTo(java.util.Collection<? super E> c)
Removes all available elements from this queue and adds them
to the given collection.
|
int |
drainTo(java.util.Collection<? super E> c,
int maxElements)
Removes at most the given number of available elements from
this queue and adds them to the given collection.
|
int |
drainTo(E[] a)
Removes at most the given number of available elements from
this queue and adds them to the given array.
|
E |
element()
Retrieves, but does not remove, the head of this queue.
|
void |
expandCapacity(int capacity)
Enlarge the queue's backlog capacity.
|
int |
getCapacity()
Report the total number of queue slots in the queue.
|
java.util.Iterator<E> |
iterator()
Returns an iterator over the elements contained in this collection.
|
boolean |
offer(E e)
Inserts the specified element into this queue if it is possible to do
so immediately without violating capacity restrictions.
|
boolean |
offer(E e,
long timeout,
java.util.concurrent.TimeUnit unit)
Inserts the specified element into this queue, waiting up to the
specified wait time if necessary for space to become available.
|
E |
peek()
Retrieves, but does not remove, the head of this queue,
or returns null if this queue is empty.
|
E |
poll()
Retrieves and removes the head of this queue,
or returns null if this queue is empty.
|
E |
poll(long timeout,
java.util.concurrent.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)
Inserts the specified element into this queue, waiting if necessary
for space to become available.
|
int |
remainingCapacity()
Returns the number of additional elements that this queue can ideally
(in the absence of memory or resource constraints) accept without
blocking, or Integer.MAX_VALUE if there is no intrinsic
limit.
|
E |
remove()
Retrieves and removes the head of this queue.
|
int |
size()
Returns the number of elements in this queue.
|
E |
take()
Retrieves and removes the head of this queue, waiting if necessary
until an element becomes available.
|
addAll, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toStringclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitpublic FastBlockingQueue(int capacity)
capacity - int maximum capacity of queuepublic void clear()
public int drainTo(java.util.Collection<? super E> c)
drainTo in interface java.util.concurrent.BlockingQueue<E>c - the collection to transfer elements intojava.lang.UnsupportedOperationException - if addition of elements
is not supported by the specified collectionjava.lang.ClassCastException - if the class of an element of this queue
prevents it from being added to the specified collectionjava.lang.NullPointerException - if the specified collection is nulljava.lang.IllegalArgumentException - if the specified collection is this
queue, or some property of an element of this queue prevents
it from being added to the specified collectionpublic java.util.Iterator<E> iterator()
public int size()
public void put(E e) throws java.lang.InterruptedException
put in interface java.util.concurrent.BlockingQueue<E>e - the element to addjava.lang.InterruptedException - if interrupted while waitingjava.lang.ClassCastException - if the class of the specified element
prevents it from being added to this queuejava.lang.NullPointerException - if the specified element is nulljava.lang.IllegalArgumentException - if some property of the specified
element prevents it from being added to this queuepublic boolean offer(E e, long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
offer in interface java.util.concurrent.BlockingQueue<E>e - the element to addtimeout - how long to wait before giving up, in units of
unitunit - a TimeUnit determining how to interpret the
timeout parameterjava.lang.InterruptedException - if interrupted while waitingjava.lang.ClassCastException - if the class of the specified element
prevents it from being added to this queuejava.lang.NullPointerException - if the specified element is nulljava.lang.IllegalArgumentException - if some property of the specified
element prevents it from being added to this queuepublic E take() throws java.lang.InterruptedException
take in interface java.util.concurrent.BlockingQueue<E>java.lang.InterruptedException - if interrupted while waitingpublic E poll(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
poll in interface java.util.concurrent.BlockingQueue<E>timeout - how long to wait before giving up, in units of
unitunit - a TimeUnit determining how to interpret the
timeout parameterjava.lang.InterruptedException - if interrupted while waitingpublic int remainingCapacity()
Note that you cannot always tell if an attempt to insert an element will succeed by inspecting remainingCapacity because it may be the case that another thread is about to insert or remove an element.
remainingCapacity in interface java.util.concurrent.BlockingQueue<E>public int drainTo(java.util.Collection<? super E> c, int maxElements)
drainTo in interface java.util.concurrent.BlockingQueue<E>c - the collection to transfer elements intomaxElements - the maximum number of elements to transferjava.lang.UnsupportedOperationException - if addition of elements
is not supported by the specified collectionjava.lang.ClassCastException - if the class of an element of this queue
prevents it from being added to the specified collectionjava.lang.NullPointerException - if the specified collection is nulljava.lang.IllegalArgumentException - if the specified collection is this
queue, or some property of an element of this queue prevents
it from being added to the specified collectionpublic int drainTo(E[] a)
a - the array to transfer elements intojava.lang.UnsupportedOperationException - if addition of elements
is not supported by the specified collectionjava.lang.ClassCastException - if the class of an element of this queue
prevents it from being added to the specified collectionjava.lang.NullPointerException - if the specified collection is nulljava.lang.IllegalArgumentException - if the specified collection is this
queue, or some property of an element of this queue prevents
it from being added to the specified collectionpublic boolean offer(E e)
add(E), which can fail to insert an element only
by throwing an exception.offer in interface java.util.concurrent.BlockingQueue<E>offer in interface java.util.Queue<E>e - the element to addjava.lang.ClassCastException - if the class of the specified element
prevents it from being added to this queuejava.lang.NullPointerException - if the specified element is null and
this queue does not permit null elementsjava.lang.IllegalArgumentException - if some property of this element
prevents it from being added to this queuepublic boolean add(E e)
public E poll()
poll in interface java.util.Queue<E>public E peek()
peek in interface java.util.Queue<E>public E element()
peek only in that it throws an exception if
this queue is empty.
This implementation returns the result of peek unless the queue is empty.
element in interface java.util.Queue<E>java.util.NoSuchElementException - if this queue is emptypublic E remove()
poll only in that it throws an exception if this
queue is empty.
This implementation returns the result of poll unless the queue is empty.
remove in interface java.util.Queue<E>java.util.NoSuchElementException - if this queue is emptypublic boolean contains(java.lang.Object o)
public int getCapacity()
public void expandCapacity(int capacity)
capacity - the new backlog capacity for the queue