org.apache.ignite.internal.processors.cache.query

## Class GridCacheQueryFutureAdapter<K,V,R>

- java.lang.Object
- - org.apache.ignite.internal.util.future.GridFutureAdapter<Collection<R>>
  - - org.apache.ignite.internal.processors.cache.query.GridCacheQueryFutureAdapter<K,V,R>

Type Parameters:
  `R` - Result type.

All Implemented Interfaces:
  AutoCloseable, IgniteInternalFuture<Collection<R>>, CacheQueryFuture<R>, GridTimeoutObject

Direct Known Subclasses:
  GridCacheDistributedQueryFuture, GridCacheLocalQueryFuture

    public abstract class GridCacheQueryFutureAdapter<K,V,R>
    extends GridFutureAdapter<Collection<R>>
    implements CacheQueryFuture<R>, GridTimeoutObject

Query future adapter.

### Field Summary

Fields
`protected GridCacheContext<K,V>` `cctx` Cache context.
`protected boolean` `loc`
`protected static IgniteLogger` `log` Logger.
`protected GridCacheQueryBean` `qry`

### Constructor Summary

Constructors
`protected` `GridCacheQueryFutureAdapter()`
`protected` `GridCacheQueryFutureAdapter(GridCacheContext<K,V> cctx, GridCacheQueryBean qry, boolean loc)`

### Method Summary

Methods
`abstract void` `awaitFirstPage()` Waits for the first page to be received from remote node(s), if any.
`boolean` `cancel()` Default no-op implementation that always returns `false`.
`protected abstract void` `cancelQuery()`
`void` `close()`
`long` `endTime()`
`protected void` `enqueue(Collection<?> col)`
`Collection<R>` `get()` Synchronously waits for completion of the computation and returns computation result.
`Collection<R>` `get(long timeout, TimeUnit unit)` Synchronously waits for completion of the computation for up to the timeout specified and returns computation result.
`Collection<R>` `getUninterruptibly()` Synchronously waits for completion of the computation and returns computation result ignoring interrupts.
`protected abstract void` `loadAllPages()` Loads all left pages.
`protected abstract void` `loadPage()` Loads next page.
`R` `next()` Returns next element from result set.
`Collection<R>` `nextPage()` Returns next page for the query.
`Collection<R>` `nextPage(long timeout)` Returns next page for the query.
`boolean` `onDone(Collection<R> res, Throwable err)` Callback to notify that future is finished.
`protected void` `onNodeLeft(UUID evtNodeId)`
`protected abstract boolean` `onPage(UUID nodeId, boolean last)`
`void` `onPage(UUID nodeId, Collection<?> data, Throwable err, boolean finished)`
`void` `onTimeout()` Timeout callback.
`void` `printMemoryStats()`
`GridCacheQueryBean` `query()`
`IgniteUuid` `timeoutId()`
`String` `toString()`

### Methods inherited from class org.apache.ignite.internal.util.future.GridFutureAdapter

`chain, chain, error, get, ignoreInterrupts, isCancelled, isDone, isFailed, listen, logger, onCancelled, onDone, onDone, onDone, onDone, result`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Methods inherited from interface org.apache.ignite.internal.processors.cache.query.CacheQueryFuture

`isDone`

### Methods inherited from interface org.apache.ignite.internal.IgniteInternalFuture

`chain, chain, error, get, isCancelled, listen, result`

### Field Detail

#### log

    protected static IgniteLogger log

Logger.

#### cctx

    protected GridCacheContext<K,V> cctx

Cache context.

#### qry

    protected final GridCacheQueryBean qry

#### loc

    protected boolean loc

### Constructor Detail

#### GridCacheQueryFutureAdapter

    protected GridCacheQueryFutureAdapter()

#### GridCacheQueryFutureAdapter

    protected GridCacheQueryFutureAdapter(GridCacheContext<K,V> cctx,
                               GridCacheQueryBean qry,
                               boolean loc)

Parameters:
  `cctx` - Context.
  `qry` - Query.
  `loc` - Local query or not.

### Method Detail

#### query

    public GridCacheQueryBean query()

Returns:
  Query.

#### onDone

    public boolean onDone(Collection<R> res,
                 Throwable err)

Callback to notify that future is finished. Note that if non-`null` exception is passed in the result value will be ignored.

Overrides:
  `onDone` in class `GridFutureAdapter<Collection<R>>`
Parameters:
  `res` - Optional result.
  `err` - Optional error.
Returns:
  `True` if result was set by this call.

#### next

    public R next()

Returns next element from result set.

This is a blocking call which will wait if there are no elements available immediately.

Specified by:
  `next` in interface `CacheQueryFuture<R>`
Returns:
  Next fetched element or `null` if all the elements have been fetched.

#### awaitFirstPage

    public abstract void awaitFirstPage()
                                 throws IgniteCheckedException

Waits for the first page to be received from remote node(s), if any.

Throws:
  `IgniteCheckedException` - If query execution failed with an error.

#### nextPage

    public Collection<R> nextPage()
                           throws IgniteCheckedException

Returns next page for the query.

Returns:
  Next page or `null` if no more pages available.
Throws:
  `IgniteCheckedException` - If fetch failed.

#### nextPage

    public Collection<R> nextPage(long timeout)
                           throws IgniteCheckedException

Returns next page for the query.

Parameters:
  `timeout` - Timeout.
Returns:
  Next page or `null` if no more pages available.
Throws:
  `IgniteCheckedException` - If fetch failed.

#### onNodeLeft

    protected void onNodeLeft(UUID evtNodeId)

Parameters:
  `evtNodeId` - Removed or failed node Id.

#### enqueue

    protected void enqueue(Collection<?> col)

Parameters:
  `col` - Collection.

#### onPage

    public void onPage(@Nullable
              UUID nodeId,
              @Nullable
              Collection<?> data,
              @Nullable
              Throwable err,
              boolean finished)

Parameters:
  `nodeId` - Sender node.
  `data` - Page data.
  `err` - Error (if was).
  `finished` - Finished or not.

#### get

    public Collection<R> get()
                      throws IgniteCheckedException

Synchronously waits for completion of the computation and returns computation result.

Specified by:
  `get` in interface `IgniteInternalFuture<Collection<R>>`
Overrides:
  `get` in class `GridFutureAdapter<Collection<R>>`
Returns:
  Computation result.
Throws:
  `IgniteInterruptedCheckedException` - Subclass of `IgniteCheckedException` thrown if the wait was interrupted.
  `IgniteFutureCancelledCheckedException` - Subclass of `IgniteCheckedException` throws if computation was cancelled.
  `IgniteCheckedException` - If computation failed.

#### get

    public Collection<R> get(long timeout,
                    TimeUnit unit)
                      throws IgniteCheckedException

Synchronously waits for completion of the computation for up to the timeout specified and returns computation result.

Specified by:
  `get` in interface `IgniteInternalFuture<Collection<R>>`
Overrides:
  `get` in class `GridFutureAdapter<Collection<R>>`
Parameters:
  `timeout` - The maximum time to wait.
  `unit` - The time unit of the `timeout` argument.
Returns:
  Computation result.
Throws:
  `IgniteInterruptedCheckedException` - Subclass of `IgniteCheckedException` thrown if the wait was interrupted.
  `IgniteFutureTimeoutCheckedException` - Subclass of `IgniteCheckedException` thrown if the wait was timed out.
  `IgniteFutureCancelledCheckedException` - Subclass of `IgniteCheckedException` throws if computation was cancelled.
  `IgniteCheckedException` - If computation failed.

#### getUninterruptibly

    public Collection<R> getUninterruptibly()
                                     throws IgniteCheckedException

Synchronously waits for completion of the computation and returns computation result ignoring interrupts.

Specified by:
  `getUninterruptibly` in interface `IgniteInternalFuture<Collection<R>>`
Overrides:
  `getUninterruptibly` in class `GridFutureAdapter<Collection<R>>`
Returns:
  Computation result.
Throws:
  `IgniteFutureCancelledCheckedException` - Subclass of `IgniteCheckedException` throws if computation was cancelled.
  `IgniteCheckedException` - If computation failed.

#### onPage

    protected abstract boolean onPage(UUID nodeId,
                 boolean last)

Parameters:
  `nodeId` - Sender node id.
  `last` - Whether page is last.
Returns:
  Is query finished or not.

#### loadPage

    protected abstract void loadPage()

Loads next page.

#### loadAllPages

    protected abstract void loadAllPages()
                                  throws IgniteInterruptedCheckedException

Loads all left pages.

Throws:
  `IgniteInterruptedCheckedException` - If thread is interrupted.

#### cancel

    public boolean cancel()
                   throws IgniteCheckedException

Default no-op implementation that always returns `false`. Futures that do support cancellation should override this method and call `GridFutureAdapter.onCancelled()` callback explicitly if cancellation indeed did happen.

Specified by:
  `cancel` in interface `IgniteInternalFuture<Collection<R>>`
Specified by:
  `cancel` in interface `CacheQueryFuture<R>`
Overrides:
  `cancel` in class `GridFutureAdapter<Collection<R>>`
Returns:
  `True` if future was canceled (i.e. was not finished prior to this call).
Throws:
  `IgniteCheckedException` - If cancellation failed.

#### cancelQuery

    protected abstract void cancelQuery()
                                 throws IgniteCheckedException

Throws:
  `IgniteCheckedException` - In case of error.

#### timeoutId

    public IgniteUuid timeoutId()

Specified by:
  `timeoutId` in interface `GridTimeoutObject`
Returns:
  ID of the object.

#### endTime

    public long endTime()

Specified by:
  `endTime` in interface `GridTimeoutObject`
Returns:
  End time.

#### onTimeout

    public void onTimeout()

Timeout callback.

Specified by:
  `onTimeout` in interface `GridTimeoutObject`

#### close

    public void close()
               throws Exception

Specified by:
  `close` in interface `AutoCloseable`
Throws:
  `Exception`

#### toString

    public String toString()

Overrides:
  `toString` in class `GridFutureAdapter<Collection<R>>`

#### printMemoryStats

    public void printMemoryStats()

2017 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Fabric | : ver. 2.0.0
Release Date | : April 30 2017