Class AsyncLinks
AsyncDataLink
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 <DataType> AsyncDataLink<DataType>cacheResult(AsyncDataLink<? extends DataType> wrappedDataLink, ReferenceType refType, ObjectCache refCreator) Returns anAsyncDataLinkwhich will return the same datas as the specifiedAsyncDataLinkbut will cache its results.static <DataType> AsyncDataLink<DataType>cacheResult(AsyncDataLink<? extends DataType> wrappedDataLink, ReferenceType refType, ObjectCache refCreator, long dataCancelTimeout, TimeUnit timeUnit) Returns anAsyncDataLinkwhich will return the same datas as the specifiedAsyncDataLinkbut will cache its results.static <InputType,ResultType>
AsyncDataLink<ResultType>convertGradually(InputType input, List<? extends AsyncDataConverter<InputType, ResultType>> transformers) Creates a newAsyncDataLinkwhich will return the given input data transformed by the specifiedAsyncDataConverter, assuming that subsequent converters in the list provide more and more accurate conversion.static <OldType,NewType>
AsyncDataLink<NewType>convertResultAsync(AsyncDataLink<? extends OldType> input, AsyncDataQuery<? super OldType, ? extends NewType> converter) Creates anAsyncDataLinkwhich will provide the same data as the specifiedAsyncDataLinkbut applies a conversion on the provided data defined by anAsyncDataQuery.static <OldType,NewType>
AsyncDataLink<NewType>convertResultSync(AsyncDataLink<? extends OldType> input, DataConverter<? super OldType, ? extends NewType> converter) Creates anAsyncDataLinkwhich will provide the same data as the specifiedAsyncDataLinkbut applies a conversion on the provided data.static <DataType> AsyncDataLink<DataType>createPreparedLink(DataType data, AsyncDataState state) Creates and returns anAsyncDataLinkwhich will provide the given data.static <DataType> AsyncDataLink<DataType>createStateReporterLink(AsyncDataLink<DataType> wrappedLink, AsyncStateReporter<DataType> reporter, long period, TimeUnit periodUnit) Creates a newAsyncDataLinkwhich will provide the exact same data as the specifiedAsyncDataLinkbut will periodically report the state of the data retrieving process.static <DataType> AsyncDataLink<DataType>createStateReporterLink(UpdateTaskExecutor reportExecutor, AsyncDataLink<DataType> wrappedLink, AsyncStateReporter<DataType> reporter, long period, TimeUnit periodUnit) Creates a newAsyncDataLinkwhich will provide the exact same data as the specifiedAsyncDataLinkbut will periodically report the state of the data retrieving process.static <DataType> AsyncDataLink<DataType>extractCachedResult(AsyncDataLink<RefCachedData<DataType>> link) Returns anAsyncDataLinkwhich retrieves thedata partfrom theRefCachedDataresults of the givenAsyncDataLink.static <DataType> AsyncDataLink<DataType>interceptData(AsyncDataLink<? extends DataType> wrappedLink, DataInterceptor<? super DataType> interceptor) Creates anAsyncDataLinkwhich will provide the same data as the specifiedAsyncDataLinkbut has a chance to intercept every the data being retrieved.static <DataType> AsyncDataLink<DataWithUid<DataType>>markResultWithUid(AsyncDataLink<? extends DataType> link) Returns anAsyncDataLinkwhich returns the same results as the specifiedAsyncDataLinkbut creates aDataWithUidobject with a new uniqueIDfrom the results of the specifiedAsyncDataLink.static <DataType> AsyncDataLink<RefCachedData<DataType>>refCacheResult(AsyncDataLink<? extends DataType> wrappedDataLink, ReferenceType refType, ObjectCache refCreator) Returns anAsyncDataLinkwhich will return the same datas as the specifiedAsyncDataLinkbut will cache its results and also return the cached reference.static <DataType> AsyncDataLink<RefCachedData<DataType>>refCacheResult(AsyncDataLink<? extends DataType> wrappedDataLink, ReferenceType refType, ObjectCache refCreator, long dataCancelTimeout, TimeUnit timeUnit) Returns anAsyncDataLinkwhich will return the same datas as the specifiedAsyncDataLinkbut will cache its results and also return the cached reference.static <DataType> AsyncDataLink<DataType>removeUidFromResult(AsyncDataLink<DataWithUid<DataType>> link) Returns anAsyncDataLinkwhich retrieves thedata partfrom theDataWithUidresults of the givenAsyncDataLink.
-
Method Details
-
interceptData
public static <DataType> AsyncDataLink<DataType> interceptData(AsyncDataLink<? extends DataType> wrappedLink, DataInterceptor<? super DataType> interceptor) Creates anAsyncDataLinkwhich will provide the same data as the specifiedAsyncDataLinkbut has a chance to intercept every the data being retrieved. It is also possible for the interceptor to filter out some of the data objects being retrieved.The methods of the
interceptorobject are called in the listener of the data retrieval request, so they must be quick, non-blocking methods.- Type Parameters:
DataType- the type of the data being provided by the returnedAsyncDataLink(and also the specified one)- Parameters:
wrappedLink- theAsyncDataLinkwhich actually provides the data and whose data objects are being intercepted. This argument cannot benull.interceptor- theDataInterceptorto be notified before data was received by the listener listening for the requested data. This argument cannot benull.- Returns:
- the
AsyncDataLinkproviding the same data as the specifiedAsyncDataLinkbut intercepts every returned data and the data notification of the data retrieval completion. This method never returnsnull. - Throws:
NullPointerException- thrown if any of the arguments isnull
-
convertResultSync
public static <OldType,NewType> AsyncDataLink<NewType> convertResultSync(AsyncDataLink<? extends OldType> input, DataConverter<? super OldType, ? extends NewType> converter) Creates anAsyncDataLinkwhich will provide the same data as the specifiedAsyncDataLinkbut applies a conversion on the provided data. That is, it will callconverter.convertDataon every data object provided by the specifiedAsyncDataLink.For example, if the specified
AsyncDataLinkprovides a string:"dummy", and the converter returns the length of the passed string as anInteger, then the returnedAsyncDataLinkwill provide theIntegervalue 5.- Type Parameters:
OldType- the type of the data objects provided by the specifiedAsyncDataLink, which is also the type of the input of the conversionNewType- the type of the data objects provided by the returnedAsyncDataLink, which is also the type of the output of the conversion- Parameters:
input- theAsyncDataLinkof which provided data is to be converted. This argument cannot benull.converter- theDataConverterdefining the conversion of the results ofinput. This argument cannot benull.- Returns:
- the
AsyncDataLinkwhich will provide the same data as the specifiedAsyncDataLinkbut applies a conversion on the provided data. This method never returnsnull. - Throws:
NullPointerException- thrown if any of the arguments isnull- See Also:
-
convertResultAsync
public static <OldType,NewType> AsyncDataLink<NewType> convertResultAsync(AsyncDataLink<? extends OldType> input, AsyncDataQuery<? super OldType, ? extends NewType> converter) Creates anAsyncDataLinkwhich will provide the same data as the specifiedAsyncDataLinkbut applies a conversion on the provided data defined by anAsyncDataQuery. That is, it will pass every data received by the inputAsyncDataLinkand pass it as an input to theAsyncDataQueryand will return the data provided by theAsyncDataLinkreturned by theAsyncDataQuery.This method is best used when the conversion requires to much time to be executed directly in a listener. For example, if the specified
AsyncDataLinkprovides aPathfrom an external source to a file and the converter loads the image from a given path, these can be combined to create anAsyncDataLinkwhich loads an image file from this external source.Note that in the above example the input
AsyncDataLinkis unlikely to provide more and more accurate data. However in general, it is possible that both the inputAsyncDataLinkand theAsyncDataLinkinstances returned by the converterAsyncDataQuerycan return more data objects with increasing accuracy. The returnedAsyncDataLinkassumes that the conversion cannot make a data (provided by the inputAsyncDataLink) more accurate than the subsequent inputsAsyncDataLink(after the first conversion).As a general and simple example assume that the input
AsyncDataLinkreturns the string"A"and"B", so"A"is more accurate than"B". Also assume that the converter query for every inputs provides two strings: The first provided string is the input string with"C"appended and second is with"D"appended. Therefore the returnedAsyncDataLinkwill provide the following strings:"AC", "AD", "BC", "BD"and the accuracy is the same as the order of these strings. Note that the returned query can only provide the strings in this order but may omit any subset of them except for the last one ("BD"which will always be provided).When an
LinkedDataControlobject is passed tocontrolthe data retrieval process, themain control datais sent to the specifiedAsyncDataLinkand thesecondary control datais sent to theAsyncDataLinkcreated by the specified query defining the conversion.- Type Parameters:
OldType- the type of the data objects provided by the specifiedAsyncDataLink, which is also the type of the input of the conversionNewType- the type of the data objects provided by the returnedAsyncDataLink, which is also the type of the output of the conversion- Parameters:
input- theAsyncDataLinkof which provided data is to be converted. This argument cannot benull.converter- theAsyncDataQuerydefining the conversion of the results ofinput. This argument cannot benull.- Returns:
- the
AsyncDataLinkwhich will provide the same data as the specifiedAsyncDataLinkbut applies a conversion on the provided data. This method never returnsnull. - Throws:
NullPointerException- thrown if any of the arguments isnull- See Also:
-
extractCachedResult
public static <DataType> AsyncDataLink<DataType> extractCachedResult(AsyncDataLink<RefCachedData<DataType>> link) Returns anAsyncDataLinkwhich retrieves thedata partfrom theRefCachedDataresults of the givenAsyncDataLink.The returned
AsyncDataLinkwill return the same number of results as the specifiedAsyncDataLink. That is the returnedAsyncDataLinkwill simply return the data part for each receivedRefCachedDatain the same order.- Type Parameters:
DataType- the type of the data to be provided by the returnedAsyncDataLink- Parameters:
link- theAsyncDataLinkfrom which thedata partis to be extracted. This argument cannot benull.- Returns:
- the
AsyncDataLinkproviding thedata partof the specifiedAsyncDataLink. This method never returnsnull. - Throws:
NullPointerException- thrown if the specifiedAsyncDataLinkisnull- See Also:
-
removeUidFromResult
public static <DataType> AsyncDataLink<DataType> removeUidFromResult(AsyncDataLink<DataWithUid<DataType>> link) Returns anAsyncDataLinkwhich retrieves thedata partfrom theDataWithUidresults of the givenAsyncDataLink.The returned
AsyncDataLinkwill return the same number of results as the specifiedAsyncDataLink. That is the returnedAsyncDataLinkwill simply return the data part for each receivedDataWithUidin the same order.- Type Parameters:
DataType- the type of the data to be provided by the returnedAsyncDataLink- Parameters:
link- theAsyncDataLinkfrom which thedata partis to be extracted. This argument cannot benull.- Returns:
- the
AsyncDataLinkproviding thedata partof the specifiedAsyncDataLink. This method never returnsnull. - Throws:
NullPointerException- thrown if the specifiedAsyncDataLinkisnull- See Also:
-
markResultWithUid
public static <DataType> AsyncDataLink<DataWithUid<DataType>> markResultWithUid(AsyncDataLink<? extends DataType> link) Returns anAsyncDataLinkwhich returns the same results as the specifiedAsyncDataLinkbut creates aDataWithUidobject with a new uniqueIDfrom the results of the specifiedAsyncDataLink.The returned
AsyncDataLinkwill return the same number of results as the specifiedAsyncDataLink. That is the returnedAsyncDataLinkwill simply return a newDataWithUidwith the same data and a unique ID.The
IDof the provided datas will be unique, so that no other object equals to them.- Type Parameters:
DataType- the type of the data provided by the specifiedAsyncDataLink- Parameters:
link- theAsyncDataLinkfrom which thedata partis to be derived for the results of the returnedAsyncDataLink. This argument cannot benull.- Returns:
- the
AsyncDataLinkproviding theDataWithUidobjects with the data parts provided by the specifiedAsyncDataLink. This method never returnsnull. - Throws:
NullPointerException- thrown if the specifiedAsyncDataLinkisnull- See Also:
-
cacheResult
public static <DataType> AsyncDataLink<DataType> cacheResult(AsyncDataLink<? extends DataType> wrappedDataLink, ReferenceType refType, ObjectCache refCreator) Returns anAsyncDataLinkwhich will return the same datas as the specifiedAsyncDataLinkbut will cache its results. The actual caching mechanism is defined by the specifiedObjectCacheand therefore the cached data is stored in aVolatileReference.Requesting data
The first time the data is requested from the returnedAsyncDataLink, it will fallback to requesting the data from the specifiedAsyncDataLinkand provide exactly the same data as provided by this underlyingAsyncDataLink. Once the final data is available, it will be cached using the given cache. Subsequent data requests will simply return this final cached data.In case the cached data expires (no longer available in the cache), the data will be returned as if it has never been requested. Note that the returned
AsyncDataLinkimplementation will never query the data from the specifiedAsyncDataLinkif not required. That is, if it is currently in the process of requesting the data, it will not start a concurrent request but will return the data from the ongoing request.Canceling requests
Attempting to cancel a data request will not cancel the requesting of the data from the specifiedAsyncDataLinkbut will only do so if there are no active requests (only canceled or completed) and even in this case only after one second has elapsed since the last active request.Controlling requests
In case the data is currently being requested from the specifiedAsyncDataLink, the control objects will be forwarded to this underlying request. Note however, thatAsyncDataControllerobjects created by the returnedAsyncDataLinkmay forward the control requests to the same underlying request.- Type Parameters:
DataType- the type of the data provided by the specifiedAsyncDataLinkwhich is the same type as the returnedAsyncDataLink- Parameters:
wrappedDataLink- theAsyncDataLinkfrom which the data is to be requested when the data is not currently cached. 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
AsyncDataLinkwhich will provide the same data as the specifiedAsyncDataLinkbut will cache its result. This method never returnsnull. - Throws:
NullPointerException- thrown if any of the arguments isnullexcept for theObjectCachewhich is allowed to benull- See Also:
-
cacheResult
public static <DataType> AsyncDataLink<DataType> cacheResult(AsyncDataLink<? extends DataType> wrappedDataLink, ReferenceType refType, ObjectCache refCreator, long dataCancelTimeout, TimeUnit timeUnit) Returns anAsyncDataLinkwhich will return the same datas as the specifiedAsyncDataLinkbut will cache its results. The actual caching mechanism is defined by the specifiedObjectCacheand therefore the cached data is stored in aVolatileReference.Requesting data
The first time the data is requested from the returnedAsyncDataLink, it will fallback to requesting the data from the specifiedAsyncDataLinkand provide exactly the same data as provided by this underlyingAsyncDataLink. Once the final data is available, it will be cached using the given cache. Subsequent data requests will simply return this final cached data.In case the cached data expires (no longer available in the cache), the data will be returned as if it has never been requested. Note that the returned
AsyncDataLinkimplementation will never query the data from the specifiedAsyncDataLinkif not required. That is, if it is currently in the process of requesting the data, it will not start a concurrent request but will return the data from the ongoing request.Canceling requests
Attempting to cancel a data request will not cancel the requesting of the data from the specifiedAsyncDataLinkbut will only do so if there are no active requests (only canceled or completed) and even in this case only after the given timeout has elapsed since the last active request.Controlling requests
In case the data is currently being requested from the specifiedAsyncDataLink, the control objects will be forwarded to this underlying request. Note however, thatAsyncDataControllerobjects created by the returnedAsyncDataLinkmay forward the control requests to the same underlying request.- Type Parameters:
DataType- the type of the data provided by the specifiedAsyncDataLinkwhich is the same type as the returnedAsyncDataLink- Parameters:
wrappedDataLink- theAsyncDataLinkfrom which the data is to be requested when the data is not currently cached. 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.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.- Returns:
- the
AsyncDataLinkwhich will provide the same data as the specifiedAsyncDataLinkbut will cache its result. This method never returnsnull. - Throws:
NullPointerException- thrown if any of the arguments isnullexcept for theObjectCachewhich is allowed to benull- See Also:
-
refCacheResult
public static <DataType> AsyncDataLink<RefCachedData<DataType>> refCacheResult(AsyncDataLink<? extends DataType> wrappedDataLink, ReferenceType refType, ObjectCache refCreator) Returns anAsyncDataLinkwhich will return the same datas as the specifiedAsyncDataLinkbut will cache its results and also return the cached reference. The actual caching mechanism is defined by the specifiedObjectCacheand therefore the cached data is stored in aVolatileReference.Requesting data
The first time the data is requested from the returnedAsyncDataLink, it will fallback to requesting the data from the specifiedAsyncDataLinkand provide exactly the same data as provided by this underlyingAsyncDataLink. Once the final data is available, it will be cached using the given cache. Subsequent data requests will simply return this final cached data.In case the cached data expires (no longer available in the cache), the data will be returned as if it has never been requested. Note that the returned
AsyncDataLinkimplementation will never query the data from the specifiedAsyncDataLinkif not required. That is, if it is currently in the process of requesting the data, it will not start a concurrent request but will return the data from the ongoing request.Canceling requests
Attempting to cancel a data request will not cancel the requesting of the data from the specifiedAsyncDataLinkbut will only do so if there are no active requests (only canceled or completed) and even in this case only after one second has elapsed since the last active request.Controlling requests
In case the data is currently being requested from the specifiedAsyncDataLink, the control objects will be forwarded to this underlying request. Note however, thatAsyncDataControllerobjects created by the returnedAsyncDataLinkmay forward the control requests to the same underlying request.- Type Parameters:
DataType- the type of the data provided by the specifiedAsyncDataLinkwhich is the same type as the returnedAsyncDataLink- Parameters:
wrappedDataLink- theAsyncDataLinkfrom which the data is to be requested when the data is not currently cached. 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
AsyncDataLinkwhich will provide the same data as the specifiedAsyncDataLinkbut will cache its result. This method never returnsnull. - Throws:
NullPointerException- thrown if any of the arguments isnullexcept for theObjectCachewhich is allowed to benull- See Also:
-
refCacheResult
public static <DataType> AsyncDataLink<RefCachedData<DataType>> refCacheResult(AsyncDataLink<? extends DataType> wrappedDataLink, ReferenceType refType, ObjectCache refCreator, long dataCancelTimeout, TimeUnit timeUnit) Returns anAsyncDataLinkwhich will return the same datas as the specifiedAsyncDataLinkbut will cache its results and also return the cached reference. The actual caching mechanism is defined by the specifiedObjectCacheand therefore the cached data is stored in aVolatileReference.Requesting data
The first time the data is requested from the returnedAsyncDataLink, it will fallback to requesting the data from the specifiedAsyncDataLinkand provide exactly the same data as provided by this underlyingAsyncDataLink. Once the final data is available, it will be cached using the given cache. Subsequent data requests will simply return this final cached data.In case the cached data expires (no longer available in the cache), the data will be returned as if it has never been requested. Note that the returned
AsyncDataLinkimplementation will never query the data from the specifiedAsyncDataLinkif not required. That is, if it is currently in the process of requesting the data, it will not start a concurrent request but will return the data from the ongoing request.Canceling requests
Attempting to cancel a data request will not cancel the requesting of the data from the specifiedAsyncDataLinkbut will only do so if there are no active requests (only canceled or completed) and even in this case only after the given timeout has elapsed since the last active request.Controlling requests
In case the data is currently being requested from the specifiedAsyncDataLink, the control objects will be forwarded to this underlying request. Note however, thatAsyncDataControllerobjects created by the returnedAsyncDataLinkmay forward the control requests to the same underlying request.- Type Parameters:
DataType- the type of the data provided by the specifiedAsyncDataLinkwhich is the same type as the returnedAsyncDataLink- Parameters:
wrappedDataLink- theAsyncDataLinkfrom which the data is to be requested when the data is not currently cached. 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.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.- Returns:
- the
AsyncDataLinkwhich will provide the same data as the specifiedAsyncDataLinkbut will cache its result. This method never returnsnull. - Throws:
NullPointerException- thrown if any of the arguments isnullexcept for theObjectCachewhich is allowed to benull- See Also:
-
convertGradually
public static <InputType,ResultType> AsyncDataLink<ResultType> convertGradually(InputType input, List<? extends AsyncDataConverter<InputType, ResultType>> transformers) Creates a newAsyncDataLinkwhich will return the given input data transformed by the specifiedAsyncDataConverter, assuming that subsequent converters in the list provide more and more accurate conversion. That is, the returnedAsyncDataLinkwill first return the input transformed by the firstAsyncDataConverter, the transformed by the secondAsyncDataConverterand so on.- Type Parameters:
InputType- the type of the input to be transformedResultType- the type of the result of the transformation- Parameters:
input- the input to be transformed and returned. This argument can only benullif theAsyncDataConverterimplementations acceptnullinputs.transformers- the list ofAsyncDataConverterinstances to transform the input data. Every element of the list defines a more accurate conversion than previous elements of the list. So every element of this list defines the same conversion except with different accuracy. This argument cannot benull, cannot containnullelements and also must contain at least a single element.- Returns:
- the
AsyncDataLinkwhich will transform the given input using the specified conversions. This method never returnsnull. - Throws:
NullPointerException- thrown if the convert list or any of the converters isnullIllegalArgumentException- thrown if there are no transformations specified
-
createStateReporterLink
public static <DataType> AsyncDataLink<DataType> createStateReporterLink(AsyncDataLink<DataType> wrappedLink, AsyncStateReporter<DataType> reporter, long period, TimeUnit periodUnit) Creates a newAsyncDataLinkwhich will provide the exact same data as the specifiedAsyncDataLinkbut will periodically report the state of the data retrieving process.The state will be reported through the provided
AsyncStateReporter.reportState(AsyncDataLink, AsyncDataListener, AsyncDataController)method. This method will be invoked on a separate thread which may be shared by other state reports. That is, multipleAsyncDataLinkinstances created by this method may share the same thread to handle state reports. Therefore it is important for theAsyncStateReporterinstances not to depend on each other.The reporting of the state of progress will end once the data providing is done (reporting is done separately for every data providing process). Note however, that it does not mean that once the
onDoneReceivenotification was received no more state report will be done but state reporting will end eventually after theonDoneReceivenotification.- Type Parameters:
DataType- the type of the data provided by the specifiedAsyncDataLinkwhich is the same type as the returnedAsyncDataLink- Parameters:
wrappedLink- theAsyncDataLinkwhich is to provide the data for the returnedAsyncDataLinkand whose state of progress is to be reported. This argument cannot benull.reporter- theAsyncStateReporterto which the state of data providing progress will be reported periodically. This argument cannot benull.period- the period of time in the specified time unit in which the state of data providing progress is to be reported. This argument must be greater than or equal to zero.periodUnit- the time unit of theperiodargument. This argument cannot benull.- Returns:
- the
AsyncDataLinkwhich will provide the exact same data as the specifiedAsyncDataLinkbut will periodically report the state of the data retrieving process. This method never returnsnull. - Throws:
IllegalArgumentException- thrown if the specified time period is lesser than zeroNullPointerException- thrown if any of the arguments isnull- See Also:
-
createStateReporterLink
public static <DataType> AsyncDataLink<DataType> createStateReporterLink(UpdateTaskExecutor reportExecutor, AsyncDataLink<DataType> wrappedLink, AsyncStateReporter<DataType> reporter, long period, TimeUnit periodUnit) Creates a newAsyncDataLinkwhich will provide the exact same data as the specifiedAsyncDataLinkbut will periodically report the state of the data retrieving process.This method works exactly the same way as its cousin
createStateReporterLinkmethod except that it will forward state of progress notifications to the specifiedUpdateTaskExecutorinstead of directly invoking theAsyncStateReporter.reportState(AsyncDataLink, AsyncDataListener, AsyncDataController)method.The state will be reported through the provided
AsyncStateReporter.reportState(AsyncDataLink, AsyncDataListener, AsyncDataController)method. This method will be invoked in the context of the specifiedUpdateTaskExecutor.The reporting of the state of progress will end once the data providing is done (reporting is done separately for every data providing process). Note however, that it does not mean that once the
onDoneReceivenotification was received no more state report will be done but state reporting will end eventually after theonDoneReceivenotification.- Type Parameters:
DataType- the type of the data provided by the specifiedAsyncDataLinkwhich is the same type as the returnedAsyncDataLink- Parameters:
reportExecutor- theUpdateTaskExecutorto use to report the state of data loading progress. This argument cannot benull.wrappedLink- theAsyncDataLinkwhich is to provide the data for the returnedAsyncDataLinkand whose state of progress is to be reported. This argument cannot benull.reporter- theAsyncStateReporterto which the state of data providing progress will be reported periodically. This argument cannot benull.period- the period of time in the specified time unit in which the state of data providing progress is to be reported. This argument must be greater than or equal to zero.periodUnit- the time unit of theperiodargument. This argument cannot benull.- Returns:
- the
AsyncDataLinkwhich will provide the exact same data as the specifiedAsyncDataLinkbut will periodically report the state of the data retrieving process. This method never returnsnull. - Throws:
IllegalArgumentException- thrown if the specified time period is lesser than zeroNullPointerException- thrown if any of the arguments isnull- See Also:
-
createPreparedLink
public static <DataType> AsyncDataLink<DataType> createPreparedLink(DataType data, AsyncDataState state) Creates and returns anAsyncDataLinkwhich will provide the given data.This method acts as a gateway between statically available data and
AsyncDataLink. The returnedAsyncDataLinkwill always provide the specified data immediately in theAsyncDataLink.getData(org.jtrim2.cancel.CancellationToken, AsyncDataListener)method and not on a separate thread. Therefore once thegetDatamethod returns it is guaranteed that the data providing has completed (i.e.: theonDoneReceivehas been called).- Type Parameters:
DataType- the type of the data to be provided- Parameters:
data- the data to be provided by the returnedAsyncDataLink. That is, exactly this object (and only this), will be provided. This argument can benullbut in this case the returnedAsyncDataLinkwill providednullas a data.state- the state of progress to be returned by the returnedAsyncDataLinkwhen data is requested. Since after the data has been requested, the providing is immediately completed this state must always report thecurrent progressas1.0. This argument can benullbut in this case the returned state will always benullwhich is not recommended.- Returns:
AsyncDataLinkwhich will provide the specified data. This method never returnsnull.
-