public final class AsyncQueries extends Object
AsyncDataQuery
implementations.
This class cannot be inherited or instantiated.
AsyncDataQuery,
AsyncLinks,
AsyncHelper| Modifier and Type | Method and Description |
|---|---|
static <QueryArgType,DataType> |
cacheByID(AsyncDataQuery<? super QueryArgType,? extends DataType> wrappedQuery,
ReferenceType refType,
ObjectCache refCreator)
Creates and returns an
AsyncDataQuery which creates
AsyncDataLink instances caching their results and caches
AsyncDataLink instances based on a unique ID provided to the
query with the input argument. |
static <QueryArgType,DataType> |
cacheByID(AsyncDataQuery<? super QueryArgType,? extends DataType> wrappedQuery,
ReferenceType refType,
ObjectCache refCreator,
int maxCacheSize)
Creates and returns an
AsyncDataQuery which creates
AsyncDataLink instances caching their results and caches
AsyncDataLink instances based on a unique ID provided to the
query with the input argument. |
static <QueryArgType,DataType> |
cacheLinks(AsyncDataQuery<? super QueryArgType,DataType> wrappedQuery)
Creates and returns an
AsyncDataQuery which caches
AsyncDataLink instances based on the input of the query. |
static <QueryArgType,DataType> |
cacheLinks(AsyncDataQuery<? super QueryArgType,DataType> wrappedQuery,
int maxCacheSize)
Creates and returns an
AsyncDataQuery which caches
AsyncDataLink instances based on the input of the query. |
static <QueryArgType,DataType> |
cacheResults(AsyncDataQuery<? super QueryArgType,? extends DataType> wrappedQuery)
Creates and returns an
AsyncDataQuery which creates
AsyncDataLink instances caching their results. |
static <QueryArgType,OldDataType,NewDataType> |
convertResultsAsync(AsyncDataQuery<? super QueryArgType,? extends OldDataType> wrappedQuery,
AsyncDataQuery<? super OldDataType,? extends NewDataType> converter)
Creates an
AsyncDataQuery which will provide the same data
as the specified AsyncDataQuery but applies a conversion on the
provided data defined by an AsyncDataQuery. |
static <QueryArgType,OldDataType,NewDataType> |
convertResultsSync(AsyncDataQuery<? super QueryArgType,? extends OldDataType> wrappedQuery,
DataConverter<? super OldDataType,? extends NewDataType> converter)
Creates a new
AsyncDataQuery which will provide the same data as
the specified AsyncDataQuery but will apply the user defined
conversion on the data. |
static <QueryArgType,DataType> |
extractCachedResults(AsyncDataQuery<? super QueryArgType,RefCachedData<DataType>> query)
Creates an
AsyncDataQuery which will provide the
data part of the specified query without
the VolatileReference to it. |
static <QueryArgType,DataType> |
markResultsWithUid(AsyncDataQuery<? super QueryArgType,? extends DataType> query)
Returns an
AsyncDataQuery which returns the same results as the
specified AsyncDataLink but creates a DataWithUid
object with a new unique ID from the provided
data of the specified AsyncDataQuery. |
static <QueryArgType,DataType> |
removeUidFromResults(AsyncDataQuery<? super QueryArgType,DataWithUid<DataType>> query)
|
public static <QueryArgType,DataType> AsyncDataQuery<CachedDataRequest<QueryArgType>,DataType> cacheResults(AsyncDataQuery<? super QueryArgType,? extends DataType> wrappedQuery)
AsyncDataQuery which creates
AsyncDataLink instances caching their results. The returned
AsyncDataQuery is based on a user specified one.
Note that the AsyncDataLink instances themselves will not be
cached. That is, requesting an AsyncDataLink from the returned
AsyncDataQuery will return a new, independent
AsyncDataLink instance. Only these AsyncDataLink
instances will cache their results. The caching mechanism done by these
AsyncDataLink instances is the same as those created by the
AsyncLinks.cacheResult(AsyncDataLink, ReferenceType,ObjectCache)
method.
The ObjectCache and other parameters defining the
exact caching mechanism must be specified when querying new
AsyncDataLink from the returned AsyncDataQuery.
As an example: Assume that the specified AsyncDataQuery loads a
file by its filename as a byte array. The returned AsyncDataQuery
will then load the files as a byte array as well, however individual
AsyncDataLink instances will cache their results and will not
reread the file. However whenever a new AsyncDataLink is returned
by the returned AsyncDataQuery it 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 returned AsyncDataQuery.
QueryArgType - the type of the input of the specified
AsyncDataQueryDataType - the type of the data returned by the specified
(and the returned) AsyncDataQuerywrappedQuery - the AsyncDataQuery whose
AsyncDataLink instances are to cache their results. This
argument cannot be null.AsyncDataQuery which will provide the same data as
the specified AsyncDataQuery but AsyncDataLink
instances 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 returns null.NullPointerException - thrown if the specified
AsyncDataQuery is nullcacheByID(AsyncDataQuery, ReferenceType, ObjectCache, int),
cacheLinks(AsyncDataQuery, int),
AsyncLinks.cacheResult(AsyncDataLink, ReferenceType, ObjectCache)public static <QueryArgType,DataType> CachedAsyncDataQuery<QueryArgType,DataType> cacheLinks(AsyncDataQuery<? super QueryArgType,DataType> wrappedQuery)
AsyncDataQuery which caches
AsyncDataLink instances based on the input of the query. That is,
the returned AsyncDataQuery may return the same
AsyncDataLink for the same input (based on equals). The
data provided by the AsyncDataLink instances are not cached by
the returned query. Those can be cached by using the
cacheResults method.
The AsyncDataQuery created by this method caches only at most
128 AsyncDataLink instances 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 an AsyncDataLink when it must be
removed from the cache and the AsyncDataLink needs to be
recreated if requested again.
Note that most often you want to cache both the AsyncDataLink and
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:
AsyncDataQuery<Path, byte[]> baseQuery = ...;
AsyncDataQuery<CachedLinkRequest<CachedDataRequest<Path>>, byte[]> cachedQuery;
cachedQuery = AsyncQueries.cacheLinks(AsyncQueries.cacheResults(baseQuery));
In the above example code cachedQuery will cache both the
AsyncDataLink instances and the data provided by them. Note that
order of cacheLinks and cacheResults method calls is
important and applying the cacheLinks method first would not
result in a desirable behaviour because the returned links would not
share the cached data of the AsyncDataLink instances.
Note that it is possible to manually remove cached items from the
returned AsyncDataQuery using its
clearCache and
removeFromCache
methods.
QueryArgType - the type of the input argument of the specified
AsyncDataQueryDataType - the type of the data provided by the specified
(and returned) AsyncDataQuerywrappedQuery - the AsyncDataQuery which actually provides
the data. The returned AsyncDataQuery will fall back to use
this AsyncDataQuery for uncached AsyncDataLink
instances. This argument cannot be null.AsyncDataQuery which caches AsyncDataLink
instances based on the input of the query. This method never returns
null.NullPointerException - thrown if the specified
AsyncDataQuery is {!code null}cacheLinks(AsyncDataQuery, int),
cacheResults(AsyncDataQuery),
cacheByID(AsyncDataQuery,ReferenceType, ObjectCache, int)public static <QueryArgType,DataType> CachedAsyncDataQuery<QueryArgType,DataType> cacheLinks(AsyncDataQuery<? super QueryArgType,DataType> wrappedQuery, int maxCacheSize)
AsyncDataQuery which caches
AsyncDataLink instances based on the input of the query. That is,
the returned AsyncDataQuery may return the same
AsyncDataLink for the same input (based on equals). The
data provided by the AsyncDataLink instances are not cached by
the returned query. Those can be cached by using the
cacheResults method.
The AsyncDataQuery created by this method caches only at most
the specified number of AsyncDataLink instances 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 an
AsyncDataLink when it must be removed from the cache and the
AsyncDataLink needs to be recreated if requested again.
Note that most often you want to cache both the AsyncDataLink and
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:
AsyncDataQuery<Path, byte[]> baseQuery = ...;
AsyncDataQuery<CachedLinkRequest<CachedDataRequest<Path>>, byte[]> cachedQuery;
cachedQuery = AsyncQueries.cacheLinks(AsyncQueries.cacheResults(baseQuery));
In the above example code cachedQuery will cache both the
AsyncDataLink instances and the data provided by them. Note that
order of cacheLinks and cacheResults method calls is
important and applying the cacheLinks method first would not
result in a desirable behaviour because the returned links would not
share the cached data of the AsyncDataLink instances.
Note that it is possible to manually remove cached items from the
returned AsyncDataQuery using its
clearCache and
removeFromCache
methods.
QueryArgType - the type of the input argument of the specified
AsyncDataQueryDataType - the type of the data provided by the specified
(and returned) AsyncDataQuerywrappedQuery - the AsyncDataQuery which actually provides
the data. The returned AsyncDataQuery will fall back to use
this AsyncDataQuery for uncached AsyncDataLink
instances. This argument cannot be null.maxCacheSize - the maximum number of AsyncDataLink to store
in the cache. When this argument is 0, the returned
AsyncDataQuery will not actually cache AsyncDataLink
instances. This argument must greater than or equal to zero.AsyncDataQuery which caches AsyncDataLink
instances based on the input of the query. This method never returns
null.IllegalArgumentException - thrown if the maxCacheSize is
lesser than zeroNullPointerException - thrown if the specified
AsyncDataQuery is {!code null}cacheLinks(AsyncDataQuery),
cacheResults(AsyncDataQuery),
cacheByID(AsyncDataQuery,ReferenceType, ObjectCache, int)public static <QueryArgType,DataType> CachedByIDAsyncDataQuery<QueryArgType,DataType> cacheByID(AsyncDataQuery<? super QueryArgType,? extends DataType> wrappedQuery, ReferenceType refType, ObjectCache refCreator)
AsyncDataQuery which creates
AsyncDataLink instances caching their results and caches
AsyncDataLink instances based on a unique ID provided to the
query with the input argument. The returned query will cache at most 128
AsyncDataLink instances concurrently.
This method call is similar to calling
cacheLinks(cacheResults(wrappedQuery)), except that the query
returned by this method caches AsyncDataLink instances using a
supplied ID instead of the input itself. Caching by ID is preferable when
the input is large (i.e. retains considerable memory) because
cacheLinks(cacheResults(wrappedQuery)) will actually store the
input for the cached AsyncDataLink instances to be able to get
data when it disappears from the cache.
QueryArgType - the type of the input of the queryDataType - the type of the data provided by the querywrappedQuery - the query which actually provides the data based on
an input. This argument cannot be null.refType - the ReferenceType to be used to reference the
cached data using the specified ObjectCache. This argument
cannot be null.refCreator - the ObjectCache to use to cache the data. This
argument can be null in which case
ObjectCache.javaRefCache() is used as the ObjectCache.AsyncDataQuery which creates
AsyncDataLink instances caching their results and caches
AsyncDataLink instances based on a unique ID provided to the
query with the input argument. This method never returns null.NullPointerException - thrown if wrappedQuery or
refType is nullcacheLinks(AsyncDataQuery, int),
cacheResults(AsyncDataQuery),
cacheByID(AsyncDataQuery,ReferenceType, ObjectCache, int)public static <QueryArgType,DataType> CachedByIDAsyncDataQuery<QueryArgType,DataType> cacheByID(AsyncDataQuery<? super QueryArgType,? extends DataType> wrappedQuery, ReferenceType refType, ObjectCache refCreator, int maxCacheSize)
AsyncDataQuery which creates
AsyncDataLink instances caching their results and caches
AsyncDataLink instances based on a unique ID provided to the
query with the input argument. The returned query will cache at most the
specified number of AsyncDataLink instances concurrently.
This method call is similar to calling
cacheLinks(cacheResults(wrappedQuery)), except that the query
returned by this method caches AsyncDataLink instances using a
supplied ID instead of the input itself. Caching by ID is preferable when
the input is large (i.e. retains considerable memory) because
cacheLinks(cacheResults(wrappedQuery)) will actually store the
input for the cached AsyncDataLink instances to be able to get
data when it disappears from the cache.
QueryArgType - the type of the input of the queryDataType - the type of the data provided by the querywrappedQuery - the query which actually provides the data based on
an input. This argument cannot be null.refType - the ReferenceType to be used to reference the
cached data using the specified ObjectCache. This argument
cannot be null.refCreator - the ObjectCache to use to cache the data. This
argument can be null in which case
ObjectCache.javaRefCache() is used as the
ObjectCache.maxCacheSize - the maximum number of AsyncDataLink instances
to be cached concurrently by the returned query. This argument must be
greater than or equal to zero.AsyncDataQuery which creates
AsyncDataLink instances caching their results and caches
AsyncDataLink instances based on a unique ID provided to the
query with the input argument. This method never returns null.IllegalArgumentException - thrown if maxCacheSize < 0NullPointerException - thrown if wrappedQuery or
refType is nullcacheLinks(AsyncDataQuery, int),
cacheResults(AsyncDataQuery),
cacheByID(AsyncDataQuery,ReferenceType, ObjectCache)public static <QueryArgType,OldDataType,NewDataType> AsyncDataQuery<QueryArgType,NewDataType> convertResultsSync(AsyncDataQuery<? super QueryArgType,? extends OldDataType> wrappedQuery, DataConverter<? super OldDataType,? extends NewDataType> converter)
AsyncDataQuery which will provide the same data as
the specified AsyncDataQuery but will apply the user defined
conversion on the data. That is, the returned query will transform the
AsyncDataLink instances created by the specified query as done
by the AsyncLinks.convertResultSync(AsyncDataLink, DataConverter)
method.
Note that the conversion is applied in an AsyncDataListener and
therefore needs to be a fast, non-blocking conversion.
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 querywrappedQuery - the query whose provided data is to be converted.
This argument cannot be null.converter - the DataConverter defining the conversion of the
data. The DataConverter#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 be null.AsyncDataQuery which will provide the same data as
the specified AsyncDataQuery but will apply the user defined
conversion on the data. This method never returns null.NullPointerException - thrown if any of the arguments is
nullAsyncLinks.convertResultSync(AsyncDataLink, DataConverter),
convertResultsAsync(AsyncDataQuery, AsyncDataQuery)public static <QueryArgType,OldDataType,NewDataType> AsyncDataQuery<QueryArgType,NewDataType> convertResultsAsync(AsyncDataQuery<? super QueryArgType,? extends OldDataType> wrappedQuery, AsyncDataQuery<? super OldDataType,? extends NewDataType> converter)
AsyncDataQuery which will provide the same data
as the specified AsyncDataQuery but applies a conversion on the
provided data defined by an AsyncDataQuery. 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.onDataArrive
method (probably because the conversion takes too much time to complete).
The returned query works by converting every AsyncDataLink
created by the specified query using the
AsyncLinks.convertResultAsync(AsyncDataLink, AsyncDataQuery) method.
For further details how exactly the conversion is done refer to the
documentation of the convertResult
method.
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 querywrappedQuery - the query whose provided data is to be converted.
This argument cannot be null.converter - the AsyncDataQuery defining the conversion of
the data. The DataConverter#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 be null.AsyncDataQuery which will provide the same data
as the specified AsyncDataQuery but applies a conversion on the
provided data defined by an AsyncDataQuery. This method never
returns null.AsyncLinks.convertResultAsync(AsyncDataLink, AsyncDataQuery),
convertResultsSync(AsyncDataQuery, DataConverter),
LinkedDataControlpublic static <QueryArgType,DataType> AsyncDataQuery<QueryArgType,DataType> extractCachedResults(AsyncDataQuery<? super QueryArgType,RefCachedData<DataType>> query)
AsyncDataQuery which will provide the
data part of the specified query without
the VolatileReference to it.
This method was designed to remove no longer necessary
VolatileReference from the data provided by AsyncDataLink
created by the AsyncLinks.refCacheResult(AsyncDataLink, ReferenceType, ObjectCache, long, TimeUnit)
method.
QueryArgType - the type of the input of both the specified and the
returned queryDataType - the type of the data provided by the returned queryquery - the AsyncDataQuery whose data part is to be
extracted and provided by the returned query. This argument cannot be
null.AsyncDataQuery which will provide the
data part of the specified query. This
method never returns null.NullPointerException - thrown if the specified query is
nullAsyncLinks.refCacheResult(AsyncDataLink, ReferenceType, ObjectCache, long, TimeUnit)public static <QueryArgType,DataType> AsyncDataQuery<QueryArgType,DataType> removeUidFromResults(AsyncDataQuery<? super QueryArgType,DataWithUid<DataType>> query)
AsyncDataQuery which will provide the
data part of the specified query without
the UID.
This method was designed to remove no longer necessary
UID from the data provided by AsyncDataLink created by the
markResultsWithUid(AsyncDataQuery) method.
QueryArgType - the type of the input of both the specified and the
returned queryDataType - the type of the data provided by the returned queryquery - the AsyncDataQuery whose data part is to be
extracted and provided by the returned query. This argument cannot be
null.AsyncDataQuery which will provide the
data part of the specified query. This
method never returns null.NullPointerException - thrown if the specified query is
nullmarkResultsWithUid(AsyncDataQuery)public static <QueryArgType,DataType> AsyncDataQuery<QueryArgType,DataWithUid<DataType>> markResultsWithUid(AsyncDataQuery<? super QueryArgType,? extends DataType> query)
AsyncDataQuery which returns the same results as the
specified AsyncDataLink but creates a DataWithUid
object with a new unique ID from the provided
data of the specified AsyncDataQuery.
The returned AsyncDataQuery works by applying the
AsyncLinks.markResultWithUid(AsyncDataLink) method on every
AsyncDataLink created by the specified query.
The ID of 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.
QueryArgType - the type of the input of both the specified and the
returned queryDataType - the type of the data provided by the specified
AsyncDataQueryquery - the AsyncDataQuery from which the
data part is to be derived for the
results of the returned AsyncDataQuery. This argument cannot be
null.AsyncDataQuery providing the DataWithUid
objects with the data parts provided by the specified
AsyncDataQuery. This method never returns null.NullPointerException - thrown if the specified
AsyncDataQuery is nullAsyncLinks.markResultWithUid(AsyncDataLink),
removeUidFromResults(AsyncDataQuery)