Package org.apache.ignite
Interface IgniteQueue<T>
-
- All Superinterfaces:
AutoCloseable,BlockingQueue<T>,Closeable,Collection<T>,Iterable<T>,Queue<T>
public interface IgniteQueue<T> extends BlockingQueue<T>, Closeable
This interface provides a rich API for working with distributed queues based on In-Memory Data Grid.Overview
Cache queue provides an access to cache elements using typical queue API. Cache queue also implementsCollectioninterface and provides all methods from collections includingCollection.addAll(Collection),Collection.removeAll(Collection), andCollection.retainAll(Collection)methods for bulk operations. Note that allCollectionmethods in the queue may throwIgniteExceptionin case of failure.Bounded vs Unbounded
Queues can beunboundedorbounded.Boundedqueues can have maximum capacity. Queue capacity can be set at creation time and cannot be changed later. Here is an example of how to createboundedLIFOqueue with capacity of1000items.IgniteQueue<String> queue = cache().queue("anyName", LIFO, 1000); ... queue.add("item");Forboundedqueues blocking operations, such astake()orput(Object)are available. These operations will block until queue capacity changes to make the operation possible.Collocated vs Non-collocated
Queue items can be placed on one node or distributed throughout grid nodes (governed bycollocatedparameter).Non-collocatedmode is provided only for partitioned caches. Ifcollocatedparameter istrue, 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 arecollocated.Here is an example of how create
unboundedqueue in non-collocated mode.IgniteQueue<String> queue = cache().queue("anyName", 0 /*unbounded*/, false /*non-collocated*/); ... queue.add("item");Creating Cache Queues
Instances of distributed cache queues can be created by calling the following method onIgniteAPI:
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description booleanadd(T item)booleanaddAll(Collection<? extends T> items)<R> RaffinityCall(IgniteCallable<R> job)Executes given job on collocated queue on the node where the queue is located (a.k.a. affinity co-location).voidaffinityRun(IgniteRunnable job)Executes given job on collocated queue on the node where the queue is located (a.k.a. affinity co-location).booleanbounded()Returnstrueif this queue is bounded.intcapacity()Gets maximum number of elements of the queue.voidclear()voidclear(int batchSize)Removes all of the elements from this queue.voidclose()Removes this queue.booleancollocated()Returnstrueif this queue can be kept on the one node only.booleancontains(Object item)booleancontainsAll(Collection<?> items)booleanisEmpty()Iterator<T>iterator()Stringname()Gets queue name.booleanoffer(T item)booleanoffer(T item, long timeout, TimeUnit unit)Tpeek()Tpoll()Tpoll(long timeout, TimeUnit unit)voidput(T item)booleanremove(Object item)booleanremoveAll(Collection<?> items)booleanremoved()Gets status of queue.booleanretainAll(Collection<?> items)intsize()Ttake()Object[]toArray()<T> T[]toArray(T[] a)<V1> IgniteQueue<V1>withKeepBinary()Returns queue that will operate with binary objects.-
Methods inherited from interface java.util.concurrent.BlockingQueue
drainTo, drainTo, remainingCapacity
-
Methods inherited from interface java.util.Collection
equals, hashCode, parallelStream, removeIf, spliterator, stream, toArray
-
-
-
-
Method Detail
-
name
String name()
Gets queue name.- Returns:
- Queue name.
-
add
boolean add(T item) throws IgniteException
- Specified by:
addin interfaceBlockingQueue<T>- Specified by:
addin interfaceCollection<T>- Specified by:
addin interfaceQueue<T>- Throws:
IgniteException
-
offer
boolean offer(T item) throws IgniteException
- Specified by:
offerin interfaceBlockingQueue<T>- Specified by:
offerin interfaceQueue<T>- Throws:
IgniteException
-
offer
boolean offer(T item, long timeout, TimeUnit unit) throws IgniteException
- Specified by:
offerin interfaceBlockingQueue<T>- Throws:
IgniteException
-
addAll
boolean addAll(Collection<? extends T> items) throws IgniteException
- Specified by:
addAllin interfaceCollection<T>- Throws:
IgniteException
-
contains
boolean contains(Object item) throws IgniteException
- Specified by:
containsin interfaceBlockingQueue<T>- Specified by:
containsin interfaceCollection<T>- Throws:
IgniteException
-
containsAll
boolean containsAll(Collection<?> items) throws IgniteException
- Specified by:
containsAllin interfaceCollection<T>- Throws:
IgniteException
-
clear
void clear() throws IgniteException- Specified by:
clearin interfaceCollection<T>- Throws:
IgniteException
-
remove
boolean remove(Object item) throws IgniteException
- Specified by:
removein interfaceBlockingQueue<T>- Specified by:
removein interfaceCollection<T>- Throws:
IgniteException
-
removeAll
boolean removeAll(Collection<?> items) throws IgniteException
- Specified by:
removeAllin interfaceCollection<T>- Throws:
IgniteException
-
isEmpty
boolean isEmpty() throws IgniteException- Specified by:
isEmptyin interfaceCollection<T>- Throws:
IgniteException
-
iterator
Iterator<T> iterator() throws IgniteException
- Specified by:
iteratorin interfaceCollection<T>- Specified by:
iteratorin interfaceIterable<T>- Throws:
IgniteException
-
toArray
Object[] toArray() throws IgniteException
- Specified by:
toArrayin interfaceCollection<T>- Throws:
IgniteException
-
toArray
<T> T[] toArray(T[] a) throws IgniteException- Specified by:
toArrayin interfaceCollection<T>- Throws:
IgniteException
-
retainAll
boolean retainAll(Collection<?> items) throws IgniteException
- Specified by:
retainAllin interfaceCollection<T>- Throws:
IgniteException
-
size
int size() throws IgniteException
- Specified by:
sizein interfaceCollection<T>- Throws:
IgniteException
-
poll
T poll() throws IgniteException
- Specified by:
pollin interfaceQueue<T>- Throws:
IgniteException
-
peek
T peek() throws IgniteException
- Specified by:
peekin interfaceQueue<T>- Throws:
IgniteException
-
put
void put(T item) throws IgniteException
- Specified by:
putin interfaceBlockingQueue<T>- Throws:
IgniteException
-
take
T take() throws IgniteException
- Specified by:
takein interfaceBlockingQueue<T>- Throws:
IgniteException
-
poll
T poll(long timeout, TimeUnit unit) throws IgniteException
- Specified by:
pollin interfaceBlockingQueue<T>- Throws:
IgniteException
-
clear
void clear(int batchSize) throws IgniteExceptionRemoves all of the elements from this queue. Method is used in massive queues with huge numbers of elements.- Parameters:
batchSize- Batch size.- Throws:
IgniteException- if operation failed.
-
close
void close() throws IgniteExceptionRemoves this queue.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IgniteException- if operation failed.
-
capacity
int capacity()
Gets maximum number of elements of the queue.- Returns:
- Maximum number of elements. If queue is unbounded
Integer.MAX_SIZEwill return.
-
bounded
boolean bounded()
Returnstrueif this queue is bounded.- Returns:
trueif this queue is bounded.
-
collocated
boolean collocated()
Returnstrueif this queue can be kept on the one node only. Returnsfalseif this queue can be kept on the many nodes.- Returns:
trueif this queue is incollocatedmodefalseotherwise.
-
removed
boolean removed()
Gets status of queue.- Returns:
trueif queue was removed from cachefalseotherwise.
-
affinityRun
void affinityRun(IgniteRunnable job) throws IgniteException
Executes given job on collocated queue on the node where the queue is located (a.k.a. affinity co-location).This is not supported for non-collocated queues.
- Parameters:
job- Job which will be co-located with the queue.- Throws:
IgniteException- If job failed.
-
affinityCall
<R> R affinityCall(IgniteCallable<R> job) throws IgniteException
Executes given job on collocated queue on the node where the queue is located (a.k.a. affinity co-location).This is not supported for non-collocated queues.
- Type Parameters:
R- Type of the job result.- Parameters:
job- Job which will be co-located with the queue.- Returns:
- Job result.
- Throws:
IgniteException- If job failed.
-
withKeepBinary
<V1> IgniteQueue<V1> withKeepBinary()
Returns queue that will operate with binary objects. This is similar toIgniteCache.withKeepBinary()but for queues.- Type Parameters:
V1- Type of the queued binary objects.- Returns:
- New queue instance for binary objects.
-
-