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. Future marked as done after all result pages are ready. Note that completeness of this future doesn't depend on whether all data are delievered to user or not. This class provides `Iterator` interface to access result data. Handling of recieved pages is triggered by `Iterator` methods. Reducing of result data (order, limit) is controlled by `CacheQueryReducer`.

### Field Summary

Fields
`protected GridCacheContext<K,V>` `cctx` Cache context.
`protected boolean` `loc`
`protected static IgniteLogger` `log` Logger.
`protected GridCacheQueryBean` `qry`
`protected CacheQueryReducer<R>` `reducer` Reducer of cache query results.

### Constructor Summary

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

### Method Summary

All Methods Instance Methods Abstract Methods Concrete Methods
`abstract void` `awaitFirstItemAvailable()` TODO: IGNITE-15728 Provide custom reducer for ScanQueryFallbackClosableIterator.
`GridCacheContext<K,V>` `cacheContext()`
`boolean` `cancel()` Default no-op implementation that always returns `false`.
`protected abstract void` `cancelQuery(Throwable err)` Cancels query on remote nodes and cleanes owned resources.
`void` `close()`
`long` `endTime()`
`boolean` `fields()`
`IgniteLogger` `logger()`
`R` `next()` Returns next element from result set.
`boolean` `onDone(Collection<R> res, Throwable err)` Callback to notify that future is finished.
`protected abstract void` `onError(Throwable err)` Invokes in case of this future error.
`protected void` `onMeta(IndexQueryResultMeta meta)` Handles query meta data from query node.
`protected void` `onNodeLeft(UUID evtNodeId)` Callback that invoked in case of a node left cluster.
`protected abstract void` `onPage(UUID nodeId, Collection<R> data, boolean lastPage)` Handles new data page from query node.
`void` `onPage(@Nullable UUID nodeId, @Nullable IndexQueryResultMeta metadata, @Nullable Collection<?> data, @Nullable Throwable err, boolean lastPage)` Entrypoint for handling query result page from remote node.
`void` `onTimeout()` Timeout callback.
`GridCacheQueryBean` `query()`
`IgniteUuid` `timeoutId()`
`String` `toString()`

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

`chain, chain, chainCompose, chainCompose, error, get, get, get, getUninterruptibly, ignoreInterrupts, isCancelled, isDone, isFailed, listen, onCancelled, onDone, onDone, onDone, onDone, reset, 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, chainCompose, chainCompose, error, get, get, get, getUninterruptibly, 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

#### reducer

    protected CacheQueryReducer<R> reducer

Reducer of cache query results.

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

#### logger

    public IgniteLogger logger()

Overrides:
  `logger` in class `GridFutureAdapter<Collection<R>>`
Returns:
  Logger instance.

#### fields

    public boolean fields()

Returns:
  If fields query.

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

#### cacheContext

    public GridCacheContext<K,V> cacheContext()

Returns:
  Cache context.

#### awaitFirstItemAvailable

    public abstract void awaitFirstItemAvailable()
                                          throws IgniteCheckedException

TODO: IGNITE-15728 Provide custom reducer for ScanQueryFallbackClosableIterator. Waits for the first item is available to return.

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

#### onNodeLeft

    protected void onNodeLeft(UUID evtNodeId)

Callback that invoked in case of a node left cluster.

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

#### onPage

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

Entrypoint for handling query result page from remote node.

Parameters:
  `nodeId` - Sender node.
  `metadata` - Query response metadata.
  `data` - Page data.
  `err` - Error (if was).
  `lastPage` - Whether it is the last page for sender node.

#### onError

    protected abstract void onError(Throwable err)

Invokes in case of this future error.

#### onPage

    protected abstract void onPage(UUID nodeId,
                                   Collection<R> data,
                                   boolean lastPage)

Handles new data page from query node.

#### onMeta

    protected void onMeta(IndexQueryResultMeta meta)

Handles query meta data from query node.

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

#### 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(Throwable err)
                                 throws IgniteCheckedException

Cancels query on remote nodes and cleanes owned resources.

Parameters:
  `err` - If query was cancelled with error.
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>>`

${current.year} Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Database and Caching Platform | : ver. 2.14.0
Release Date | : September 29 2022