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 converted
ResultType - the type of the resulting data after conversion

public final class AsyncDataConverter<InputType,ResultType> extends Object
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 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

    • AsyncDataConverter

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

    • submit

      public CompletionStage<ResultType> submit(CancellationToken cancelToken, InputType input)
      Submits a task to the wrapped executor which will carry out the data conversion 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 converted. This argument will be passed to the wrapped data converter object. This argument can only be null if the data converter accepts null objects.
      Returns:
      the CompletionStage representing the conversion routine. This method never returns null.
      Throws:
      NullPointerException - thrown if the specified CancellationToken is null
    • getConverter

      public DataConverter<InputType,ResultType> 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

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

      public String toString()
      Returns the string representation of this AsyncDataConverter in no particular format. The returned string will contain the string representation of both the data converter 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.