Class ParallelMappingIterator<T,R>

java.lang.Object
com.github.basking2.sdsai.itrex.iterators.ParallelMappingIterator<T,R>
All Implemented Interfaces:
Iterator<R>

public class ParallelMappingIterator<T,R> extends Object implements Iterator<R>
A ParallelMappingIterator will map elements in threads, using an executor service.
  • Constructor Details

    • ParallelMappingIterator

      public ParallelMappingIterator(boolean ordered, Iterator<T> inputs, Executor executor, int breadth, MappingIterator.Mapper<T,R> mappingFunction)
      Constructor with a default error handler.
      Parameters:
      ordered - If true, results from this iterator will be emitted in the same order they are read. If true, this will cause head-of-line blocking if a slow element is encountered, but often this is acceptable.
      inputs - The inputs to map.
      executor - The executor service to dispatch work into.
      breadth - How many concurrent tasks should be started.
      mappingFunction - A function to map from type T to R.
    • ParallelMappingIterator

      public ParallelMappingIterator(boolean ordered, Iterator<T> inputs, Executor executor, int breadth, MappingIterator.Mapper<T,R> mappingFunction, Consumer<Throwable> reportError)
      Constructor.
      Parameters:
      ordered - If true, results from this iterator will be emitted in the same order they are read. If true, this will cause head-of-line blocking if a slow element is encountered, but often this is acceptable.
      inputs - The inputs to map.
      executor - The executor service to dispatch work into.
      breadth - How many concurrent tasks should be started.
      mappingFunction - A function to map from type T to R.
      reportError - If the mapping function throws an exception, how is it handled?
  • Method Details

    • hasNext

      public boolean hasNext()
      Specified by:
      hasNext in interface Iterator<T>
    • next

      public R next()
      Specified by:
      next in interface Iterator<T>