public class ReorderingBlockingQueue<E>
extends java.lang.Object
put(Object, long)
must be called with an object and a timestamp. Timestamps must be a contiguous interval of the
natural numbers starting at zero, and objects will be returned in timestamp order. Failure to
comply with the contract (i.e., missing timestamps) will cause the queue to block forever.
put(Object, long)
might block if there is not enough space to keep track of the
object (i.e., if its timestamp is too far in time w.r.t. the timestamp that would be
returned next by the queue). take()
might block if the object with the next
timestamp has not been put(Object, long)
yet.
All methods of this class complete in constant time.
Constructor | Description |
---|---|
ReorderingBlockingQueue(int capacity) |
Creates a
ReorderingBlockingQueue with the given fixed
capacity. |
Modifier and Type | Method | Description |
---|---|---|
boolean |
isEmpty() |
Returns whether this queue is empty.
|
void |
put(E e,
long timeStamp) |
Inserts an element with given timestamp, waiting for space to become available
if the timestamp of the element minus the current timestamp of the queue exceeds
the queue capacity.
|
int |
size() |
Returns the number of elements in this queue.
|
E |
take() |
Returns the element with the next timestamp, waiting until it is available.
|
public ReorderingBlockingQueue(int capacity)
ReorderingBlockingQueue
with the given fixed
capacity.capacity
- the capacity of this queue (will be rounded to the next power of two).public void put(E e, long timeStamp) throws java.lang.InterruptedException
e
- an element.timeStamp
- the timestamp of e
.java.lang.InterruptedException
public E take() throws java.lang.InterruptedException
Note that because of the reordering semantics, an invocation of this method on a nonempty queue might block nonetheless.
java.lang.InterruptedException
public int size()
isEmpty()
public boolean isEmpty()