public class Queue extends Object implements Serializable
Queue
class implements a First-In-First-Out
(FIFO) list of objects.
A queue is for the exclusive use of one single consumer, whereas many
producers may access it. It is ready for use after instantiation. A
producer may wait for the queue to be empty by calling the
stop()
method. This method returns when the queue is
actually empty, and prohibits any further call to the push
method. To be able to use the queue again, it must be re-started through
the start()
method.
Modifier and Type | Field and Description |
---|---|
private boolean |
closed
true if the queue has been closed. |
private List<Object> |
elements
The list holding queue elements.
|
private static long |
serialVersionUID
define serialVersionUID for interoperability
|
private boolean |
stopping
true if a producer called the stop()
method. |
Constructor and Description |
---|
Queue()
Constructs a
Queue instance. |
Modifier and Type | Method and Description |
---|---|
void |
clear()
Removes all of the elements from this queue.
|
void |
close()
Closes the queue.
|
Object |
get()
Waits for an object to be pushed in the queue, and eventually returns
it without removing it.
|
Object |
get(long timeout)
Waits for an object to be pushed in the queue or a specified amount of time has elapsed.
|
Object |
getAndPop()
Waits for an object to be pushed in the queue, then removes and returns
the object at the top of this queue.
|
boolean |
isEmpty()
Returns true if this queue contains no elements.
|
String |
list()
Returns a stringified form of the queue.
|
Object |
pop()
Removes and returns the object at the top of this queue.
|
void |
push(Object item)
Pushes an item at the end of this queue.
|
boolean |
search(Comparator<Object> c,
Object o2) |
int |
size()
Returns the number of elements in this list.
|
void |
start()
Authorizes the use of the queue by producers.
|
void |
stop()
Stops the queue by returning when it is empty and prohibiting any
further producers call to the
push method. |
private static final long serialVersionUID
private boolean stopping
true
if a producer called the stop()
method.private boolean closed
true
if the queue has been closed.public boolean search(Comparator<Object> c, Object o2)
public void push(Object item)
item
- The item to be pushed at the end of this queue.StoppedQueueException
- If the queue is stopping or stopped.public Object get() throws InterruptedException
InterruptedException
- interrupted.public Object get(long timeout) throws InterruptedException
timeout
- The maximum time to wait in milliseconds.InterruptedException
- interrupted.public Object pop()
EmptyQueueException
- If the queue is empty.public Object getAndPop() throws InterruptedException
InterruptedException
- interrupted.public void start()
public void stop() throws InterruptedException
push
method.InterruptedException
- interrupted.public void close()
get()
with an
InterruptedException
.public boolean isEmpty()
public void clear()
public int size()
public String list()
Copyright © 2021 ScalAgent D.T.. All rights reserved.