Package org.jtrim2.concurrent.query
Data links
Data links
are the
fundamental part of the package, they represent a connection to a specific
data. Through this connection, the data can be retrieved as many times as
required.
The base interface for data links is AsyncDataLink
which was designed to be simple to implement and simple to use. To implement
it, one must implement its lone method to retrieve the data in a separate
thread and notify the specified listener
when the data is available. A usually sufficient implementation is
to submit a task to a TaskExecutorService
and retrieve the data synchronously in that task and when the data is finally
available, notify the listener.
Implementations should do only a single task which is as simple as possible
and should not do any extra work like caching. Such extra works can and
should be implemented in separate implementations and those implementations
should then be combined. For common tasks like a data link transforming
the result of another data link, caching the result of a data link: the class
AsyncLinks
contains convenient factory
methods.
Data queries
Since data links represent a connection to a single particular data and one does not always want to retrieve the same data over and over,data queries
were created.
The base interface for data queries is AsyncDataQuery
and usually they are even more easier to implement than data links. Since
they are designed to return a data link for a specific input, a usual
implementation only needs to create and return a new instance of a data link.
That is, in most cases they are just simply a factory of data links.
Just like data links, it is possible to create a complex data query
implementation by combining multiple instances. The class
AsyncQueries
contains convenient factory
methods for useful implementations.
Debugging
Debugging concurrent code is always harder than debugging a simple synchronous code. Asynchronous data links are no exceptions. Since usually implementing data links are just submitting a task to an executor and then do the data retrieval process synchronously, it should be relatively easy to test and debug such implementations. If it is desirable to avoid putting break points to the start of such synchronous code, one could use an executor which executes tasks synchronously (assuming executors are used as recommended) in the test code and simply single step the code. Although executing tasks synchronously is different and may not detect synchronization issues, it may help to rule out such issue in specific cases. Also due to theAsyncDataLink
interface being simple, synchronization issues are less
likely to occur.-
ClassDescriptionThe
AsyncDataController
used to control the way the data is provided by anAsyncDataLink
and the state of providing the data.AsyncDataConverter<InputType,ResultType> Defines a conversion of objects and theTaskExecutorService
which should be used to execute the conversion process.AsyncDataLink<DataType>Defines a link to asynchronously access a specific data.AsyncDataListener<DataType>Listens for data provided by anAsyncDataLink
.AsyncDataQuery<QueryArgType,DataType> Defines an object which can be used to query data based on a specified input.Defines the progress of the providing of a data provided by anAsyncDataLink
.AsyncDataTransformer<DataType>Defines a transformation of objects to the same type and theTaskExecutorService
which should be used to execute the transformation process.Contains static helper methods to create consistent string format forAsyncDataLink
andAsyncDataQuery
implementations.Contains useful helper methods for asynchronous data transferring using anAsyncDataLink
.Contains static factory methods for usefulAsyncDataLink
implementations.Contains static factory methods for usefulAsyncDataQuery
implementations.Defines how an asynchronous data transfer has completed.AsyncStateReporter<DataType>Defines the listener which will be notified periodically by theAsyncDataLink
created by theAsyncLinks.createStateReporterLink
method.CachedAsyncDataQuery<QueryArgType,DataType> Defines anAsyncDataQuery
which cachesAsyncDataLink
instances based on the input of the query.CachedByIDAsyncDataQuery<QueryArgType,DataType> Defines anAsyncDataQuery
which createsAsyncDataLink
instances caching their results and cachesAsyncDataLink
instances based on a unique ID provided to the query with the input argument.CachedDataRequest<QueryArgType>Defines a request for a data which should be cached if possible.CachedLinkContainer<CacheRefType>Defines a container for cachedAsyncDataLink
instances.CachedLinkRequest<QueryArgType>Defines a request for a data when theAsyncDataLink
providing should be cached.DataConverter<OldDataType,NewDataType> Defines a conversion from one type to another.DataInterceptor<DataType>Defines an interface for intercepting data provided by anAsyncDataLink
.An exception defining a general failure of transferring a data asynchronously.DataTransformer<DataType>Defines a transformation of objects.DataWithUid<DataType>Defines an object and its ID which uniquely identifies the object within the JVM.AnAsyncDataController
implementation which delegates all of its methods to anotherAsyncDataController
specified at construction time.Defines anAsyncDataController
which forwards every call to a wrappedAsyncDataController
but the wrappedAsyncDataController
can be specified later, after construction time.Defines acontrol object
forAsyncDataController
instances controlling the data retrieval process of twoAsyncDataLink
instances.Defines an aggregate state of progress of multiple data retrieval processes.OrderedData<DataType>Defines a data with an index which indicates how accurate the data is.RefCachedData<DataType>Defines a data and aVolatileReference
of the same data.AnAsyncDataController
implementation which stores a volatile reference to anAsyncDataState
but otherwise does nothing.Defines anAsyncDataState
with a specific double value as the state of progress and a string describing the current state.An exception describing unexpected failure in one or moreAsyncDataListener
.