Package org.jtrim2.concurrent.query
Class AsyncDataTransformer<DataType>
java.lang.Object
org.jtrim2.concurrent.query.AsyncDataTransformer<DataType>
- Type Parameters:
DataType- the type of the data which is to be converted and also the type of the resulting data after conversion
Defines a transformation of objects to the same type and the
TaskExecutorService which should be used to
execute the transformation process. This class is a less general version of
AsyncDataConverter and can be used when a series of conversion needed
to be done but keeping the type of the objects to be converted.
This class effectively just holds a DataTransformer and the
TaskExecutorService.
This class was created to use a more fitting name when converting to the same type and also to reduce the number of generic argument.
Thread safety
Instances of this class are safe to use by multiple threads concurrently.Synchronization transparency
Aside from thesubmit method,
methods of this class are synchronization transparent. This
submit method however needs to submit a task to the
TaskExecutorService and as such is not
synchronization transparent.- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionAsyncDataTransformer(DataTransformer<DataType> transformer, TaskExecutorService executor) Creates a newAsyncDataTransformerwith the given transformation routine andTaskExecutorService. -
Method Summary
Modifier and TypeMethodDescriptionReturns theTaskExecutorServiceon which the data transformation is intended to be executed.Returns the data transformer object which will carry out the conversion of the input data.submit(CancellationToken cancelToken, DataType input) Submits a task to the wrappedexecutorwhich will carry out thedata transformation routine.toString()Returns the string representation of thisAsyncDataTransformerin no particular format.
-
Constructor Details
-
AsyncDataTransformer
Creates a newAsyncDataTransformerwith the given transformation routine andTaskExecutorService.- Parameters:
transformer- theDataTransformerwhich defines the transformation of input datas. This argument cannot benull.executor- theTaskExecutorServicewhich is to be used execute thetransformationof the input data. This argument cannot benull.- Throws:
NullPointerException- thrown if any of the arguments isnull
-
-
Method Details
-
submit
Submits a task to the wrappedexecutorwhich will carry out thedata transformation routine.- Parameters:
cancelToken- theCancellationTokenwhich is to be checked if the submitted task is to be canceled. This is theCancellationTokenwhich will be forwarded to the specifiedTaskExecutor. This argument cannot benull.input- the data which is to be transformed. This argument will be passed to the wrappeddata transformer. This argument can only benullif the data transformer acceptsnullobjects.- Returns:
- the
CompletionStagerepresenting the transformation routine. This method never returnsnull.
-
getTransformer
Returns the data transformer object which will carry out the conversion of the input data. This is the same object which was specified at construction time.- Returns:
- the data transformer object which will carry out the conversion
of the input data. This method never returns
null.
-
getExecutor
Returns theTaskExecutorServiceon which the data transformation is intended to be executed. ThisTaskExecutorServiceis the same as the one specified at construction time.- Returns:
- the
TaskExecutorServiceon which the data transformation is intended to be executed. This method never returnsnull.
-
toString
Returns the string representation of thisAsyncDataTransformerin no particular format. The returned string will contain the string representation of both thedata transformerand theexecutor.This method is intended to be used for debugging only.
-