Package org.jtrim2.concurrent.query
Class AsyncDataConverter<InputType,ResultType>
java.lang.Object
org.jtrim2.concurrent.query.AsyncDataConverter<InputType,ResultType>
- Type Parameters:
InputType- the type of the data which is to be convertedResultType- the type of the resulting data after conversion
Defines a conversion of objects and the
TaskExecutorService
which should be used to execute the conversion process.
This class effectively just holds a DataConverter and the
TaskExecutorService.
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.-
Constructor Summary
ConstructorsConstructorDescriptionAsyncDataConverter(DataConverter<InputType, ResultType> converter, TaskExecutorService executor) Creates a newAsyncDataConverterwith the given conversion routine andTaskExecutorService. -
Method Summary
Modifier and TypeMethodDescriptionReturns the data converter object which will carry out the conversion of the input data.Returns theTaskExecutorServiceon which the data conversion is intended to be executed.submit(CancellationToken cancelToken, InputType input) Submits a task to the wrappedexecutorwhich will carry out thedata conversion routine.toString()Returns the string representation of thisAsyncDataConverterin no particular format.
-
Constructor Details
-
AsyncDataConverter
public AsyncDataConverter(DataConverter<InputType, ResultType> converter, TaskExecutorService executor) Creates a newAsyncDataConverterwith the given conversion routine andTaskExecutorService.- Parameters:
converter- theDataConverterwhich defines the conversion of input datas. This argument cannot benull.executor- theTaskExecutorServicewhich is to be used execute theconversionof 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 conversion 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 converted. This argument will be passed to the wrappeddata converter object. This argument can only benullif the data converter acceptsnullobjects.- Returns:
- the
CompletionStagerepresenting the conversion routine. This method never returnsnull. - Throws:
NullPointerException- thrown if the specifiedCancellationTokenisnull
-
getConverter
Returns the data converter 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 converter object which will carry out the conversion of
the input data. This method never returns
null.
-
getExecutor
Returns theTaskExecutorServiceon which the data conversion is intended to be executed. ThisTaskExecutorServiceis the same as the one specified at construction time.- Returns:
- the
TaskExecutorServiceon which the data conversion is intended to be executed. This method never returnsnull.
-
toString
Returns the string representation of thisAsyncDataConverterin no particular format. The returned string will contain the string representation of both thedata converterand theexecutor.This method is intended to be used for debugging only.
-