Class CachedByIDAsyncDataQuery<QueryArgType,DataType>
- Type Parameters:
QueryArgType- the type of the input actually used to query the data. Note however, that this query usesCachedLinkRequest<DataWithUid<QueryArgType>>as input.DataType- the type of the data to be retrieved. As with everyAsyncDataQuery, this type is strongly recommended to be immutable or effectively immutable.
- All Implemented Interfaces:
AsyncDataQuery<CachedLinkRequest<DataWithUid<QueryArgType>>,,DataWithUid<DataType>> CachedLinkContainer<Object>
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
query will cache at most the specified number of AsyncDataLink
instances concurrently.
This query is similar to the one created by the
AsyncQueries.cacheLinks(AsyncQueries.cacheResults(wrappedQuery)) method
invocation, except that this query 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
AsyncQueries.cacheLinks(AsyncQueries.cacheResults(wrappedQuery)) will
actually store the input for the cached AsyncDataLink instances to be
able to get data when it disappears from the cache.
Creating instances
It is not possible to directly instantiate this class, to create instances of this class use theAsyncQueries.cacheByID(AsyncDataQuery, ReferenceType, ObjectCache, int)
method.
Thread safety
This class is safe to be used by multiple threads concurrently.Synchronization transparency
This class is not synchronization transparent but methods of this class return reasonably fast. That is, they can be executed by methods need to be responsive (e.g.: listeners, methods called on the AWT event dispatch thread).-
Method Summary
Modifier and TypeMethodDescriptionRemoves everyAsyncDataLinkinstances from the cache currently cached by this query.Returns anAsyncDataLinkwhich will provide data based on the specified input.booleanremoveFromCache(Object arg) Removes a cachedAsyncDataLinkwhich was cached by the specified input.toString()Returns the string representation of thisAsyncDataQueryin no particular format.
-
Method Details
-
clearCache
Removes everyAsyncDataLinkinstances from the cache currently cached by this query. A subsequent retrieval request from the cache will fail to find any requiredAsyncDataLink, therefore causing the implementation to fallback to recreate the requiredAsyncDataLinkinstance.Note that this method takes linear time in the number of cached
AsyncDataLinkinstances.- Specified by:
clearCachein interfaceCachedLinkContainer<QueryArgType>- Returns:
- the collection of inputs whose
AsyncDataLinkinstances were cached before calling this method. This method never returnsnull.
-
removeFromCache
Removes a cachedAsyncDataLinkwhich was cached by the specified input. A subsequent retrieval request from the cache requiring theAsyncDataLinkassociated with the specified input will fail, therefore causing the implementation to fallback to recreate the requiredAsyncDataLinkinstance.- Specified by:
removeFromCachein interfaceCachedLinkContainer<QueryArgType>- Parameters:
arg- the input for which the associatedAsyncDataLinkis to be removed from the cache. This argument can benull.- Returns:
trueif anAsyncDataLinkinstance was cached for the specified input,falseotherwise. If this method returnsfalse, it did nothing because there was noAsyncDataLinkassociated with the given input in the cache.
-
createDataLink
public AsyncDataLink<DataWithUid<DataType>> createDataLink(CachedLinkRequest<DataWithUid<QueryArgType>> arg) Returns anAsyncDataLinkwhich will provide data based on the specified input. The returnedAsyncDataLinkmay be retrieved from the cache rather than actually requesting it from the underlyingAsyncDataLink.Regardless if the requested
AsyncDataLinkwas cached or not, this method returns immediately without blocking.- Specified by:
createDataLinkin interfaceAsyncDataQuery<QueryArgType,DataType> - Parameters:
arg- the input argument which is to be used to retrieve the data. This argument contains information about how the returnedAsyncDataLinkmay be cached and the actualinputwhich determines what data is to be retrieved by the returnedAsyncDataLink. This argument cannot benull.- Returns:
- the
AsyncDataLinkwhich will provide data based on the specified input. This method never returnsnull. - Throws:
NullPointerException- thrown if the specified argument isnull
-
toString
Returns the string representation of thisAsyncDataQueryin no particular format.This method is intended to be used for debugging only.
-