Package gov.usgs.earthquake.util
Class RoundRobinBlockingQueue<T>
- java.lang.Object
-
- gov.usgs.earthquake.util.RoundRobinQueue<T>
-
- gov.usgs.earthquake.util.RoundRobinBlockingQueue<T>
-
- Type Parameters:
T
- queue item type.
- All Implemented Interfaces:
java.lang.Iterable<T>
,java.util.Collection<T>
,java.util.concurrent.BlockingQueue<T>
,java.util.Queue<T>
- Direct Known Subclasses:
ListenerNotificationQueue
,NotificationEventBlockingQueue
public class RoundRobinBlockingQueue<T> extends RoundRobinQueue<T> implements java.util.concurrent.BlockingQueue<T>
Round Robin Blocking Queue.put(Object)
andtake()
are recommended, as other methods internally call these methods.
-
-
Constructor Summary
Constructors Constructor Description RoundRobinBlockingQueue()
Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
add(T e)
Add an item to the queue.boolean
contains(java.lang.Object e)
Check if queue contains an item.int
drainTo(java.util.Collection<? super T> c)
Empty queue into a collection.int
drainTo(java.util.Collection<? super T> c, int max)
Empty queue into a collection, stopping after max elements.boolean
offer(T e)
Offer an item to the queue.boolean
offer(T e, long timeout, java.util.concurrent.TimeUnit unit)
Offer an item to the queue.T
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(T e)
Put an item in the queue.int
remainingCapacity()
Unbounded queues return Integer.MAX_VALUE.boolean
remove(java.lang.Object e)
Remove an object from the queue.T
take()
Remove an object from the queue.-
Methods inherited from class gov.usgs.earthquake.util.RoundRobinQueue
addAll, clear, containsAll, element, getQueueId, isEmpty, iterator, peek, poll, remove, removeAll, retainAll, size, toArray, toArray, toList
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
-
-
Method Detail
-
add
public boolean add(T e)
Add an item to the queue.
-
contains
public boolean contains(java.lang.Object e)
Check if queue contains an item.- Specified by:
contains
in interfacejava.util.concurrent.BlockingQueue<T>
- Specified by:
contains
in interfacejava.util.Collection<T>
- Overrides:
contains
in classRoundRobinQueue<T>
-
offer
public boolean offer(T e)
Offer an item to the queue. Callsadd(Object)
, but returns false if any exceptions thrown.- Specified by:
offer
in interfacejava.util.concurrent.BlockingQueue<T>
- Specified by:
offer
in interfacejava.util.Queue<T>
- Overrides:
offer
in classRoundRobinQueue<T>
- Parameters:
e
- item to add- Returns:
- true if added, false otherwise.
-
offer
public boolean offer(T e, long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
Offer an item to the queue. Same asoffer(Object)
, this is an unbounded queue.- Specified by:
offer
in interfacejava.util.concurrent.BlockingQueue<T>
- Throws:
java.lang.InterruptedException
-
poll
public T poll(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
Retrieves and removes the head of this queue, waiting up to the specified wait time if necessary for an element to become available.- Specified by:
poll
in interfacejava.util.concurrent.BlockingQueue<T>
- Throws:
java.lang.InterruptedException
-
put
public void put(T e) throws java.lang.InterruptedException
Put an item in the queue.- Specified by:
put
in interfacejava.util.concurrent.BlockingQueue<T>
- Throws:
java.lang.InterruptedException
- if interrupted while acquiring lock.
-
remainingCapacity
public int remainingCapacity()
Unbounded queues return Integer.MAX_VALUE.- Specified by:
remainingCapacity
in interfacejava.util.concurrent.BlockingQueue<T>
- Returns:
- Integer.MAX_VALUE;
-
remove
public boolean remove(java.lang.Object e)
Remove an object from the queue.- Specified by:
remove
in interfacejava.util.concurrent.BlockingQueue<T>
- Specified by:
remove
in interfacejava.util.Collection<T>
- Overrides:
remove
in classRoundRobinQueue<T>
-
take
public T take() throws java.lang.InterruptedException
Remove an object from the queue.- Specified by:
take
in interfacejava.util.concurrent.BlockingQueue<T>
- Throws:
java.lang.InterruptedException
-
drainTo
public int drainTo(java.util.Collection<? super T> c)
Empty queue into a collection.- Specified by:
drainTo
in interfacejava.util.concurrent.BlockingQueue<T>
-
-