Class GridCacheQueueAdapter<T>
- java.lang.Object
-
- java.util.AbstractCollection<T>
-
- org.apache.ignite.internal.processors.datastructures.GridCacheQueueAdapter<T>
-
- All Implemented Interfaces:
Closeable,AutoCloseable,Iterable<T>,Collection<T>,BlockingQueue<T>,Queue<T>,IgniteQueue<T>
- Direct Known Subclasses:
GridAtomicCacheQueueImpl,GridTransactionalCacheQueueImpl
public abstract class GridCacheQueueAdapter<T> extends AbstractCollection<T> implements IgniteQueue<T>
Common code forIgniteQueueimplementation.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classGridCacheQueueAdapter.AddProcessorprotected static classGridCacheQueueAdapter.ClearProcessorprotected static classGridCacheQueueAdapter.PollProcessorprotected static classGridCacheQueueAdapter.RemoveProcessor
-
Field Summary
Fields Modifier and Type Field Description protected GridCacheAdaptercacheCache.protected GridCacheContext<?,?>cctxCache context.protected IgniteUuididQueue unique ID.protected IgniteLoggerlogLogger.protected static longQUEUE_REMOVED_IDXValue returned by closure updating queue header indicating that queue was removed.protected GridCacheQueueHeaderKeyqueueKeyQueue header key.protected StringqueueNameQueue name.
-
Constructor Summary
Constructors Modifier Constructor Description protectedGridCacheQueueAdapter(String queueName, GridCacheQueueHeader hdr, GridCacheContext<?,?> cctx)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description booleanadd(T item)<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.protected voidcheckRemoved(@Nullable GridCacheQueueHeader hdr)Checks queue state, throwsIllegalStateExceptionif queue was removed.protected voidcheckRemoved(Long idx)Checks result of closure modifying queue header, throwsIllegalStateExceptionif queue was removed.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.intdrainTo(Collection<? super T> c)intdrainTo(Collection<? super T> c, int maxElements)Telement()booleanequals(Object o)inthashCode()IgniteUuidid()protected QueueItemKeyitemKey(Long idx)Iterator<T>iterator()Stringname()Gets queue name.booleanoffer(T item, long timeout, TimeUnit unit)voidonClientDisconnected()Release all semaphores used in blocking operations in case of client disconnect.voidonHeaderChanged(GridCacheQueueHeader hdr)voidonKernalStop()Grid stop callback.voidonRemoved(boolean throw0)Marks queue as removed.Tpeek()Tpoll(long timeout, TimeUnit unit)voidput(T item)intremainingCapacity()Tremove()booleanremoved()Gets status of queue.protected abstract voidremoveItem(long rmvIdx)Removes item with given index from queue.intsize()Ttake()StringtoString()<V1> IgniteQueue<V1>withKeepBinary()Returns queue that will operate with binary objects.-
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, spliterator, stream, toArray
-
-
-
-
Field Detail
-
QUEUE_REMOVED_IDX
protected static final long QUEUE_REMOVED_IDX
Value returned by closure updating queue header indicating that queue was removed.- See Also:
- Constant Field Values
-
log
protected final IgniteLogger log
Logger.
-
cctx
protected final GridCacheContext<?,?> cctx
Cache context.
-
cache
protected final GridCacheAdapter cache
Cache.
-
queueName
protected final String queueName
Queue name.
-
queueKey
protected final GridCacheQueueHeaderKey queueKey
Queue header key.
-
id
protected final IgniteUuid id
Queue unique ID.
-
-
Constructor Detail
-
GridCacheQueueAdapter
protected GridCacheQueueAdapter(String queueName, GridCacheQueueHeader hdr, GridCacheContext<?,?> cctx)
- Parameters:
queueName- Queue name.hdr- Queue hdr.cctx- Cache context.
-
-
Method Detail
-
name
public String name()
Gets queue name.- Specified by:
namein interfaceIgniteQueue<T>- Returns:
- Queue name.
-
add
public boolean add(T item)
- Specified by:
addin interfaceBlockingQueue<T>- Specified by:
addin interfaceCollection<T>- Specified by:
addin interfaceIgniteQueue<T>- Specified by:
addin interfaceQueue<T>- Overrides:
addin classAbstractCollection<T>
-
collocated
public boolean collocated()
Returnstrueif this queue can be kept on the one node only. Returnsfalseif this queue can be kept on the many nodes.- Specified by:
collocatedin interfaceIgniteQueue<T>- Returns:
trueif this queue is incollocatedmodefalseotherwise.
-
capacity
public int capacity()
Gets maximum number of elements of the queue.- Specified by:
capacityin interfaceIgniteQueue<T>- Returns:
- Maximum number of elements. If queue is unbounded
Integer.MAX_SIZEwill return.
-
bounded
public boolean bounded()
Returnstrueif this queue is bounded.- Specified by:
boundedin interfaceIgniteQueue<T>- Returns:
trueif this queue is bounded.
-
size
public int size()
- Specified by:
sizein interfaceCollection<T>- Specified by:
sizein interfaceIgniteQueue<T>- Specified by:
sizein classAbstractCollection<T>
-
peek
@Nullable public T peek() throws IgniteException
- Specified by:
peekin interfaceIgniteQueue<T>- Specified by:
peekin interfaceQueue<T>- Throws:
IgniteException
-
iterator
public Iterator<T> iterator()
- Specified by:
iteratorin interfaceCollection<T>- Specified by:
iteratorin interfaceIgniteQueue<T>- Specified by:
iteratorin interfaceIterable<T>- Specified by:
iteratorin classAbstractCollection<T>
-
put
public void put(T item) throws IgniteException
- Specified by:
putin interfaceBlockingQueue<T>- Specified by:
putin interfaceIgniteQueue<T>- Throws:
IgniteException
-
offer
public boolean offer(T item, long timeout, TimeUnit unit) throws IgniteException
- Specified by:
offerin interfaceBlockingQueue<T>- Specified by:
offerin interfaceIgniteQueue<T>- Throws:
IgniteException
-
take
@Nullable public T take() throws IgniteException
- Specified by:
takein interfaceBlockingQueue<T>- Specified by:
takein interfaceIgniteQueue<T>- Throws:
IgniteException
-
poll
@Nullable public T poll(long timeout, TimeUnit unit) throws IgniteException
- Specified by:
pollin interfaceBlockingQueue<T>- Specified by:
pollin interfaceIgniteQueue<T>- Throws:
IgniteException
-
remainingCapacity
public int remainingCapacity()
- Specified by:
remainingCapacityin interfaceBlockingQueue<T>
-
clear
public void clear()
- Specified by:
clearin interfaceCollection<T>- Specified by:
clearin interfaceIgniteQueue<T>- Overrides:
clearin classAbstractCollection<T>
-
clear
public void clear(int batchSize) throws IgniteExceptionRemoves all of the elements from this queue. Method is used in massive queues with huge numbers of elements.- Specified by:
clearin interfaceIgniteQueue<T>- Parameters:
batchSize- Batch size.- Throws:
IgniteException- if operation failed.
-
drainTo
public int drainTo(Collection<? super T> c)
- Specified by:
drainToin interfaceBlockingQueue<T>
-
drainTo
public int drainTo(Collection<? super T> c, int maxElements)
- Specified by:
drainToin interfaceBlockingQueue<T>
-
removed
public boolean removed()
Gets status of queue.- Specified by:
removedin interfaceIgniteQueue<T>- Returns:
trueif queue was removed from cachefalseotherwise.
-
affinityRun
public void affinityRun(IgniteRunnable job)
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.
- Specified by:
affinityRunin interfaceIgniteQueue<T>- Parameters:
job- Job which will be co-located with the queue.
-
affinityCall
public <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).This is not supported for non-collocated queues.
- Specified by:
affinityCallin interfaceIgniteQueue<T>- Type Parameters:
R- Type of the job result.- Parameters:
job- Job which will be co-located with the queue.- Returns:
- Job result.
-
withKeepBinary
public <V1> IgniteQueue<V1> withKeepBinary()
Returns queue that will operate with binary objects. This is similar toIgniteCache.withKeepBinary()but for queues.- Specified by:
withKeepBinaryin interfaceIgniteQueue<T>- Type Parameters:
V1- Type of the queued binary objects.- Returns:
- New queue instance for binary objects.
-
checkRemoved
protected final void checkRemoved(Long idx)
Checks result of closure modifying queue header, throwsIllegalStateExceptionif queue was removed.- Parameters:
idx- Result of closure execution.
-
checkRemoved
protected final void checkRemoved(@Nullable @Nullable GridCacheQueueHeader hdr)Checks queue state, throwsIllegalStateExceptionif queue was removed.- Parameters:
hdr- Queue hdr.
-
onClientDisconnected
public void onClientDisconnected()
Release all semaphores used in blocking operations in case of client disconnect.
-
onRemoved
public void onRemoved(boolean throw0)
Marks queue as removed.- Parameters:
throw0- Iftruethen throwsIllegalStateException.
-
onHeaderChanged
public void onHeaderChanged(GridCacheQueueHeader hdr)
- Parameters:
hdr- Queue header.
-
onKernalStop
public void onKernalStop()
Grid stop callback.
-
id
public IgniteUuid id()
- Returns:
- Queue unique ID.
-
removeItem
protected abstract void removeItem(long rmvIdx) throws IgniteCheckedExceptionRemoves item with given index from queue.- Parameters:
rmvIdx- Index of item to be removed.- Throws:
IgniteCheckedException- If failed.
-
itemKey
protected QueueItemKey itemKey(Long idx)
- Parameters:
idx- Item index.- Returns:
- Item key.
-
close
public void close()
Removes this queue.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceIgniteQueue<T>
-
equals
public boolean equals(Object o)
- Specified by:
equalsin interfaceCollection<T>- Overrides:
equalsin classObject
-
hashCode
public int hashCode()
- Specified by:
hashCodein interfaceCollection<T>- Overrides:
hashCodein classObject
-
toString
public String toString()
- Overrides:
toStringin classAbstractCollection<T>
-
-