- Type Parameters:
QueryArgType- the type of the actual input of the query for the data retrieval process. Note that this type is recommended to be immutable or effectively immutable.
AsyncDataQuery as an input.
Apart from the input of the query, the request contains the cache to be used to cache the requested data and a timeout value. The timeout value determines how much time must elapse until an abandoned data retrieval request (i.e.: when every data retrieval request was canceled) should actually stop the data retrieval process. It can be advantageous not to stop the data retrieval process immediately when every request was canceled if there is a chance, that the data can be requested soon.
Note: Two instances of CachedDataRequest are considered equal
if, and only if their query arguments are equal. Other
properties are ignored by the equals and the
hashCode methods. The reason of this to allow the
AsyncQueries.cacheLinks(AsyncQueries.cacheResults(wrappedQuery))
invocations to work as expected.
Thread safety
The methods of this class are safe to be accessed by multiple threads concurrently. Instances of this class are immutable except that its properties might be mutable objects (i.e.: theObjectCache and possibly the
QueryArg).
Synchronization transparency
The methods of this class are synchronization transparent.-
Constructor Summary
ConstructorsConstructorDescriptionCachedDataRequest(QueryArgType queryArg) Creates and initializes theCachedDataRequestwith the given properties.CachedDataRequest(QueryArgType queryArg, ReferenceType refType) Creates and initializes theCachedDataRequestwith the given properties.CachedDataRequest(QueryArgType queryArg, ReferenceType refType, ObjectCache objectCache) Creates and initializes theCachedDataRequestwith the given properties.CachedDataRequest(QueryArgType queryArg, ReferenceType refType, ObjectCache objectCache, long dataCancelTimeout, TimeUnit timeunit) Creates and initializes theCachedDataRequestwith the given properties. -
Method Summary
Modifier and TypeMethodDescriptionbooleanChecks if the specified object is aCachedDataRequestand has aquery argumentwhich equals to the query argument of thisCachedDataRequest.longgetDataCancelTimeout(TimeUnit timeunit) Returns the timeout value to wait before actually canceling abandoned data retrieval processes in the given time unit.Returns theObjectCacheused to cache the data to be retrieved.Returns the object used as the input of the query of the data.Returns theReferenceTypeto be used to reference the cached data using theObjectCacheproperty.inthashCode()Returns a hash code value compatible with theequalsmethod, usable in hash tables.toString()Returns the string representation of thisCachedDataRequestin no particular format.
-
Constructor Details
-
CachedDataRequest
Creates and initializes theCachedDataRequestwith the given properties.The
ObjectCacheused to cache data isObjectCache.javaRefCache()and the reference type isReferenceType.WeakRefTypeusing this constructor.The time in the given unit to wait before actually canceling abandoned requests is 5 seconds using this constructor.
- Parameters:
queryArg- the object used as the input of theAsyncDataQueryto retrieve the requested data. This argument can benullif the query acceptsnullvalues as its input.- Throws:
NullPointerException- thrown ifrefTypeisnull
-
CachedDataRequest
Creates and initializes theCachedDataRequestwith the given properties.The
ObjectCacheused to cache data isObjectCache.javaRefCache()using this constructor.The time in the given unit to wait before actually canceling abandoned requests is 5 seconds using this constructor.
- Parameters:
queryArg- the object used as the input of theAsyncDataQueryto retrieve the requested data. This argument can benullif the query acceptsnullvalues as its input.refType- theReferenceTypeto be used to reference the cached data using theJavaRefObjectCache.INSTANCEcache. This argument cannot benull.- Throws:
NullPointerException- thrown ifrefTypeisnull
-
CachedDataRequest
Creates and initializes theCachedDataRequestwith the given properties.The time in the given unit to wait before actually canceling abandoned requests is 5 seconds using this constructor.
- Parameters:
queryArg- the object used as the input of theAsyncDataQueryto retrieve the requested data. This argument can benullif the query acceptsnullvalues as its input.refType- theReferenceTypeto be used to reference the cached data using the specifiedObjectCache. This argument cannot benull.objectCache- theObjectCacheto use to cache the data. This argument can benullin which caseObjectCache.javaRefCache()is used as theObjectCache.- Throws:
NullPointerException- thrown ifrefTypeisnull
-
CachedDataRequest
public CachedDataRequest(QueryArgType queryArg, ReferenceType refType, ObjectCache objectCache, long dataCancelTimeout, TimeUnit timeunit) Creates and initializes theCachedDataRequestwith the given properties.- Parameters:
queryArg- the object used as the input of theAsyncDataQueryto retrieve the requested data. This argument can benullif the query acceptsnullvalues as its input.refType- theReferenceTypeto be used to reference the cached data using the specifiedObjectCache. This argument cannot benull.objectCache- theObjectCacheto use to cache the data. This argument can benullin which caseObjectCache.javaRefCache()is used as theObjectCache.dataCancelTimeout- the time in the given unit to wait before actually canceling abandoned requests. Before this time elapses, it is possible to start requesting the data and continuing where the request was left off. This argument must be greater than or equal to zero. In case this argument is zero, the data requesting will be canceled as soon as the data is detected to be not required.timeunit- the time unit of thedataCancelTimeoutargument. This argument cannot benull.- Throws:
IllegalArgumentException- thrown ifdataCancelTimeout < 0NullPointerException- thrown ifrefTypeortimeunitisnull
-
-
Method Details
-
getDataCancelTimeout
Returns the timeout value to wait before actually canceling abandoned data retrieval processes in the given time unit.Before this time elapses, it is possible to start requesting the data and continuing where the request was left off. This is advantageous when there is a chance of an abandoned data may be requested again soon.
- Parameters:
timeunit- the time unit in which the timeout value is to be returned. This argument cannot benull.- Returns:
- the timeout value to wait before actually canceling abandoned data retrieval processes in the given time unit. This method always returns a value greater than or equal to zero.
- Throws:
NullPointerException- thrown if the specified time unit isnull
-
getObjectCache
Returns theObjectCacheused to cache the data to be retrieved.- Returns:
- the
ObjectCacheused to cache the data to be retrieved. This method never returnsnull.
-
getQueryArg
Returns the object used as the input of the query of the data. That is, this is the only property which determines what data is to be retrieved. Other properties only define the behaviour of the cache.- Returns:
- the object used as the input of the query of the data. This
method may return
nullifnullwas passed in the constructor.
-
getRefType
Returns theReferenceTypeto be used to reference the cached data using theObjectCacheproperty. That is, this value is intended to be passed to thegetReferencemethod of theObjectCache.- Returns:
- the
ReferenceTypeto be used to reference the cached data using theObjectCacheproperty. This method never returnsnull.
-
toString
Returns the string representation of thisCachedDataRequestin no particular format.This method is intended to be used for debugging only.
-
hashCode
public int hashCode()Returns a hash code value compatible with theequalsmethod, usable in hash tables. -
equals
Checks if the specified object is aCachedDataRequestand has aquery argumentwhich equals to the query argument of thisCachedDataRequest. Other properties ofCachedDataRequestare ignored for the comparison.- Overrides:
equalsin classObject- Parameters:
obj- the object to which thisCachedDataRequestis to be compared to. This argument can benull, in which case the return value isfalse.- Returns:
trueif the specified object is aCachedDataRequestand has aquery argumentwhich equals to the query argument of thisCachedDataRequest,falseotherwise
-