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 providesIteratorinterface to access result data. Handling of recieved pages is triggered byIteratormethods. Reducing of result data (order, limit) is controlled byCacheQueryReducer.
-
-
Field Summary
Fields Modifier and Type Field Description protected GridCacheContext<K,V>cctxCache context.protected booleanlocprotected static IgniteLoggerlogLogger.protected GridCacheQueryBeanqryprotected CacheQueryReducer<R>reducerReducer of cache query results.
-
Constructor Summary
Constructors Modifier Constructor Description protectedGridCacheQueryFutureAdapter()protectedGridCacheQueryFutureAdapter(GridCacheContext<K,V> cctx, GridCacheQueryBean qry, boolean loc)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract voidawaitFirstItemAvailable()TODO: IGNITE-15728 Provide custom reducer for ScanQueryFallbackClosableIterator.GridCacheContext<K,V>cacheContext()booleancancel()Default no-op implementation that always returnsfalse.protected abstract voidcancelQuery(Throwable err)Cancels query on remote nodes and cleanes owned resources.voidclose()longendTime()booleanfields()IgniteLoggerlogger()Rnext()Returns next element from result set.booleanonDone(Collection<R> res, Throwable err)Callback to notify that future is finished.protected abstract voidonError(Throwable err)Invokes in case of this future error.protected voidonMeta(IndexQueryResultMeta meta)Handles query meta data from query node.protected voidonNodeLeft(UUID evtNodeId)Callback that invoked in case of a node left cluster.voidonPage(@Nullable UUID nodeId, @Nullable IndexQueryResultMeta metadata, @Nullable Collection<?> data, @Nullable Throwable err, boolean lastPage)Entrypoint for handling query result page from remote node.protected abstract voidonPage(UUID nodeId, Collection<R> data, boolean lastPage)Handles new data page from query node.voidonTimeout()Timeout callback.GridCacheQueryBeanquery()IgniteUuidtimeoutId()StringtoString()-
Methods inherited from class org.apache.ignite.internal.util.future.GridFutureAdapter
chain, chain, chain, chain, chainCompose, chainCompose, error, get, get, get, getUninterruptibly, ignoreInterrupts, isCancelled, isDone, isFailed, listen, 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, chain, chain, chainCompose, chainCompose, error, get, get, get, getUninterruptibly, isCancelled, listen, 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:
loggerin classGridFutureAdapter<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:
nextin interfaceCacheQueryFuture<K>- Returns:
- Next fetched element or
nullif all the elements have been fetched.
-
cacheContext
public GridCacheContext<K,V> cacheContext()
- Returns:
- Cache context.
-
awaitFirstItemAvailable
public abstract void awaitFirstItemAvailable() throws IgniteCheckedExceptionTODO: 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-nullexception is passed in the result value will be ignored.- Overrides:
onDonein classGridFutureAdapter<Collection<R>>- Parameters:
res- Optional result.err- Optional error.- Returns:
Trueif result was set by this call.
-
cancel
public boolean cancel() throws IgniteCheckedExceptionDefault no-op implementation that always returnsfalse. Futures that do support cancellation should override this method and callGridFutureAdapter.onCancelled()callback explicitly if cancellation indeed did happen.- Specified by:
cancelin interfaceCacheQueryFuture<K>- Specified by:
cancelin interfaceIgniteInternalFuture<K>- Overrides:
cancelin classGridFutureAdapter<Collection<R>>- Returns:
Trueif 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:
timeoutIdin interfaceGridTimeoutObject- Returns:
- ID of the object.
-
endTime
public long endTime()
- Specified by:
endTimein interfaceGridTimeoutObject- Returns:
- End time.
-
onTimeout
public void onTimeout()
Timeout callback.- Specified by:
onTimeoutin interfaceGridTimeoutObject
-
close
public void close() throws Exception- Specified by:
closein interfaceAutoCloseable- Throws:
Exception
-
toString
public String toString()
- Overrides:
toStringin classGridFutureAdapter<Collection<R>>
-
-