|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.AbstractCollection<E>
org.ka2ddo.util.FastBlockingQueue<E>
E
- data type of queued recordspublic class FastBlockingQueue<E>
This attempts to make a simpler and faster FIFO queue than ArrayBlockingQueue with no guarantees regarding fairness, minimum execution time, and minimum transient memory allocations. Optimized for single producer and single consumer.
Constructor Summary | |
---|---|
FastBlockingQueue(int capacity)
Create a FastBlockingQueue with the specified maximum queue backlog. |
Method Summary | |
---|---|
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. |
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. |
Methods inherited from class java.util.AbstractCollection |
---|
addAll, 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 |
---|
remove |
Methods inherited from interface java.util.Collection |
---|
addAll, containsAll, equals, hashCode, isEmpty, removeAll, retainAll, toArray, toArray |
Constructor Detail |
---|
public FastBlockingQueue(int capacity)
capacity
- int maximum capacity of queueMethod Detail |
---|
public void clear()
clear
in interface java.util.Collection<E>
clear
in class java.util.AbstractCollection<E>
public int drainTo(java.util.Collection<? super E> c)
drainTo
in interface java.util.concurrent.BlockingQueue<E>
c
- the collection to transfer elements into
java.lang.UnsupportedOperationException
- if addition of elements
is not supported by the specified collection
java.lang.ClassCastException
- if the class of an element of this queue
prevents it from being added to the specified collection
java.lang.NullPointerException
- if the specified collection is null
java.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()
iterator
in interface java.lang.Iterable<E>
iterator
in interface java.util.Collection<E>
iterator
in class java.util.AbstractCollection<E>
public int size()
size
in interface java.util.Collection<E>
size
in class java.util.AbstractCollection<E>
public void put(E e) throws java.lang.InterruptedException
put
in interface java.util.concurrent.BlockingQueue<E>
e
- the element to add
java.lang.InterruptedException
- if interrupted while waiting
java.lang.ClassCastException
- if the class of the specified element
prevents it from being added to this queue
java.lang.NullPointerException
- if the specified element is null
java.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 parameter
java.lang.InterruptedException
- if interrupted while waiting
java.lang.ClassCastException
- if the class of the specified element
prevents it from being added to this queue
java.lang.NullPointerException
- if the specified element is null
java.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 parameter
java.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 transfer
java.lang.UnsupportedOperationException
- if addition of elements
is not supported by the specified collection
java.lang.ClassCastException
- if the class of an element of this queue
prevents it from being added to the specified collection
java.lang.NullPointerException
- if the specified collection is null
java.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 into
java.lang.UnsupportedOperationException
- if addition of elements
is not supported by the specified collection
java.lang.ClassCastException
- if the class of an element of this queue
prevents it from being added to the specified collection
java.lang.NullPointerException
- if the specified collection is null
java.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 add
java.lang.ClassCastException
- if the class of the specified element
prevents it from being added to this queue
java.lang.NullPointerException
- if the specified element is null and
this queue does not permit null elements
java.lang.IllegalArgumentException
- if some property of this element
prevents it from being added to this queuepublic boolean add(E e)
add
in interface java.util.Collection<E>
add
in interface java.util.concurrent.BlockingQueue<E>
add
in interface java.util.Queue<E>
add
in class java.util.AbstractCollection<E>
java.lang.IllegalStateException
- if queue is already fullpublic 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)
contains
in interface java.util.Collection<E>
contains
in interface java.util.concurrent.BlockingQueue<E>
contains
in class java.util.AbstractCollection<E>
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |