org.apache.ignite.internal.processors.datastructures

## 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 for `IgniteQueue` implementation.

### Nested Class Summary

Nested Classes
`protected static class` `GridCacheQueueAdapter.AddProcessor`
`protected static class` `GridCacheQueueAdapter.ClearProcessor`
`protected static class` `GridCacheQueueAdapter.PollProcessor`
`protected static class` `GridCacheQueueAdapter.RemoveProcessor`

### Field Summary

Fields
`protected GridCacheAdapter` `cache` Cache.
`protected GridCacheContext<?,?>` `cctx` Cache context.
`protected IgniteUuid` `id` Queue unique ID.
`protected IgniteLogger` `log` Logger.
`protected static int` `MAX_UPDATE_RETRIES`
`protected static long` `QUEUE_REMOVED_IDX` Value returned by closure updating queue header indicating that queue was removed.
`protected GridCacheQueueHeaderKey` `queueKey` Queue header key.
`protected String` `queueName` Queue name.
`protected static long` `RETRY_DELAY`

### Constructor Summary

Constructors
`protected` `GridCacheQueueAdapter(String queueName, GridCacheQueueHeader hdr, GridCacheContext<?,?> cctx)`

### Method Summary

Methods
`boolean` `add(T item)`
`boolean` `bounded()` Returns `true` if this queue is bounded.
`int` `capacity()` Gets maximum number of elements of the queue.
`protected void` `checkRemoved(GridCacheQueueHeader hdr)` Checks queue state, throws `IllegalStateException` if queue was removed.
`protected void` `checkRemoved(Long idx)` Checks result of closure modifying queue header, throws `IllegalStateException` if queue was removed.
`void` `clear()`
`void` `clear(int batchSize)` Removes all of the elements from this queue.
`void` `close()` Removes this queue.
`boolean` `collocated()` Returns `true` if this queue can be kept on the one node only.
`int` `drainTo(Collection<? super T> c)`
`int` `drainTo(Collection<? super T> c, int maxElements)`
`T` `element()`
`boolean` `equals(Object o)`
`int` `hashCode()`
`IgniteUuid` `id()`
`protected org.apache.ignite.internal.processors.datastructures.GridCacheQueueItemKey` `itemKey(Long idx)`
`Iterator<T>` `iterator()`
`String` `name()` Gets queue name.
`boolean` `offer(T item, long timeout, TimeUnit unit)`
`void` `onHeaderChanged(GridCacheQueueHeader hdr)`
`void` `onKernalStop()` Grid stop callback.
`void` `onRemoved(boolean throw0)` Marks queue as removed.
`T` `peek()`
`T` `poll(long timeout, TimeUnit unit)`
`void` `put(T item)`
`int` `remainingCapacity()`
`T` `remove()`
`boolean` `removed()` Gets status of queue.
`protected abstract void` `removeItem(long rmvIdx)` Removes item with given index from queue.
`int` `size()`
`T` `take()`
`String` `toString()`

### 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 org.apache.ignite.IgniteQueue

`addAll, contains, containsAll, isEmpty, offer, poll, remove, removeAll, retainAll, toArray, 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

#### MAX_UPDATE_RETRIES

    protected static final int MAX_UPDATE_RETRIES

See Also:
  Constant Field Values

#### RETRY_DELAY

    protected static final long RETRY_DELAY

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:
  `name` in interface `IgniteQueue<T>`
Returns:
  Queue name.

#### add

    public boolean add(T item)

Specified by:
  `add` in interface `Collection<T>`
Specified by:
  `add` in interface `BlockingQueue<T>`
Specified by:
  `add` in interface `Queue<T>`
Specified by:
  `add` in interface `IgniteQueue<T>`
Overrides:
  `add` in class `AbstractCollection<T>`

#### collocated

    public boolean collocated()

Returns `true` if this queue can be kept on the one node only. Returns `false` if this queue can be kept on the many nodes.

Specified by:
  `collocated` in interface `IgniteQueue<T>`
Returns:
  `true` if this queue is in `collocated` mode `false` otherwise.

#### capacity

    public int capacity()

Gets maximum number of elements of the queue.

Specified by:
  `capacity` in interface `IgniteQueue<T>`
Returns:
  Maximum number of elements. If queue is unbounded `Integer.MAX_SIZE` will return.

#### bounded

    public boolean bounded()

Returns `true` if this queue is bounded.

Specified by:
  `bounded` in interface `IgniteQueue<T>`
Returns:
  `true` if this queue is bounded.

#### size

    public int size()

Specified by:
  `size` in interface `Collection<T>`
Specified by:
  `size` in interface `IgniteQueue<T>`
Specified by:
  `size` in class `AbstractCollection<T>`

#### peek

    @Nullable
    public T peek()
           throws IgniteException

Specified by:
  `peek` in interface `Queue<T>`
Specified by:
  `peek` in interface `IgniteQueue<T>`
Throws:
  `IgniteException`

#### remove

    public T remove()

Specified by:
  `remove` in interface `Queue<T>`

#### element

    public T element()

Specified by:
  `element` in interface `Queue<T>`

#### iterator

    public Iterator<T> iterator()

Specified by:
  `iterator` in interface `Iterable<T>`
Specified by:
  `iterator` in interface `Collection<T>`
Specified by:
  `iterator` in interface `IgniteQueue<T>`
Specified by:
  `iterator` in class `AbstractCollection<T>`

#### put

    public void put(T item)
             throws IgniteException

Specified by:
  `put` in interface `BlockingQueue<T>`
Specified by:
  `put` in interface `IgniteQueue<T>`
Throws:
  `IgniteException`

#### offer

    public boolean offer(T item,
                long timeout,
                TimeUnit unit)
                  throws IgniteException

Specified by:
  `offer` in interface `BlockingQueue<T>`
Specified by:
  `offer` in interface `IgniteQueue<T>`
Throws:
  `IgniteException`

#### take

    @Nullable
    public T take()
           throws IgniteException

Specified by:
  `take` in interface `BlockingQueue<T>`
Specified by:
  `take` in interface `IgniteQueue<T>`
Throws:
  `IgniteException`

#### poll

    @Nullable
    public T poll(long timeout,
                  TimeUnit unit)
           throws IgniteException

Specified by:
  `poll` in interface `BlockingQueue<T>`
Specified by:
  `poll` in interface `IgniteQueue<T>`
Throws:
  `IgniteException`

#### remainingCapacity

    public int remainingCapacity()

Specified by:
  `remainingCapacity` in interface `BlockingQueue<T>`

#### clear

    public void clear()

Specified by:
  `clear` in interface `Collection<T>`
Specified by:
  `clear` in interface `IgniteQueue<T>`
Overrides:
  `clear` in class `AbstractCollection<T>`

#### clear

    public 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.

Specified by:
  `clear` in interface `IgniteQueue<T>`
Parameters:
  `batchSize` - Batch size.
Throws:
  `IgniteException` - if operation failed.

#### drainTo

    public int drainTo(Collection<? super T> c)

Specified by:
  `drainTo` in interface `BlockingQueue<T>`

#### drainTo

    public int drainTo(Collection<? super T> c,
              int maxElements)

Specified by:
  `drainTo` in interface `BlockingQueue<T>`

#### removed

    public boolean removed()

Gets status of queue.

Specified by:
  `removed` in interface `IgniteQueue<T>`
Returns:
  `true` if queue was removed from cache `false` otherwise.

#### checkRemoved

    protected final void checkRemoved(Long idx)

Checks result of closure modifying queue header, throws `IllegalStateException` if queue was removed.

Parameters:
  `idx` - Result of closure execution.

#### checkRemoved

    protected final void checkRemoved(@Nullable
                    GridCacheQueueHeader hdr)

Checks queue state, throws `IllegalStateException` if queue was removed.

Parameters:
  `hdr` - Queue hdr.

#### onRemoved

    public void onRemoved(boolean throw0)

Marks queue as removed.

Parameters:
  `throw0` - If `true` then throws `IllegalStateException`.

#### 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 IgniteCheckedException

Removes item with given index from queue.

Parameters:
  `rmvIdx` - Index of item to be removed.
Throws:
  `IgniteCheckedException` - If failed.

#### itemKey

    protected org.apache.ignite.internal.processors.datastructures.GridCacheQueueItemKey itemKey(Long idx)

Parameters:
  `idx` - Item index.
Returns:
  Item key.

#### close

    public void close()

Removes this queue.

Specified by:
  `close` in interface `Closeable`
Specified by:
  `close` in interface `AutoCloseable`
Specified by:
  `close` in interface `IgniteQueue<T>`

#### equals

    public boolean equals(Object o)

Specified by:
  `equals` in interface `Collection<T>`
Overrides:
  `equals` in class `Object`

#### hashCode

    public int hashCode()

Specified by:
  `hashCode` in interface `Collection<T>`
Overrides:
  `hashCode` in class `Object`

#### toString

    public String toString()

Overrides:
  `toString` in class `AbstractCollection<T>`

2015 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Fabric | : ver. 1.0.0-RC1
Release Date | : February 17 2015