AsyncDataQuery
implementations.
This class cannot be inherited or instantiated.
Thread safety
Unless otherwise noted, methods of this class are safe to use by multiple threads concurrently.Synchronization transparency
Methods of this class are synchronization transparent.- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic <QueryArgType,DataType>
CachedByIDAsyncDataQuery<QueryArgType,DataType> cacheByID(AsyncDataQuery<? super QueryArgType, ? extends DataType> wrappedQuery, ReferenceType refType, ObjectCache refCreator) Creates and returns anAsyncDataQuerywhich createsAsyncDataLinkinstances caching their results and cachesAsyncDataLinkinstances based on a unique ID provided to the query with the input argument.static <QueryArgType,DataType>
CachedByIDAsyncDataQuery<QueryArgType,DataType> cacheByID(AsyncDataQuery<? super QueryArgType, ? extends DataType> wrappedQuery, ReferenceType refType, ObjectCache refCreator, int maxCacheSize) Creates and returns anAsyncDataQuerywhich createsAsyncDataLinkinstances caching their results and cachesAsyncDataLinkinstances based on a unique ID provided to the query with the input argument.static <QueryArgType,DataType>
CachedAsyncDataQuery<QueryArgType,DataType> cacheLinks(AsyncDataQuery<? super QueryArgType, DataType> wrappedQuery) Creates and returns anAsyncDataQuerywhich cachesAsyncDataLinkinstances based on the input of the query.static <QueryArgType,DataType>
CachedAsyncDataQuery<QueryArgType,DataType> cacheLinks(AsyncDataQuery<? super QueryArgType, DataType> wrappedQuery, int maxCacheSize) Creates and returns anAsyncDataQuerywhich cachesAsyncDataLinkinstances based on the input of the query.static <QueryArgType,DataType>
AsyncDataQuery<CachedDataRequest<QueryArgType>,DataType> cacheResults(AsyncDataQuery<? super QueryArgType, ? extends DataType> wrappedQuery) Creates and returns anAsyncDataQuerywhich createsAsyncDataLinkinstances caching their results.static <QueryArgType,OldDataType, NewDataType>
AsyncDataQuery<QueryArgType,NewDataType> convertResultsAsync(AsyncDataQuery<? super QueryArgType, ? extends OldDataType> wrappedQuery, AsyncDataQuery<? super OldDataType, ? extends NewDataType> converter) Creates anAsyncDataQuerywhich will provide the same data as the specifiedAsyncDataQuerybut applies a conversion on the provided data defined by anAsyncDataQuery.static <QueryArgType,OldDataType, NewDataType>
AsyncDataQuery<QueryArgType,NewDataType> convertResultsSync(AsyncDataQuery<? super QueryArgType, ? extends OldDataType> wrappedQuery, DataConverter<? super OldDataType, ? extends NewDataType> converter) Creates a newAsyncDataQuerywhich will provide the same data as the specifiedAsyncDataQuerybut will apply the user defined conversion on the data.static <QueryArgType,DataType>
AsyncDataQuery<QueryArgType,DataType> extractCachedResults(AsyncDataQuery<? super QueryArgType, RefCachedData<DataType>> query) Creates anAsyncDataQuerywhich will provide thedata partof the specified query without theVolatileReferenceto it.static <QueryArgType,DataType>
AsyncDataQuery<QueryArgType,DataWithUid<DataType>> markResultsWithUid(AsyncDataQuery<? super QueryArgType, ? extends DataType> query) Returns anAsyncDataQuerywhich returns the same results as the specifiedAsyncDataLinkbut creates aDataWithUidobject with a new uniqueIDfrom the provided data of the specifiedAsyncDataQuery.static <QueryArgType,DataType>
AsyncDataQuery<QueryArgType,DataType> removeUidFromResults(AsyncDataQuery<? super QueryArgType, DataWithUid<DataType>> query)
-
Method Details
-
cacheResults
public static <QueryArgType,DataType> AsyncDataQuery<CachedDataRequest<QueryArgType>,DataType> cacheResults(AsyncDataQuery<? super QueryArgType, ? extends DataType> wrappedQuery) Creates and returns anAsyncDataQuerywhich createsAsyncDataLinkinstances caching their results. The returnedAsyncDataQueryis based on a user specified one.Note that the
AsyncDataLinkinstances themselves will not be cached. That is, requesting anAsyncDataLinkfrom the returnedAsyncDataQuerywill return a new, independentAsyncDataLinkinstance. Only theseAsyncDataLinkinstances will cache their results. The caching mechanism done by theseAsyncDataLinkinstances is the same as those created by theAsyncLinks.cacheResult(AsyncDataLink, ReferenceType,ObjectCache)method.The
ObjectCacheand other parameters defining the exact caching mechanism must be specified when querying newAsyncDataLinkfrom the returnedAsyncDataQuery.As an example: Assume that the specified
AsyncDataQueryloads a file by its filename as a byte array. The returnedAsyncDataQuerywill then load the files as a byte array as well, however individualAsyncDataLinkinstances will cache their results and will not reread the file. However whenever a newAsyncDataLinkis returned by the returnedAsyncDataQueryit will still need to reread the file at the first attempt of loading regardless that a file with the same name has been requested from the returnedAsyncDataQuery.- Type Parameters:
QueryArgType- the type of the input of the specifiedAsyncDataQueryDataType- the type of the data returned by the specified (and the returned)AsyncDataQuery- Parameters:
wrappedQuery- theAsyncDataQuerywhoseAsyncDataLinkinstances are to cache their results. This argument cannot benull.- Returns:
- the
AsyncDataQuerywhich will provide the same data as the specifiedAsyncDataQuerybutAsyncDataLinkinstances created by it will cache their results. Notice that this returned query requires additional inputs to specify how data is to be cached. This method never returnsnull. - Throws:
NullPointerException- thrown if the specifiedAsyncDataQueryisnull- See Also:
-
cacheLinks
public static <QueryArgType,DataType> CachedAsyncDataQuery<QueryArgType,DataType> cacheLinks(AsyncDataQuery<? super QueryArgType, DataType> wrappedQuery) Creates and returns anAsyncDataQuerywhich cachesAsyncDataLinkinstances based on the input of the query. That is, the returnedAsyncDataQuerymay return the sameAsyncDataLinkfor the same input (based onequals). The data provided by theAsyncDataLinkinstances are not cached by the returned query. Those can be cached by using thecacheResultsmethod.The
AsyncDataQuerycreated by this method caches only at most 128AsyncDataLinkinstances and when this limit is exceeded, the one used least recently is discarded from the cache. Also a lease time can be specified when requesting anAsyncDataLinkwhen it must be removed from the cache and theAsyncDataLinkneeds to be recreated if requested again.Note that most often you want to cache both the
AsyncDataLinkand the data provided by them. Assume that there is a query which loads the content of a file as a byte array by file name:
In the above example codeAsyncDataQuery<Path, byte[]> baseQuery = ...; AsyncDataQuery<CachedLinkRequest<CachedDataRequest<Path>>, byte[]> cachedQuery; cachedQuery = AsyncQueries.cacheLinks(AsyncQueries.cacheResults(baseQuery));cachedQuerywill cache both theAsyncDataLinkinstances and the data provided by them. Note that order ofcacheLinksandcacheResultsmethod calls is important and applying thecacheLinksmethod first would not result in a desirable behaviour because the returned links would not share the cached data of theAsyncDataLinkinstances.Note that it is possible to manually remove cached items from the returned
AsyncDataQueryusing itsclearCacheandremoveFromCachemethods.- Type Parameters:
QueryArgType- the type of the input argument of the specifiedAsyncDataQueryDataType- the type of the data provided by the specified (and returned)AsyncDataQuery- Parameters:
wrappedQuery- theAsyncDataQuerywhich actually provides the data. The returnedAsyncDataQuerywill fall back to use thisAsyncDataQueryfor uncachedAsyncDataLinkinstances. This argument cannot benull.- Returns:
- the
AsyncDataQuerywhich cachesAsyncDataLinkinstances based on the input of the query. This method never returnsnull. - Throws:
NullPointerException- thrown if the specifiedAsyncDataQueryis {!code null}- See Also:
-
cacheLinks
public static <QueryArgType,DataType> CachedAsyncDataQuery<QueryArgType,DataType> cacheLinks(AsyncDataQuery<? super QueryArgType, DataType> wrappedQuery, int maxCacheSize) Creates and returns anAsyncDataQuerywhich cachesAsyncDataLinkinstances based on the input of the query. That is, the returnedAsyncDataQuerymay return the sameAsyncDataLinkfor the same input (based onequals). The data provided by theAsyncDataLinkinstances are not cached by the returned query. Those can be cached by using thecacheResultsmethod.The
AsyncDataQuerycreated by this method caches only at most the specified number ofAsyncDataLinkinstances and when this limit is exceeded, the one used least recently is discarded from the cache. Also a lease time can be specified when requesting anAsyncDataLinkwhen it must be removed from the cache and theAsyncDataLinkneeds to be recreated if requested again.Note that most often you want to cache both the
AsyncDataLinkand the data provided by them. Assume that there is a query which loads the content of a file as a byte array by file name:
In the above example codeAsyncDataQuery<Path, byte[]> baseQuery = ...; AsyncDataQuery<CachedLinkRequest<CachedDataRequest<Path>>, byte[]> cachedQuery; cachedQuery = AsyncQueries.cacheLinks(AsyncQueries.cacheResults(baseQuery));cachedQuerywill cache both theAsyncDataLinkinstances and the data provided by them. Note that order ofcacheLinksandcacheResultsmethod calls is important and applying thecacheLinksmethod first would not result in a desirable behaviour because the returned links would not share the cached data of theAsyncDataLinkinstances.Note that it is possible to manually remove cached items from the returned
AsyncDataQueryusing itsclearCacheandremoveFromCachemethods.- Type Parameters:
QueryArgType- the type of the input argument of the specifiedAsyncDataQueryDataType- the type of the data provided by the specified (and returned)AsyncDataQuery- Parameters:
wrappedQuery- theAsyncDataQuerywhich actually provides the data. The returnedAsyncDataQuerywill fall back to use thisAsyncDataQueryfor uncachedAsyncDataLinkinstances. This argument cannot benull.maxCacheSize- the maximum number ofAsyncDataLinkto store in the cache. When this argument is 0, the returnedAsyncDataQuerywill not actually cacheAsyncDataLinkinstances. This argument must greater than or equal to zero.- Returns:
- the
AsyncDataQuerywhich cachesAsyncDataLinkinstances based on the input of the query. This method never returnsnull. - Throws:
IllegalArgumentException- thrown if themaxCacheSizeis lesser than zeroNullPointerException- thrown if the specifiedAsyncDataQueryis {!code null}- See Also:
-
cacheByID
public static <QueryArgType,DataType> CachedByIDAsyncDataQuery<QueryArgType,DataType> cacheByID(AsyncDataQuery<? super QueryArgType, ? extends DataType> wrappedQuery, ReferenceType refType, ObjectCache refCreator) Creates and returns anAsyncDataQuerywhich createsAsyncDataLinkinstances caching their results and cachesAsyncDataLinkinstances based on a unique ID provided to the query with the input argument. The returned query will cache at most 128AsyncDataLinkinstances concurrently.This method call is similar to calling
cacheLinks(cacheResults(wrappedQuery)), except that the query returned by this method cachesAsyncDataLinkinstances using a supplied ID instead of the input itself. Caching by ID is preferable when the input is large (i.e. retains considerable memory) becausecacheLinks(cacheResults(wrappedQuery))will actually store the input for the cachedAsyncDataLinkinstances to be able to get data when it disappears from the cache.- Type Parameters:
QueryArgType- the type of the input of the queryDataType- the type of the data provided by the query- Parameters:
wrappedQuery- the query which actually provides the data based on an input. This argument cannot benull.refType- theReferenceTypeto be used to reference the cached data using the specifiedObjectCache. This argument cannot benull.refCreator- theObjectCacheto use to cache the data. This argument can benullin which caseObjectCache.javaRefCache()is used as theObjectCache.- Returns:
- the
AsyncDataQuerywhich createsAsyncDataLinkinstances caching their results and cachesAsyncDataLinkinstances based on a unique ID provided to the query with the input argument. This method never returnsnull. - Throws:
NullPointerException- thrown ifwrappedQueryorrefTypeisnull- See Also:
-
cacheByID
public static <QueryArgType,DataType> CachedByIDAsyncDataQuery<QueryArgType,DataType> cacheByID(AsyncDataQuery<? super QueryArgType, ? extends DataType> wrappedQuery, ReferenceType refType, ObjectCache refCreator, int maxCacheSize) Creates and returns anAsyncDataQuerywhich createsAsyncDataLinkinstances caching their results and cachesAsyncDataLinkinstances based on a unique ID provided to the query with the input argument. The returned query will cache at most the specified number ofAsyncDataLinkinstances concurrently.This method call is similar to calling
cacheLinks(cacheResults(wrappedQuery)), except that the query returned by this method cachesAsyncDataLinkinstances using a supplied ID instead of the input itself. Caching by ID is preferable when the input is large (i.e. retains considerable memory) becausecacheLinks(cacheResults(wrappedQuery))will actually store the input for the cachedAsyncDataLinkinstances to be able to get data when it disappears from the cache.- Type Parameters:
QueryArgType- the type of the input of the queryDataType- the type of the data provided by the query- Parameters:
wrappedQuery- the query which actually provides the data based on an input. This argument cannot benull.refType- theReferenceTypeto be used to reference the cached data using the specifiedObjectCache. This argument cannot benull.refCreator- theObjectCacheto use to cache the data. This argument can benullin which caseObjectCache.javaRefCache()is used as theObjectCache.maxCacheSize- the maximum number ofAsyncDataLinkinstances to be cached concurrently by the returned query. This argument must be greater than or equal to zero.- Returns:
- the
AsyncDataQuerywhich createsAsyncDataLinkinstances caching their results and cachesAsyncDataLinkinstances based on a unique ID provided to the query with the input argument. This method never returnsnull. - Throws:
IllegalArgumentException- thrown ifmaxCacheSize < 0NullPointerException- thrown ifwrappedQueryorrefTypeisnull- See Also:
-
convertResultsSync
public static <QueryArgType,OldDataType, AsyncDataQuery<QueryArgType,NewDataType> NewDataType> convertResultsSync(AsyncDataQuery<? super QueryArgType, ? extends OldDataType> wrappedQuery, DataConverter<? super OldDataType, ? extends NewDataType> converter) Creates a newAsyncDataQuerywhich will provide the same data as the specifiedAsyncDataQuerybut will apply the user defined conversion on the data. That is, the returned query will transform theAsyncDataLinkinstances created by the specified query as done by theAsyncLinks.convertResultSync(AsyncDataLink, DataConverter)method.Note that the conversion is applied in an
AsyncDataListenerand therefore needs to be a fast, non-blocking conversion.- Type Parameters:
QueryArgType- the type of the input of both the specified and the returned queryOldDataType- the type of the data provided by the specified query which is to be convertedNewDataType- the type of the data provided by the returned query- Parameters:
wrappedQuery- the query whose provided data is to be converted. This argument cannot benull.converter- theDataConverterdefining the conversion of the data. TheDataConverter#convertData(OldDataType)method will be applied to every data provided by the specified query and the result will actually be provided by the resulting query. This argument cannot benull.- Returns:
- the
AsyncDataQuerywhich will provide the same data as the specifiedAsyncDataQuerybut will apply the user defined conversion on the data. This method never returnsnull. - Throws:
NullPointerException- thrown if any of the arguments isnull- See Also:
-
convertResultsAsync
public static <QueryArgType,OldDataType, AsyncDataQuery<QueryArgType,NewDataType> NewDataType> convertResultsAsync(AsyncDataQuery<? super QueryArgType, ? extends OldDataType> wrappedQuery, AsyncDataQuery<? super OldDataType, ? extends NewDataType> converter) Creates anAsyncDataQuerywhich will provide the same data as the specifiedAsyncDataQuerybut applies a conversion on the provided data defined by anAsyncDataQuery. That is, every data provided by the specified query (wrappedQuery) will be used as an input for the converter query (converter) and the data provided by this converter query will be provided by the returned query.This method is best used when the conversion need to applied on the data cannot be executed in the
AsyncDataListener.onDataArrivemethod (probably because the conversion takes too much time to complete).The returned query works by converting every
AsyncDataLinkcreated by the specified query using theAsyncLinks.convertResultAsync(AsyncDataLink, AsyncDataQuery)method. For further details how exactly the conversion is done refer to the documentation of theconvertResultmethod.- Type Parameters:
QueryArgType- the type of the input of both the specified and the returned queryOldDataType- the type of the data provided by the specified query which is to be convertedNewDataType- the type of the data provided by the returned query- Parameters:
wrappedQuery- the query whose provided data is to be converted. This argument cannot benull.converter- theAsyncDataQuerydefining the conversion of the data. TheDataConverter#convertData(OldDataType)method will be applied to every data provided by the specified query and the result will actually be provided by the resulting query. This argument cannot benull.- Returns:
- the
AsyncDataQuerywhich will provide the same data as the specifiedAsyncDataQuerybut applies a conversion on the provided data defined by anAsyncDataQuery. This method never returnsnull. - See Also:
-
extractCachedResults
public static <QueryArgType,DataType> AsyncDataQuery<QueryArgType,DataType> extractCachedResults(AsyncDataQuery<? super QueryArgType, RefCachedData<DataType>> query) Creates anAsyncDataQuerywhich will provide thedata partof the specified query without theVolatileReferenceto it.This method was designed to remove no longer necessary
VolatileReferencefrom the data provided byAsyncDataLinkcreated by theAsyncLinks.refCacheResult(AsyncDataLink, ReferenceType, ObjectCache, long, TimeUnit)method.- Type Parameters:
QueryArgType- the type of the input of both the specified and the returned queryDataType- the type of the data provided by the returned query- Parameters:
query- theAsyncDataQuerywhose data part is to be extracted and provided by the returned query. This argument cannot benull.- Returns:
- the
AsyncDataQuerywhich will provide thedata partof the specified query. This method never returnsnull. - Throws:
NullPointerException- thrown if the specified query isnull- See Also:
-
removeUidFromResults
public static <QueryArgType,DataType> AsyncDataQuery<QueryArgType,DataType> removeUidFromResults(AsyncDataQuery<? super QueryArgType, DataWithUid<DataType>> query) Creates anAsyncDataQuerywhich will provide thedata partof the specified query without theUID.This method was designed to remove no longer necessary UID from the data provided by
AsyncDataLinkcreated by themarkResultsWithUid(AsyncDataQuery)method.- Type Parameters:
QueryArgType- the type of the input of both the specified and the returned queryDataType- the type of the data provided by the returned query- Parameters:
query- theAsyncDataQuerywhose data part is to be extracted and provided by the returned query. This argument cannot benull.- Returns:
- the
AsyncDataQuerywhich will provide thedata partof the specified query. This method never returnsnull. - Throws:
NullPointerException- thrown if the specified query isnull- See Also:
-
markResultsWithUid
public static <QueryArgType,DataType> AsyncDataQuery<QueryArgType,DataWithUid<DataType>> markResultsWithUid(AsyncDataQuery<? super QueryArgType, ? extends DataType> query) Returns anAsyncDataQuerywhich returns the same results as the specifiedAsyncDataLinkbut creates aDataWithUidobject with a new uniqueIDfrom the provided data of the specifiedAsyncDataQuery.The returned
AsyncDataQueryworks by applying theAsyncLinks.markResultWithUid(AsyncDataLink)method on everyAsyncDataLinkcreated by the specified query.The
IDof the provided datas will be unique, so that no other object equals to them. That is, the ID will be different even for same data if requested multiple times.- Type Parameters:
QueryArgType- the type of the input of both the specified and the returned queryDataType- the type of the data provided by the specifiedAsyncDataQuery- Parameters:
query- theAsyncDataQueryfrom which thedata partis to be derived for the results of the returnedAsyncDataQuery. This argument cannot benull.- Returns:
- the
AsyncDataQueryproviding theDataWithUidobjects with the data parts provided by the specifiedAsyncDataQuery. This method never returnsnull. - Throws:
NullPointerException- thrown if the specifiedAsyncDataQueryisnull- See Also:
-