Package org.ros.concurrent
Class CircularBlockingDeque<T>
java.lang.Object
org.ros.concurrent.CircularBlockingDeque<T>
- All Implemented Interfaces:
Iterable<T>
A deque that removes head or tail elements when the number of elements
exceeds the limit and blocks on
takeFirst() and takeLast() when
there are no elements available.- Author:
- damonkohler@google.com (Damon Kohler)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanAdds the specified entry to the tail of the queue, overwriting older entries if necessary.booleanAdds the specified entry to the tail of the queue, overwriting older entries if necessary.booleanisEmpty()iterator()Returns an iterator over the queue.Retrieves, but does not remove, the head of this queue, returningnullif this queue is empty.peekLast()Retrieves, but does not remove, the tail of this queue, returningnullif this queue is empty.Retrieves the head of the queue, blocking if necessary until an entry is available.takeLast()Retrieves the tail of the queue, blocking if necessary until an entry is available.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
CircularBlockingDeque
public CircularBlockingDeque(int capacity) - Parameters:
capacity- the maximum number of elements allowed in the queue
-
-
Method Details
-
addLast
Adds the specified entry to the tail of the queue, overwriting older entries if necessary.- Parameters:
entry- the entry to add- Returns:
true
-
addFirst
Adds the specified entry to the tail of the queue, overwriting older entries if necessary.- Parameters:
entry- the entry to add- Returns:
true
-
takeFirst
Retrieves the head of the queue, blocking if necessary until an entry is available.- Returns:
- the head of the queue
- Throws:
InterruptedException
-
peekFirst
Retrieves, but does not remove, the head of this queue, returningnullif this queue is empty.- Returns:
- the head of this queue, or
nullif this queue is empty
-
takeLast
Retrieves the tail of the queue, blocking if necessary until an entry is available.- Returns:
- the tail of the queue
- Throws:
InterruptedException
-
peekLast
Retrieves, but does not remove, the tail of this queue, returningnullif this queue is empty.- Returns:
- the tail of this queue, or
nullif this queue is empty
-
isEmpty
public boolean isEmpty() -
iterator
Returns an iterator over the queue.Note that this is not thread-safe and that
Iterator.remove()is unsupported.
-