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 implementsCollection
interface and provides all methods from collections includingCollection.addAll(Collection)
,Collection.removeAll(Collection)
, andCollection.retainAll(Collection)
methods for bulk operations. Note that allCollection
methods in the queue may throwIgniteException
in case of failure.Bounded vs Unbounded
Queues can beunbounded
orbounded
.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 createbounded
LIFO
queue with capacity of1000
items.IgniteQueue<String> queue = cache().queue("anyName", LIFO, 1000); ... queue.add("item");
Forbounded
queues 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 bycollocated
parameter).Non-collocated
mode is provided only for partitioned caches. Ifcollocated
parameter 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
unbounded
queue 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 onIgnite
API:
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description boolean
add(T item)
boolean
addAll(Collection<? extends T> items)
<R> R
affinityCall(IgniteCallable<R> job)
Executes given job on collocated queue on the node where the queue is located (a.k.a. affinity co-location).void
affinityRun(IgniteRunnable job)
Executes given job on collocated queue on the node where the queue is located (a.k.a. affinity co-location).boolean
bounded()
Returnstrue
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.void
close()
Removes this queue.boolean
collocated()
Returnstrue
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)
<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:
add
in interfaceBlockingQueue<T>
- Specified by:
add
in interfaceCollection<T>
- Specified by:
add
in interfaceQueue<T>
- Throws:
IgniteException
-
offer
boolean offer(T item) throws IgniteException
- Specified by:
offer
in interfaceBlockingQueue<T>
- Specified by:
offer
in interfaceQueue<T>
- Throws:
IgniteException
-
offer
boolean offer(T item, long timeout, TimeUnit unit) throws IgniteException
- Specified by:
offer
in interfaceBlockingQueue<T>
- Throws:
IgniteException
-
addAll
boolean addAll(Collection<? extends T> items) throws IgniteException
- Specified by:
addAll
in interfaceCollection<T>
- Throws:
IgniteException
-
contains
boolean contains(Object item) throws IgniteException
- Specified by:
contains
in interfaceBlockingQueue<T>
- Specified by:
contains
in interfaceCollection<T>
- Throws:
IgniteException
-
containsAll
boolean containsAll(Collection<?> items) throws IgniteException
- Specified by:
containsAll
in interfaceCollection<T>
- Throws:
IgniteException
-
clear
void clear() throws IgniteException
- Specified by:
clear
in interfaceCollection<T>
- Throws:
IgniteException
-
remove
boolean remove(Object item) throws IgniteException
- Specified by:
remove
in interfaceBlockingQueue<T>
- Specified by:
remove
in interfaceCollection<T>
- Throws:
IgniteException
-
removeAll
boolean removeAll(Collection<?> items) throws IgniteException
- Specified by:
removeAll
in interfaceCollection<T>
- Throws:
IgniteException
-
isEmpty
boolean isEmpty() throws IgniteException
- Specified by:
isEmpty
in interfaceCollection<T>
- Throws:
IgniteException
-
iterator
Iterator<T> iterator() throws IgniteException
- Specified by:
iterator
in interfaceCollection<T>
- Specified by:
iterator
in interfaceIterable<T>
- Throws:
IgniteException
-
toArray
Object[] toArray() throws IgniteException
- Specified by:
toArray
in interfaceCollection<T>
- Throws:
IgniteException
-
toArray
<T> T[] toArray(T[] a) throws IgniteException
- Specified by:
toArray
in interfaceCollection<T>
- Throws:
IgniteException
-
retainAll
boolean retainAll(Collection<?> items) throws IgniteException
- Specified by:
retainAll
in interfaceCollection<T>
- Throws:
IgniteException
-
size
int size() throws IgniteException
- Specified by:
size
in interfaceCollection<T>
- Throws:
IgniteException
-
poll
T poll() throws IgniteException
- Specified by:
poll
in interfaceQueue<T>
- Throws:
IgniteException
-
peek
T peek() throws IgniteException
- Specified by:
peek
in interfaceQueue<T>
- Throws:
IgniteException
-
put
void put(T item) throws IgniteException
- Specified by:
put
in interfaceBlockingQueue<T>
- Throws:
IgniteException
-
take
T take() throws IgniteException
- Specified by:
take
in interfaceBlockingQueue<T>
- Throws:
IgniteException
-
poll
T poll(long timeout, TimeUnit unit) throws IgniteException
- Specified by:
poll
in interfaceBlockingQueue<T>
- Throws:
IgniteException
-
clear
void clear(int batchSize) throws IgniteException
Removes 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 IgniteException
Removes this queue.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in 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_SIZE
will return.
-
bounded
boolean bounded()
Returnstrue
if this queue is bounded.- Returns:
true
if this queue is bounded.
-
collocated
boolean collocated()
Returnstrue
if this queue can be kept on the one node only. Returnsfalse
if this queue can be kept on the many nodes.- Returns:
true
if this queue is incollocated
modefalse
otherwise.
-
removed
boolean removed()
Gets status of queue.- Returns:
true
if queue was removed from cachefalse
otherwise.
-
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.
-
-