Module jtrim.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

public final class AsyncDataTransformer<DataType> extends Object
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 the submit 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 Details

    • AsyncDataTransformer

      public AsyncDataTransformer(DataTransformer<DataType> transformer, TaskExecutorService executor)
      Creates a new AsyncDataTransformer with the given transformation routine and TaskExecutorService.
      Parameters:
      transformer - the DataTransformer which defines the transformation of input datas. This argument cannot be null.
      executor - the TaskExecutorService which is to be used execute the transformation of the input data. This argument cannot be null.
      Throws:
      NullPointerException - thrown if any of the arguments is null
  • Method Details

    • submit

      public CompletionStage<DataType> submit(CancellationToken cancelToken, DataType input)
      Submits a task to the wrapped executor which will carry out the data transformation routine.
      Parameters:
      cancelToken - the CancellationToken which is to be checked if the submitted task is to be canceled. This is the CancellationToken which will be forwarded to the specified TaskExecutor. This argument cannot be null.
      input - the data which is to be transformed. This argument will be passed to the wrapped data transformer. This argument can only be null if the data transformer accepts null objects.
      Returns:
      the CompletionStage representing the transformation routine. This method never returns null.
    • getTransformer

      public DataTransformer<DataType> 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

      public TaskExecutorService getExecutor()
      Returns the TaskExecutorService on which the data transformation is intended to be executed. This TaskExecutorService is the same as the one specified at construction time.
      Returns:
      the TaskExecutorService on which the data transformation is intended to be executed. This method never returns null.
    • toString

      public String toString()
      Returns the string representation of this AsyncDataTransformer in no particular format. The returned string will contain the string representation of both the data transformer and the executor.

      This method is intended to be used for debugging only.

      Overrides:
      toString in class Object
      Returns:
      the string representation of this object in no particular format. This method never returns null.