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:
Iterable<T>
,Collection<T>
,BlockingQueue<T>
,Queue<T>
- Direct Known Subclasses:
ListenerNotificationQueue
,NotificationEventBlockingQueue
Round Robin Blocking Queue.
put(Object)
and take()
are recommended, as other methods
internally call these methods.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
Add an item to the queue.boolean
Check if queue contains an item.int
drainTo
(Collection<? super T> c) Empty queue into a collection.int
drainTo
(Collection<? super T> c, int max) Empty queue into a collection, stopping after max elements.boolean
Offer an item to the queue.boolean
Offer an item to the queue.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 an item in the queue.int
Unbounded queues return Integer.MAX_VALUE.boolean
Remove an object from the queue.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
Methods inherited from interface java.util.Collection
addAll, clear, containsAll, equals, hashCode, isEmpty, iterator, parallelStream, removeAll, removeIf, retainAll, size, spliterator, stream, toArray, toArray, toArray
-
Constructor Details
-
RoundRobinBlockingQueue
public RoundRobinBlockingQueue()Constructor
-
-
Method Details
-
add
Add an item to the queue.- Specified by:
add
in interfaceBlockingQueue<T>
- Specified by:
add
in interfaceCollection<T>
- Specified by:
add
in interfaceQueue<T>
- Overrides:
add
in classRoundRobinQueue<T>
- Parameters:
e
- item to add- Returns:
- true if added.
-
contains
Check if queue contains an item.- Specified by:
contains
in interfaceBlockingQueue<T>
- Specified by:
contains
in interfaceCollection<T>
- Overrides:
contains
in classRoundRobinQueue<T>
-
offer
Offer an item to the queue. Callsadd(Object)
, but returns false if any exceptions thrown.- Specified by:
offer
in interfaceBlockingQueue<T>
- Specified by:
offer
in interfaceQueue<T>
- Overrides:
offer
in classRoundRobinQueue<T>
- Parameters:
e
- item to add- Returns:
- true if added, false otherwise.
-
offer
Offer an item to the queue. Same asoffer(Object)
, this is an unbounded queue.- Specified by:
offer
in interfaceBlockingQueue<T>
- Throws:
InterruptedException
-
poll
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 interfaceBlockingQueue<T>
- Throws:
InterruptedException
-
put
Put an item in the queue.- Specified by:
put
in interfaceBlockingQueue<T>
- Throws:
InterruptedException
- if interrupted while acquiring lock.
-
remainingCapacity
public int remainingCapacity()Unbounded queues return Integer.MAX_VALUE.- Specified by:
remainingCapacity
in interfaceBlockingQueue<T>
- Returns:
- Integer.MAX_VALUE;
-
remove
Remove an object from the queue.- Specified by:
remove
in interfaceBlockingQueue<T>
- Specified by:
remove
in interfaceCollection<T>
- Overrides:
remove
in classRoundRobinQueue<T>
-
take
Remove an object from the queue.- Specified by:
take
in interfaceBlockingQueue<T>
- Throws:
InterruptedException
-
drainTo
Empty queue into a collection.- Specified by:
drainTo
in interfaceBlockingQueue<T>
-
drainTo
Empty queue into a collection, stopping after max elements.- Specified by:
drainTo
in interfaceBlockingQueue<T>
-