public class FifoQueueImpl<T> extends Object implements FifoQueue<T>
This interface defines a queue that uses F irst In,
F irst O ut semantics when adding and removing objects.
Each object that is added to the queue is effectively placed at the end of
the list of previous elements. Each call to remove
will result
in the removal of the next element, or the oldest element in the queue.
Modifier and Type | Field and Description |
---|---|
protected BlockingQueue<T> |
m_delegate
The delegate list where queue elements are stored.
|
Constructor and Description |
---|
FifoQueueImpl()
Constructs a new First In, First Out queue that can be used to exchange
data.
|
Modifier and Type | Method and Description |
---|---|
void |
add(T element)
Inserts a new element into the queue.
|
boolean |
add(T element,
long timeout)
Inserts a new element into the queue.
|
boolean |
isEmpty()
Used to test if the current queue has no stored elements.
|
T |
remove()
Removes the oldest element from the queue.
|
T |
remove(long timeout)
Removes the next element from the queue if one becomes available before
the timeout expires.
|
int |
size()
Returns the current number of elements that are in the queue.
|
protected final BlockingQueue<T> m_delegate
public FifoQueueImpl()
public void add(T element) throws InterruptedException
add
in interface FifoQueue<T>
element
- The object to append to the queue.FifoQueueException
- if any.InterruptedException
- if any.public boolean add(T element, long timeout) throws InterruptedException
timeout
expires, then a false
value is returned to the caller.
Inserts a new element into the queue. If the queue has reached an
implementation limit and the timeout
expires, then a false
value is returned to the caller.add
in interface FifoQueue<T>
element
- The object to append to the queue.timeout
- The time to wait on the insertion to succeed.InterruptedException
- Thrown if the thread is interrupted.public T remove() throws InterruptedException
remove
in interface FifoQueue<T>
FifoQueueException
- if any.InterruptedException
- if any.public T remove(long timeout) throws InterruptedException
null
reference is returned to the caller.
Removes the next element from the queue if one becomes available before
the timeout expires. If the timeout expires before an element is
available then a null
reference is returned to the caller.remove
in interface FifoQueue<T>
timeout
- The time to wait on an object to be available.null
if one is
not available.FifoQueueException
- Thrown if a queue error occurs.InterruptedException
- Thrown if the thread is interrupted.public int size()
Copyright © 2017. All rights reserved.