public interface GridCacheQueue<T> extends BlockingQueue<T>
Collection interface and provides all methods from collections including
Collection.addAll(Collection), Collection.removeAll(Collection), and
Collection.retainAll(Collection) methods for bulk operations. Note that all
Collection methods in the queue may throw GridRuntimeException in case
of failure.
All queue operations have synchronous and asynchronous counterparts.
unbounded or bounded. Bounded queues can
have maximum capacity. Queue capacity can be set at creation time and cannot be
changed later. Here is an example of how to create bounded LIFO queue with
capacity of 1000 items.
GridCacheQueue<String> queue = cache().queue("anyName", LIFO, 1000);
...
queue.add("item");
For bounded queues blocking operations, such as take() or put(Object)
are available. These operations will block until queue capacity changes to make the operation
possible.
collocated parameter). Non-collocated mode is provided only
for partitioned caches. If collocated parameter is true, then all queue items
will be collocated on one node, otherwise items will be distributed through all grid nodes.
Unless explicitly specified, by default queues are collocated.
Here is an example of how create unbounded queue
in non-collocated mode.
GridCacheQueue<String> queue = cache().queue("anyName", 0 /*unbounded*/, false /*non-collocated*/);
...
queue.add("item");
GridCacheDataStructures API:
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(T item) |
boolean |
addAll(Collection<? extends T> items) |
boolean |
bounded()
Returns
true if this queue is bounded. |
int |
capacity()
Gets maximum number of elements of the queue.
|
void |
clear() |
void |
clear(int batchSize)
Removes all of the elements from this queue.
|
boolean |
collocated()
Returns
true if this queue can be kept on the one node only. |
boolean |
contains(Object item) |
boolean |
containsAll(Collection<?> items) |
boolean |
isEmpty() |
Iterator<T> |
iterator() |
String |
name()
Gets queue name.
|
boolean |
offer(T item) |
boolean |
offer(T item,
long timeout,
TimeUnit unit) |
T |
peek() |
T |
poll() |
T |
poll(long timeout,
TimeUnit unit) |
void |
put(T item) |
boolean |
remove(Object item) |
boolean |
removeAll(Collection<?> items) |
boolean |
removed()
Gets status of queue.
|
boolean |
retainAll(Collection<?> items) |
int |
size() |
T |
take() |
Object[] |
toArray() |
<T> T[] |
toArray(T[] a) |
drainTo, drainTo, remainingCapacityequals, hashCodeString name()
boolean add(T item) throws GridRuntimeException
add in interface BlockingQueue<T>add in interface Collection<T>add in interface Queue<T>GridRuntimeExceptionboolean offer(T item) throws GridRuntimeException
offer in interface BlockingQueue<T>offer in interface Queue<T>GridRuntimeExceptionboolean offer(T item, long timeout, TimeUnit unit) throws GridRuntimeException
offer in interface BlockingQueue<T>GridRuntimeExceptionboolean addAll(Collection<? extends T> items) throws GridRuntimeException
addAll in interface Collection<T>GridRuntimeExceptionboolean contains(Object item) throws GridRuntimeException
contains in interface BlockingQueue<T>contains in interface Collection<T>GridRuntimeExceptionboolean containsAll(Collection<?> items) throws GridRuntimeException
containsAll in interface Collection<T>GridRuntimeExceptionvoid clear()
throws GridRuntimeException
clear in interface Collection<T>GridRuntimeExceptionboolean remove(Object item) throws GridRuntimeException
remove in interface BlockingQueue<T>remove in interface Collection<T>GridRuntimeExceptionboolean removeAll(Collection<?> items) throws GridRuntimeException
removeAll in interface Collection<T>GridRuntimeExceptionboolean isEmpty()
throws GridRuntimeException
isEmpty in interface Collection<T>GridRuntimeExceptionIterator<T> iterator() throws GridRuntimeException
iterator in interface Collection<T>iterator in interface Iterable<T>GridRuntimeExceptionObject[] toArray() throws GridRuntimeException
toArray in interface Collection<T>GridRuntimeException<T> T[] toArray(T[] a)
throws GridRuntimeException
toArray in interface Collection<T>GridRuntimeExceptionboolean retainAll(Collection<?> items) throws GridRuntimeException
retainAll in interface Collection<T>GridRuntimeExceptionint size()
throws GridRuntimeException
size in interface Collection<T>GridRuntimeException@Nullable T poll() throws GridRuntimeException
poll in interface Queue<T>GridRuntimeException@Nullable T peek() throws GridRuntimeException
peek in interface Queue<T>GridRuntimeExceptionvoid put(T item) throws GridRuntimeException
put in interface BlockingQueue<T>GridRuntimeException@Nullable T take() throws GridRuntimeException
take in interface BlockingQueue<T>GridRuntimeException@Nullable T poll(long timeout, TimeUnit unit) throws GridRuntimeException
poll in interface BlockingQueue<T>GridRuntimeExceptionvoid clear(int batchSize)
throws GridRuntimeException
batchSize - Batch size.GridRuntimeException - if operation failed.int capacity()
throws GridException
Integer.MAX_SIZE will return.GridException - If operation failed.boolean bounded()
throws GridException
true if this queue is bounded.true if this queue is bounded.GridException - If operation failed.boolean collocated()
throws GridException
true if this queue can be kept on the one node only.
Returns false if this queue can be kept on the many nodes.true if this queue is in collocated mode false otherwise.GridException - If operation failed.boolean removed()
true if queue was removed from cache false otherwise.Copyright © 2014. All rights reserved.